29 July 2009

to_yaml from mysql SELECT tip

Append \G at the end of a SELECT query .

select * from countries limit 5\G;

*************************** 1. row ***************************
id: 4
continent_id: 2
region_id: 14
permalink: afghanistan
name_en: Afghanistan
name_de: Afghanistan
lat: 33.9391
lng: 67.71
eu_member: 0
alpha2: NULL
alpha3: NULL
*************************** 2. row ***************************
id: 8
continent_id: 3
region_id: 19
permalink: albania
name_en: Albania
name_de: Albanien
lat: 41.1533
lng: 20.1683
eu_member: 0
alpha2: NULL
alpha3: NULL

13 July 2009

Fixing Bus Error BUG in ruby entreprise edition

If you want to use ruby enterprise edition (ree) for your project, it's very important to install all the dependencies with the ree gem command, especially if the gems rely on native code such as imagemagick, or ... bluecloth.

I bumped into the following bug when I tried to run my specs with ree:

$ /opt/ruby-enterprise-1.8.6-20090610/bin/ruby spec/models/advocacy_spec.rb
/.gem/ruby/1.8/gems/bluecloth-2.0.0/lib/bluecloth_ext.bundle: [BUG] Bus Error
ruby 1.8.6 (2008-08-11) [i686-darwin9.7.0]

Abort trap

The solution was to install the bluecloth gem again, with reee gem:

:trunk$ /opt/ruby-enterprise-1.8.6-20090610/bin/gem install bluecloth
WARNING: Installing to ~/.gem since /opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8 and
/opt/ruby-enterprise-1.8.6-20090610/bin aren't both writable.
Building native extensions. This could take a while...
Successfully installed bluecloth-2.0.4
1 gem installed
Installing ri documentation for bluecloth-2.0.4...
Installing RDoc documentation for bluecloth-2.0.4...
jm-macbook:trunk jeanmichel$ /opt/ruby-enterprise-1.8.6-20090610/bin/ruby spec/models/advocacy_spec.rb
...

Finished in 0.349809 seconds

The recent versions of rubygems use the ~/.gem/ruby/1.8/ folder so it make sense to install gems in your home folder so standard ruby and ree can share them.

On a sidenote, running the specs with ree worked without any problem. memory consumption was lower but it did not improve the speed.