Archive for the ‘ruby’ Category

Google Analytics ‘rubaidh’ plugin with multiple account support

Monday, August 11th, 2008

For the Bonnes-Ondes project, we want to allow users to follow their listener visits. The solution is simple : associate a Google Analytics tracker id to the Bonnes-Ondes host … but the Google Analytics ‘rubaidh’ plugin supports only a single Google Analytics account.

A recent patch allows to override the Google Anaytics tracker id, but we wanted to use several tracker ids in our case.

A small patch later and the Bonnes-Ondes controller can associate a Google Analytics account to the request. The after filter generates google code for several accounts. This plugin fork uses a GoogleAnalytics instance for each account and concats the code of each found instance.

(more…)

“Java, c’est legacy”

Tuesday, December 11th, 2007

.. et oui … entendu hier à Paris On Rails. Après avoir 10 ans à essayer de prouver que Java était un vrai langage qui avait tout sa place .. l’objectif est atteint voir .. dépassé :-)

Bon, sinon, le propos était plutôt sur Rails … Quelques conférences intéressantes en particulier celles de Nicolas Mérouze sur HAML et SASS, Christophe Porteneuve sur Prototype (snif, j’ai tout compris) ou encore Jean-Michel Garnier sur RSpec (enfin quelqu’un qui parle de CruiseControl.rb :-) ).

Le démarrage de Rails en France est apparemment plus poussif en France que dans d’autres pays. Mais ca fait plaisir de voir qu’on est pas tout seul à rouler sur les mêmes .. rails :-D

Go to gtk bookmarks in your shell

Wednesday, November 28th, 2007

Gnome (I mean the FileChooser, Nautilus, etc) supports for a few time Bookmarks/Places. You can go back to your favorite folders in a single click. Very usefull in Gedit for example.

But when you’re in your shell ? I use a lot the Ctrl+R search in my zsh history, but it’s a bit tiring to search always the same thing.

First step : a small ruby script to find the wanted path in the gtk boorkmark.

Second step : because a script can’t change the current path of your shell, a function called by an alias is needed. Under zsh, you can make it like that (into your .zshrc) :

function go_impl() {
  target_name=$1
  target=`go-path $target_name`

  if [ -d "$target" ]; then
    cd $target
  else
    echo "target not found : $target_name" 2>&1
  fi
}

alias go='go_impl'

And then ?

[hyppo:~] go freecast
[hyppo:..g/freecast/trunk]

:-)

For the moment, I didn’t manage to setup the zsh completion … The following code :

function go_targets { reply=(`go-path --all`); }
compctl -K go_targets go

… doesn’t nothing

Fix Rails Hotkeys underscore limitation

Friday, November 23rd, 2007

I’m using the Rails Hotkeys plugin for a moment in gedit. There is a small bug, a bit painful : if you’re editing a file customer_report.rb, Rails Hotkeys uses only customer as basename to open related file. So you’ll open customer.rb and not customer_report_test.rb :-(

Here is a small patch to fix Rails Hotkeys underscore limitation. The basename is now computed by removing only _controller, _test or _controller_test to the file basename.

If needed, the two lines to install :

cd ~/.gnome2/gedit/plugins/rails_hotkeys
patch < 2007-11-23-rails_hotkeys_underscore_limitation.patch

Test ActionMailer for a multipart mail

Thursday, November 22nd, 2007

When your ActionMailer creates multipart mails with both html et text bodies, your unit test can become a nightmare. The default policy to test ActionMailer (provided by the generated testcase) is comparing the created mail content with a static fixture. It’s very difficult to maintain. And this approach is impossible with a multipart mail. Several things in the encoded mail are randomly created (like the mimepart boundaries).

Another policy is promoted by Dave Thomas in his book Agile Web Development with Rails or Shanti A. Braford. The principle is simple : test only that the important information is present into the mail body.

This approach is meanful in a html/text mail. The two parts contain often the same important information. So the same assertions can be performed on the two parts of the mail :

sent.parts.each do |part|
  assert_match #{user.name}, part.body, "#{part.content_type} invalid"
  ...
end

inotify support for autotest

Friday, October 26th, 2007

autotest is a really great tool. But my laptop is too old and the current autotest method to detect modifications is a bit heavy for it.

Like Mark Scottishclimbs, I thought about using ruby-inotify to detect changes in source files.

Add to your .autotest file this piece of code to add inotify support. A small change in Autotest#wait_for_changes replaces the simple sleep by a waiting of an inotify event.

Update: ruby-inotify seems buggy. I’ve switched successfully the implementation to inotify. Just download INotify-0.3.0.rb into your load path (such /usr/local/lib/site_ruby/1.8). No native library is required.

RailsCasts on my Nokia 800

Wednesday, October 24th, 2007

I’ve just discovered RailsCasts. I have now more than 70 videos to watch … A good occasion to run the n800 mplayer :-)

A great software combinaison : DownloadHelper to download the movies in a directory, 770-encode.pl to re-encode them for the n800.

A small example with the last RailsCasts episode, here is a 30 second sample of RailsCasts - episode 76 - scope_out for Nokia 800.

I wrote a small wrapper maemo-video-encode-all to encode video files in batch.

A small scp to copy reencoded video files on your nokia SD and enjoy :-)