My first Ruby on Rails patch


Photo made by Bruce Tuten

As I was googling my name I found my name on a Rails Contributors List which could only mean that my little Rails patch got accepted, which made me very happy for today.
Now I am in the list with all the Rails celebrities with just one patch :) .
I got the inspiration by reading Rohit Arondekar’s report about his Bugmash Contribution.
I used the Gimme Ticket service to find a bug to patch and the Bugmash Guide to get Rails from Github and create the patch.

Formtastics country selection with localized country names

In a project I am using formtastic as the formbuilder and I needed to show and save the country in some models. As suggested on the formtastic page I used the iso-3166-country-select plugin as a quick solution. The country names in this plugin are directly in code and not localizable, so that quite soon the question was asked why the entries are in English. Another requirement was to display the country codes instead of the full country name.
The LocalizedCountrySelect plugin provides localized country names which can be downloaded for a lot of languages.
Unfortunately the functions have “localized_” prepended. Formtastic expects the iso-3166-country-select function names without “localized_” so I forked the project, changed the function names and also added an option to show the country codes.

Estimations

I had to make an estimation about the open bugs for a project in bugzilla and just had the long format list of bugs. I started by copying the values from the HTML page manually into a spreadsheet. As I reached the middle of the list I thought it would be better to automate that.
Writing a program to do it is way better than doing it by myself.

# parses a bugzilla search result list in long format
# and creates a csv file

require 'rubygems'
require 'nokogiri'
require 'fastercsv'

f = File.open("show_bug.htm")
doc = Nokogiri::HTML(f)
f.close
FasterCSV.open("bugs.csv", "w") do |csv|
  doc.css("h1").each do |bug|
    bug_number = bug.css("a").text
    tbody = bug.next_sibling.next_sibling
    bug_description = tbody.css("td").first.text
    csv < < [ bug_number, bug_description]
  end
end

KTagebuch for KDE4

I am currently porting KTagebuch to KDE4. Saving, loading and browsing is already working.
For people who already want to try this version I created a Ubuntu package for KTagebuch-0.80. Please create a backup of your KTagebuch database which you can find in “~/.kde/share/apps/ktagebuch/”, because this version has not been tested much.
I set up a github repository for the source code.

Notes about creating a project with Seam, Eclipse and Maven2

install JBoss, Seam und Eclipse (German): http://javathreads.de/2008/09/tutorial-mit-jboss-seam-und-jee5-unter-eclipse-starten/

I used the following versions: jboss-5.1.0.GA, jboss-seam-2.1.1, Eclipse 3.6M2

Maven Project Template: http://kasper.eobjects.dk/2009/04/seam-ejbs-and-ear-packaging-in-maven.html

1. Change sayHello in ejb-hello.xhtml to sayHello() (with the parentheses)
2. Change version of facelets dependency in web/pom.xml from 1.1.11 to 1.1.15.B1 to work with JBoss AS 5

Eclipse Maven Plugin: http://code.google.com/p/q4e/

Import project directory as Maven2 project (Seam-EJB-…) .

Eclipse File sync Plugin für Deployment http://andrei.gmxhome.de/filesync/index.html

Create configuration for Filesync:

Filename: packaging/.settings/de.loskutov.FileSync.prefs:

#Wed Oct 07 11:34:44 CEST 2009
WARNING=DO NOT MODIFY THIS FILE IF YOU DON'T UNDERSTAND
defaultDestination=
/JBossSeam/jboss/jboss-5.1.0.GA/server/default/deploy
defaultVariables=
eclipse.preferences.version=1
includeTeamPrivateFiles=false
map|0=target|,|*.ear|,|,
useCurrentDateForDestinationFiles=false

Deployment:
- start jboss in Eclipse
- mvn install

Steps to adapt the project template
-Change Java files in src/main/java
-Rename the template project name “SeamExample” in the pom.xml files

Reading a CSV File with FasterCSV

I needed to import a data in a CSV file into a database. I needed to find the encoding of the CSV file. I found a method to display the encoding in the VIM statusline, and included this code in .vimrc:

# show file encoding in vim status line
if has("statusline")
 set statusline=%< %f\
%h%m%r%=%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\
&bomb)?\",B\":\"\").\"]\ \"}%k\ %-14.(%l,%c%V%)\ %P
endif

The characterset was Latin1, and I converted it to unicode with Iconv. The row with umlauts had to be split manually, because FasterCSV did not split it.

FasterCSV.foreach(csv_file) do |row|
  if(row[1].nil?)
     row=row[0].split(',')
     Iconv.iconv('UTF-8', 'LATIN1',row[0]).join
     Iconv.iconv('UTF-8', 'LATIN1',row[1]).join
  end
end

Is there a more elegant solution?

RBDiary – 1.0

RBDiary 1.0

RBDiary – 1.0 another attempt at at diary application. This time I used Ruby and plain QT which means it is cross platform and works on all three OSs. I wrote it in a few hours and it already does everything I need. With KTagebuch it was completely different. I spent many hours just struggling with the automake build tool.