sabato 15 agosto 2009

Autospec for Rails + libnotify on ubuntu howto


Hallo! After a couple of hours of work I finally managed to get autospec popup notifications on my ubuntu machine. Now I can start autotest in the background, and whenever I save a file into my project folder, after a few seconds I receive a notification message on my desktop about the tests.
Here are the steps to get the same result:

  1. install the required gems (ZenTest, and obviously rspec and rspec-rails);
  2. sudo aptitude install libnotify-bin;
  3. edit the file .autotest in your home folder (I said home, not the root of your project!) with the content from this link: https://gist.github.com/840314
  4. save the two pictures rails_ok.png and rail_fail.png from http://blog.internautdesign.com/2006/11/12/autotest-growl-goodness and put them into your ~/Pictures/rails folder.
At this point you are supposed to only run autospec in your project root folder, save a file and see a notification like the one at the top of this article! Happy BDD!

domenica 9 agosto 2009

Building a pronounceable password generator in Ruby

Heya guys! Today I tried to build a pronounceable password generator. To keep it simple, I started from a simple concatenation of words - in my case, italian words. This is really easy, but you'll see that results will be very good.

I took a list of italian words from this site: Italian dictionary and affix file for ispell. It's a good choice because ispell dictionaries are prepared to be declined; concatenating two words without suffixes will give good results for pronounceability.

Before proceeding, however, I needed to narrow the words list:

I removed the ispell affix definitions, to get words like "abaco" instead of "abaco/G":
cat italian.words | sed 's/\/[A-Z]*//g' > parole.txt
I removed all words containing capital letters, like "Yamaha", "Windows", and "Acicastello":
cat parole.txt | sed '/[a-z]*[A-Z][a-z]*/d' > paroleNoCapital.txt
Finally, I sedded out some cuss words - not writing them here, for the sake of decency! :)

I was then ready to write the following ruby script:

def genera_pass_da(parole, n = 2)
how_many_words = parole.size
word = ''
1.upto(n) do
word += parole[rand(how_many_words)].chomp
end
word
end

file = File.open("parole.txt")
parole = file.lines.to_a.select { |word| word.size < 7 }
1.upto(10) do
puts genera_pass_da parole
end
Even if it's far from being polished and optimized, launching this gives a good set of pronounceable passwords. They're all lowercase and without numbers - so probably not the best choice for your remote banking account - but still ok for other uses. Here's a shot:

metalelf0@eagleone$ ruby rapg.rb
uditovoi
vammimidi
gechitua
dareisisma
ecoivi
ancabatto
unotacca
fangopupe
apesella
bemasire
Someday I'll improve it by adding numbers, some capital letters, customizing choices and so on - but many friends are yelling me that it's sunday and I need to go out, so... see ya soon!