TOP

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
Read More
TOP

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

Read More
TOP

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?

Read More

Bad Behavior has blocked 44 access attempts in the last 7 days.