Category: ruby/rails

load_missing_constant’: Syck is not missing constant BadAlias! (ArgumentError)

Posted by – November 29, 2011

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)

Posted by – November 1, 2011

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/
example of edited yajl.h
static void yajl_check_and_fire_callback(void * ctx);
static void yajl_set_static_value(void * ctx, VALUE val);
voila! :)

Custom UINavigationBar with image and back button

Posted by – September 27, 2011

@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

Posted by – June 23, 2011

it’s simple :)

 if (window.devicePixelRatio >= 2) { alert('retina found'); };

Jak jsem počeštil Ruby

Posted by – September 28, 2010

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.

More

ruby – oslovení

Posted by – September 20, 2010

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á)…
More

Ruby 1.8.7-p174 and OpenSSL 1.0.0a

Posted by – July 3, 2010

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.

More

How to get line number and file of your RoR code

Posted by – May 18, 2010

    # 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

use as of

  file, line, method = parse_caller(caller(1).first)

custom date/time formatting with i18n

Posted by – March 22, 2009

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

add czech pluralize to i18n

Posted by – March 22, 2009

module I18n::Backend
  class Simple

  protected

  def pluralize(locale, entry, count)
    return entry unless entry.is_a?(Hash) and count
    key = :zero if count == 0 && entry.has_key?(:zero)
    key ||= count == 1 ? :one : (2..4).include?(count) ? :few : :other
    raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key)
    entry[key]
  end

  end # class

end # module