Monthly Archives: April 2007

Rails and plugins

I’ve come to really love working with Ruby on Rails – it forces a structured approach of Web development upon you which helps enough to get you organised, but doesn’t get in the way of being productive.

I’ve also learnt to search for plugins or gems whenever I need a specific functionality because more often than not somebody has already solved the problem that I am trying to address.

Today I played with Andy Singleton’s GUID plugin (global unique identifier) and found a bug. I haven’t found a way to publish the solution through the rails wiki (I’m really new to the community), so I’m posting it here. I’ve also sent Andy an email, so hopefully the issue will get addressed.

Here is what happend.

I got the plugin working on my development computer and wanted to test it on another machine. However, the plugin gave me the following error message:

#{RAILS_ROOT}/vendor/plugins/guid/lib/uuidtools.rb:235:in `timestamp_create'
#{RAILS_ROOT}/vendor/plugins/guid/lib/uuidtools.rb:225:in `timestamp_create'
#{RAILS_ROOT}/vendor/plugins/guid/lib/usesguid.rb:25:in `after_initialize'

After some digging I found that it uses the MAC address of the computer for seeding the GUID. To query the MAC address, it calls ifconfig (or ipconfig on a Windows machine) – which is fair enough. It has several cases that it goes through. However, the case of my machine was missing and the code did not address a nil return from the get_mac_address function.

My case was simple to solve: my MAC address comes in upper case characters, while the code only tested for lower-case characters. So, I added another parsing condition for my case:

if mac_addresses.size == 0
ifconfig_output = `/sbin/ifconfig | grep HWaddr | cut -c39-`
mac_addresses = ifconfig_output.scan(
Regexp.new("(#{(["[0-9A-F]{2}"] * 6).join(":")})"))
end

The generic problem is harder to solve – and maybe it should not be solved, but fail on the programmer, since he/she is trying to roll out GUID calculation on a machine where the program is unable to calculate a MAC address…..

Hmmm….

Extracting keyframes from Ogg Theora

As I was playing with Ogg Theora lots for LCA, I needed to script the extraction of keyframes from Ogg Theora files.

There’s a manual way to achieve this through totem: you just use ctrl-s to capture a frame. However, I didn’t want to do this for every one of the hundreds of videos that we captured.

Here’s a script that I found somewhere and might work for you, but it didn’t work for me:

dumpvideo foo.ogg | yuv2ppm | pnmsplit - image-%d.ppm; for file in image-*.ppm; do convert $file `basename $file .ppm`.jpeg; done

What worked for me in the end was a nice and simple call to mplayer:

mplayer -ss 120 -frames 1 -vo jpeg $file