nunojob:~ dscape/08$ echo The Black Sheep

Archive for the ‘Howto’ Category

Information Retrieval using the Boolean Model in Ruby on Rails


famfamfam flag iconset yaml representation on ruby

First download the flags from famfamfam into a folder called flags (pngs only,
no subfolders!).

Now in the bash:

cd flags
ls > file.txt

Now your on the interactive ruby shell (irb).

# If you want to use this as a script just copy
# the bash lines and put them as
# system ‘cd flags’
# system ‘wget …’ and so on

# We start treating the output from the ls
# open the ls output
f = ‘file.txt’
# place the file in lines
lines = f.readlines
# map those who have 2 digits codes
lines = { |line| line.size == 7 }
# get the 2 digits
lines = { |line| line[0..1] }

# Then the iso file
# open the iso file
f = ‘iso3166_en_code_lists.txt’
# get rid of the notes
# place the file in iso
iso = f.readlines
# create a new hash
hashed_iso = {}
# select non empty lines { |a| !a.rstrip.empty? }.map do |b|
# remove the whitespaces and split in ‘;’
aux = b.rstrip.split ‘;’
# place info in the hash
hashed_iso[aux[1].downcase] = aux[0].capitalize

# Now we cross information giving more
# importance to what’s in the iso.
iso_famfamfam = {
# select those who have flags in famfamfam
|k,v| lines.member? k
}.sort_by {
# sort them by the name the user will see
|pair| pair[1]

# Now we create the contents to store in the yaml file
# create the yaml first line
yaml_lines = “hash: \n”
iso_famfamfam.each do |pair|
# for each pair, create the yaml
# representation and put in yaml_lines
yaml_lines < < ' ' + pair[0] + ': ' + pair[1] + "\n" end yaml_lines << "array: ---\n" iso_famfamfam.each do |pair| yaml_lines << '- - ' + pair[0] + "\n - " + pair[1] + "\n" end # put it in a file f = 'flags.yml', 'w' f.write yaml_lines f.close #sample for loading the yaml into ruby f = 'flags.yml' fy = YAML.load f [/sourcecode] Now you have your yaml representation of the flags. Do what you please. Personally I'm going to use the file to load it to Ruby when my Ruby on Rails app starts and use it as part of the registration system in the

Howto: Change folder icon in Leopard

Copy the icon you want to use (PNG), browse to the folder you want to change the icon.

Now select it and press command + I. Now select the folder and press command + V to paste the icon.

Skitchcast: Ruby Gems is now on v1.0

Here how to update your gem to 1.0 and RoR to 2.0.2

Imagem do dia

Atenção: Esta ilustração mostra como limpar as preferências do TextMate. É apenas um devaneio geek, que mostra como se pode complicar até a mais simples das coisas. A próxima versão será em base-64, para piorar ainda mais o cenário. Contudo quero deixar claro que o uso ilícito de software proprietário é crime. Se através deste exemplo descobrirem como se faz e o fizerem estão a vossa própria responsabilidade.

Creating a User Interface for XML Schema using xForms

We use XSLT all the time to convert a XML document into another format. XML Schemas are XML documents and I think it would be interesting to create the user interface and model for that specific schema using xForms. This would drastically decrease development time and would allow a quick view on what that XML Schema is all about. In other words, this would do for xForms what JAXB does for Java.

Why xForms? xForms is W3C recommendation for creating user interfaces and it’s based on the MVC pattern. This is enough to convince me, I’m all for standards.

While researching I found some works on this subject [here, here] but they are mostly on conference proceedings and therefor I thought no one had really implemented a Generic Schema to xForms transformation engine. Before giving up I asked Vítor Rodrigues about this, as IBM is know for their XML Alphaworks. Guess what? Now I have the solution.

Here’s what you need create an xForm from a Schema:

  • Download Eclipse WTP
  • Open Eclipse and browse to Help > Software Updates > Find and Install
  • Click New Remote Site
  • Name: Emerging Technologies Toolkit (ETTK) Updates
  • Select it and click Finish
  • Now select Emerging Technologies Toolkit (ETTK) Updates > Emerging Technologies Toolkit – Technologies > Visual XForms Designer
  • Click next.
  • Accept the license, install the software and restart eclipse.

Now for the Visual XForms Designer I made a little screen-cast. Just click here to see it.

MacBook OS X Leopard Tips: Controlling the fan speed with Fan Control

I use my computer for something like 6 hours a day so it’s bound to get hot. I didn’t like the apple scheme for the fans that consists basically in making no noise until it’s hot and then make a lot of it.

So I looked for a open-source application to help me control the fan rpm and found Fan Control. I wouldn’t even post this if not for one simple fact: The source is included in the dmg file. Good job guys!