Mario's Blog

The journal of a software developer who has a fondness of cheese

OSX Lion Colour Sampling Using DigitalColor Meter

Previously when I was running Mac OSX Snow Leopard I would use the built in tool ‘DigitalColor Meter’ to grab RGB values from my screen. Using the tool is is very quick to grab colours from websites, photoshop files, anything really.

When I upgraded to OSX Lion and opened the colour meter for the first time I realised that it had changed and I could no longer quickly grab colour values to use. I realised though by changing one of the menu settings I could get back the previous functionality; here’s how:

Open Sourcing Like a Pro

For a little while I haven’t had any spare time to do any original open source work. I’d still been contributing to Locomotive CMS, fixing bugs and generally just helping out, but I haven’t had the chance to work on anything new. Thankfully for a client project of mine I had the chance to create a new gem.

So, yesterday at work I released the activemerchant-bpoint gem. A small plugin for Active Merchant that provides a billing gateway for the commonwealth bank’s BPOINT merchant gateway service. It’s really great to work in an environment that encourages open source work. Hopefully this is just the start and I hope in the future that i’ll be able to open source much more of the work I do.

Ruby 1.9.3rc With RVM

The Ruby MRI 1.9.3 RC1 has just been released and I wanted to try it out, the latest version of rvm only lists the 1.9.3 preview1 and 1.9.3-head which doesn’t appear to work correctly. Here’s how I managed to get 1.9.3 installed using rvm:

1
2
3
4
 rvm install ruby-1.9.3-tv1_9_3_rc1 --with-libyaml-dir=$HOME/.rvm/usr
 rvm alias create 1.9.3-rc ruby-1.9.3-tv1_9_3_rc1

 rvm use 1.9.3-rc

Ruby 1.9.3 works quite well (all of my tests still seem to be green), although there are a few small issues at the moment. For example ruby-debug19 doesn’t currently install. Running a quick test shows that 1.9.3 does indeed seem to load up a rails environment much quicker, here is a comparison of running rspec and cucumber tests for a rails 3.1 project.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 Using /Users/mario/.rvm/gems/ruby-1.9.3-tv1_9_3_rc1

 time rspec spec
 Finished in 22.81 seconds

 real  0m28.469s
 user  0m11.000s
 sys   0m0.895s

 time cucumber
 0m4.816s

 real  0m12.955s
 user  0m10.579s
 sys   0m0.701s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 Using /Users/mario/.rvm/gems/ruby-1.9.2-p290

 time rspec spec
 Finished in 25.69 seconds

 real  0m43.826s
 user  0m18.193s
 sys   0m1.367s

 time cucumber
 0m6.007s

 real  0m24.559s
 user  0m19.324s
 sys   0m1.200s

As you can see the actual tests themselves ran faster but not by much, the total execution time went down a lot though as 1.9.3 has some new fixes to dramatically speed up the time it takes to require libraries.

Update

1.9.3rc1 is now available directly through RVM. Simply run:

1
2
3
 rvm get head
 rvm reload
 rvm install 1.9.3

Locomotive CMS

A few months ago a friend and coworker of mine pointed me towards Locomotive CMS, a content management system built on ruby on rails which has multi site support out of the box and has a really pretty admin interface.

I have been helping out Locomotive CMS for a while now in my spare time. I’ve been fixing bugs here and there and helping out users that require assistance. A couple of days ago I was appointed as one of the maintainers for the project, YAY.

Locomotive is really neat, you should totally check it out!

Squeel

I’ve been using a really neat gem lately called Squeel, it provides extra support for active record to do lots of neat things. There’s heaps of examples at the homepage.

Today I managed to get a patch into squeel (YAY!). I found a bug which was only occurring on ruby 1.9.2 sporadically. I wrote a failing spec and the author Ernie created a fix on the very same day.

Using Arel Directly in Rails

Today I was creating a model method which would return some associated objects. It wasn’t hugely complex but I basically needed to match an sql string which looked something like this:

1
2
 SELECT * FROM table WHERE column_one = something AND column_two = something
 OR column_three = something AND column_four = something

After reading some arel documentation, I came up this:

1
2
3
 version  = Version.arel_table
 versions = Version.where(version[:c1].eq(something).and(version[:c2].eq
 (something)).or(version[:c3].eq(something).and(version[:c4].eq(something))))

If this is a bit too fiddly for you then there are some nice gems that do this for you, such as Squeel.

Things to Remember in Vim

I’ve been using Vim for a couple of months now and soo far it’s been great. I’m still learning new things all the time which is really good as well. Here’s some of the tips and trick’s i’ve picked up

To Automatically indent the current line where it should reside when programming use ==

Use Ctrl + c instead of having to reach for the ESC key all the time.

The comment plugin adds the mapping \c Space which comments a line (Or multiple visually selected lines). It also uncomments already commented lines.

:A to cycle between the test and the implementation (Using the rails plugin).

:R to cycle between related files, eg from a view to the controller and back (Using the rails plugin).

. Repeats the last action.

Align [param] Align the visually selected lines based on the parameter given. So for example Align = would align lines based on the equal signs.