Ahoj Kubi, tady máš další příklad v ruby. Jedná se o operace, kde jsou dvě čísla. Program načte požadovaný operand, a následně se dotazuje na dvě celá čísla.
Read More
Category: ruby/rails
load_missing_constant’: Syck is not missing constant BadAlias! (ArgumentError)
Weird ruby/rails error. I was soo crazy about that. And solution is pretty simple.
CHECK your YAML files for error. As I’ve changed my ruby version other than 1.9.2p180 (higher) and as YAML has changed since then, this could make crazy and hidden errors like that one.
cucumber + yajl troubles (OSX Lion)
using rails 3.0.1 and cucumber-rails (~>1.1.0).. and got this weird error message:
dyld: lazy symbol binding failed: Symbol not found: _yajl_set_static_value Referenced from: ~/.rvm/gems/ruby-1.9.3-p0/gems/yajl-ruby-1.0.0/lib/yajl/yajl.bundle Expected in: flat namespace dyld: Symbol not found: _yajl_set_static_value Referenced from: ~/.rvm/gems/ruby-1.9.3-p0/gems/yajl-ruby-1.0.0/lib/yajl/yajl.bundle Expected in: flat namespace Trace/BPT trap: 5
so.. working solution is:
- go to the gem itself ~/.rvm/gems/ruby-1.9.3-p0/gems/yajl-ruby-1.0.0/ext/yajl open yajl_ext.h and yajl_ext.c and change inline void to static void
- gmake clean all
- overwrite yajl.bundle in lib/
static void yajl_check_and_fire_callback(void * ctx); static void yajl_set_static_value(void * ctx, VALUE val);
Custom UINavigationBar with image and back button
@implementation UINavigationBar (UINavigationBarCustomDraw) - (void) drawRect:(CGRect)rect { [self setTintColor:[UIColor colorWithRed:0.5f green: 0.5f blue:0 alpha:1]]; if ([self.topItem.title length] > 0 && ![self.topItem.title isEqualToString:@"Back to ..."]) { [[UIImage imageNamed:@"Header_1px.png"] drawInRect:rect]; CGRect frame = CGRectMake(0, 0, 320, 44); UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease]; [label setBackgroundColor:[UIColor clearColor]]; label.font = [UIFont boldSystemFontOfSize: 20.0]; label.shadowColor = [UIColor colorWithWhite:0.0 alpha:1]; label.textAlignment = UITextAlignmentCenter; label.textColor = [UIColor whiteColor]; label.text = self.topItem.title; self.topItem.titleView = label; } else { [[UIImage imageNamed:"Header.png"] drawInRect:rect]; self.topItem.titleView = [[[UIView alloc] init] autorelease]; } } @end
source: http://www.developers-life.com/custom-uinavigationbar-with-image-and-back-button.html
js – detecting retina displays
it’s simple :)
if (window.devicePixelRatio >= 2) { alert('retina found'); };
Jak jsem počeštil Ruby
Ne, nebojte se. Nezbláznil jsem se, ani jsem doopravdy neudělal z Ruby dokonalý analyzátor jazyka českého. Jen jsem pro výuku programování svého syna dospěl k zajímavému pokusu. Neboť ještě neovládá tak dokonale výrazivo, použité u programovacích jazyků, rozhodl jsem se, že zkusím alespoň “počeštit” Ruby.
ruby – oslovení
Tak Kubo, třeba to ocení i někdo jiný.. Jak jsi psal e-mail, tak tady jsem ti napsal jednoduchý kód, jak udělat oslovení pro různá jména (křestní, česká)…
Read More
Ruby 1.8.7-p174 and OpenSSL 1.0.0a
Because of some compile errors with openssl 1.0.0a, I’ve tried to change source code to match new openssl version and be able to recompile 1.8.7-p174 with new openssl version. Ruby 1.8.7-p299 doesn’t need any changes and works with openssl-1.0.0a like a charm.
How to get line number and file of your RoR code
# parse caller to fetch filename, method & line of call def parse_caller(at) if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at file = Regexp.last_match[1] line = Regexp.last_match[2].to_i method = Regexp.last_match[3] [file, line, method] end end
file, line, method = parse_caller(caller(1).first)
custom date/time formatting with i18n
in helper
def show_date(date) return '' if date.nil? || date==0 l(Time.at(date), :format => :ddate) end
in config/locale/en.yml (for example)
date: formats: ddate: %d.%m.%Y