Introduction to Algorithms

Maybe this is old news to some, but I recently discovered that there’s a complete recording (audio at iTunes, audio and video on the web) of an MIT lecture by Prof. Charles E. Leiserson using “The Big Book” Introduction to Algorithms (which he co-wrote) as textbook. I just listened to the first of 25 lectures and liked it as a refresher course on the stuff I learned at university years ago. Lecture notes are available online as well.

ActiveRecord and Hibernate - Friends or Foes?

Currently, I am in the nice situation to decide for myself with which framework I will build a demonstration portal. So, as I want to profit from the fast-paced development processes (at least the Ruby aficionados say so) and the lightweightiness of Rails, I decided to go the Rail(s)Way.

Problem is, that I have to use a legacy database in PostgreSQL where I am not allowed to tinker with the structure, but I am forced to insert data into the tables. The database was created using Hibernate, which means an overall database sequence is used to generate the unique IDs. Unfortunately my new pal ActiveRecord does not know anything about global Postgres sequences, so I had to figure out a way to use the hibernate sequence in a hack to get my unique IDs.

What I did was to use the hook before_validation_on_create in the ActiveRecord table model to create an ID. This looks like this:

[ruby]
class Term < ActiveRecord::Base
before_validation_on_create :generate_id

private
# use the hibernate sequence to generate the next id
def generate_id
self.id = Term.connection,execute(”select nextval(’hibernate_sequence’)”).result[0][0]
end
end
[/ruby]

Developer Coffee Mug

I need a coffee mug with all the nifty regular expression constructs on it. Especially the java character classes would be nice to have.