November 11th, 2011

Aka the “mandatory” 11/11/11 post.

Nothing else here, move along.

Movies I've watched recently:

  • W ukryciu / In Hiding (2013) 2.5/5

    2015-08-27 22:37
    * * +

    Not my cup of tea. It was a good movie, but the main character was too psychotic for me.

  • Bilet na księżyc (2013) 4/5

    2015-08-25 22:56
    * * * *

    Awesome story, which could have actually happened but we don't know it for sure.

  • Fotograf / The Photographer (2014) 4.5/5

    2015-08-24 23:24
    * * * * +

    Modern day horror movie. It was *almost* real.

  • Zwerbowana milość (2010) 5/5

    2015-08-23 23:10
    * * * * *

    Awesome Communist era thriller/action movie. Superb acting and incredible story (which might be even true, who knows for sure).

  • Jeziorak (2014) 4.5/5

    2015-08-22 23:28
    * * * * +

    Excellent Polish thriller. I've had great fun watching it.

  • Mad Max: Fury Road (2015) 5/5

    2015-08-22 00:36
    * * * * *

    Wow, what a treat! Sure, it was a "little bit" over the top, but it was so enjoyable that you do not care about it.


Movie ratings archive »

Ruby 1.9.2 via rvm installation woes

November 8th, 2011

I’ve just had to upgrade Ruby to 1.9.2 (from 1.8.7) on the EC2 instance, but ran into a weird error while running rvm install 1.9.2:

Compiling yaml in /home/ubuntu/.rvm/src/yaml-0.1.4.
ERROR: Error running 'make ', please read /home/ubuntu/.rvm/log/ruby-1.9.2-p290/yaml/make.log
Installing yaml to /home/ubuntu/.rvm/usr
ERROR: Error running 'make install', please read /home/ubuntu/.rvm/log/ruby-1.9.2-p290/yaml/make.install.log

and in the log:

src/Makefile.am:2: Libtool library used but `LIBTOOL' is undefined
src/Makefile.am:2:   The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
src/Makefile.am:2:   to `configure.ac' and run `aclocal' and `autoconf' again.
src/Makefile.am:2:   If `AC_PROG_LIBTOOL' is in `configure.ac', make sure
src/Makefile.am:2:   its definition is in aclocal's search path.

Fortunately the solution was rather simple, although Google was not really that helpful this time, hence this post:

sudo aptitude install libtool

Basically the libtool library was not installed.

In Ruby ‘?’ binds stronger than ‘or’

October 13th, 2011

Found it the hard way.


true or true ? "yes" : "no"
=> true

the above is basically the same as this:

true or (true ? "yes" : "no")
=> true

The proper way:

true || true ? "yes" : "no"
=> "yes"

Tell bundler to install gems globally when using capistrano

October 8th, 2011

Seems like it’s not so straightforward. Here’s the excerpt from my config/deploy.rb:

require "bundler/capistrano"
set :bundle_dir,     ""         # install into "system" gems
set :bundle_flags,   "--quiet"  # no verbose output
set :bundle_without, []         # bundle all gems (even dev & test)

Maybe someone finds it helpful.

Painful ruby 1.9.2-p180 to 1.9.2-p290 upgrade

October 8th, 2011

I did the recommended upgrade of my current p180 to the new p290 using rvm:

$ rvm upgrade ruby-1.9.2-p180 ruby-1.9.2-p290

First annoyance – moving gems from one gemset to the new one took over 40 minutes. Have really no idea why.

But after it was done, whenever I tried to run ‘gem’ or ‘rake’ or ‘bundle’ I got:

Invalid gemspec in [/home/jkl/.rvm/gems/ruby-1.9.2-p290/specifications/guard-0.8.1.gemspec]: invalid date format in specification: "2011-09-29
Invalid gemspec in [/home/jkl/.rvm/gems/ruby-1.9.2-p290/specifications/json-1.6.1.gemspec]: invalid date format in specification: "2011-09-18 0
Invalid gemspec in [/home/jkl/.rvm/gems/ruby-1.9.2-p290/specifications/heroku-2.8.4.gemspec]: invalid date format in specification: "2011-09-23
Invalid gemspec in [/home/jkl/.rvm/gems/ruby-1.9.2-p290/specifications/guard-0.8.4.gemspec]: invalid date format in specification: "2011-10-03
Invalid gemspec in [/home/jkl/.rvm/gems/ruby-1.9.2-p290/specifications/multi_xml-0.4.0.gemspec]: invalid date format in specification: "2011-09
-06 00:00:00.000000000Z"
Invalid gemspec in [/home/jkl/.rvm/gems/ruby-1.9.2-p290/specifications/heroku-2.8.1.gemspec]: invalid date format in specification: "2011-09-21
Invalid gemspec in [/home/jkl/.rvm/gems/ruby-1.9.2-p290/specifications/metrical-0.0.7.gemspec]: invalid date format in specification: "2011-09-
11 00:00:00.000000000Z"
and so on...

The above is another manifestation of the YAML engine switch from Syck to Psych and all of the incompatibilities it has brought. The problem is that now you have to reinstall all of your gems, because all installed gems have wrong gemspec specification. D’oh.

I fixed it by running:

$ rvm gemset empty

And then bundling in each project…

$ bundle

Some more reading material.

Bug of the day

September 28th, 2011

Completely bad code follows, beware.

Silent error in Ruby 1.8.7:

x = [:a, :b]
=> [:a, :b]

=> nil

=> [:a, :b]

Explicit error (resulting in a failing test) in Ruby 1.9.2:

x = [:a, :b]
=> [:a, :b]

TypeError: can't convert Symbol into Integer

Just yet another incompatibility, but for the better!

Run guard-jasmine-headless-webkit without X server

September 9th, 2011

You write specs for your javascript, right? If not, you really should.

jasmine-headless-webkit really helps with that. guard-jasmine-headless-webkit makes it all even more enjoyable, although there’s one caveat – it’s not so easy to set it all up.

There is a great guide for that, but it lacks some important details on running guard-jasmine-headless-webkit without graphical interface (X server).

Assuming you already have Xvfb installed, execute this command to run Xvfb in the background:

Xvfb :0 -screen 0 1024x768x24 > /dev/null 2>&1 &

And then you need to setup the DISPLAY shell variable in order for guard-jasmine-headless-webkit to automatically connect to our virtual frame buffer. Here’s the excerpt from my .bash_profile (it first checks if there is Xvfb running on display :0 and only then sets the DISPLAY variable):

xdpyinfo -display :0 &>/dev/null && export DISPLAY=:0

Hash to HTML (hash2html) in Ruby

September 5th, 2011

I needed to output a Hash as a nested HTML structure. Googling didn’t find any satisfactory results, so I decided to roll my own. UL/LI tags seemed like the best choice. It was a nice exercise in recursion.

The result is a function, which outputs a nicely indented HTML. Note, however, that it’s a very basic solution. It doesn’t cope well with anything other than Strings and Numbers (unless your objects support a nice to_s method).

# Prints nested Hash as a nested <ul> and <li> tags
# - keys are wrapped in <strong> tags
# - values are wrapped in <span> tags
def HashToHTML(hash, opts = {})
  return if !hash.is_a?(Hash)

  indent_level = opts.fetch(:indent_level) { 0 }

  out = " " * indent_level + "<ul>\n"

  hash.each do |key, value|
    out += " " * (indent_level + 2) + "<li><strong>#{key}:</strong>"

    if value.is_a?(Hash)
      out += "\n" + HashToHTML(value, :indent_level => indent_level + 2) + " " * (indent_level + 2) + "</li>\n"
      out += " <span>#{value}</span></li>\n"

  out += " " * indent_level + "</ul>\n"

Who knows, maybe someone somewhere finds it useful.

Update: much more concise solution by Piotr Szotkowski.

My first pull request to a public project has been accepted

August 31st, 2011

It was a small but important patch to the i18n gem‘s pluralization rules for the Polish language.

Really made my day. Thanks Krzysztof!


August 30th, 2011
{}.fetch(:a) { 0 }
=> 0

I think it’s really beautiful. Oh, and it’s Ruby, btw.

Update: this is even better:

{}.fetch(:a) { {} }
=> {}