Tuesday, November 11, 2008

Matching Ruby Regular Expressions Across Lines

Just a quick note: x.matches(/something.*/) will match all of one line.
To match all lines x.matches(/something.*/m) you need to put the 'm'.

Nice!

I found it here.

Wednesday, October 29, 2008

Transform a Twiki Table

I needed to change a TWiki table to make the rows become columns and columns become rows.

Ruby + 5 mins =

table = <<-TABLE
...paste table here...
TABLE

rows = (table.split "\n").collect { |line| line.split("|") }
puts (0.. rows[1].length).each { |col| puts "|#{rows.collect{ |row| row[col] }.join("|")}|" }

Ahhhh.. That could have been painful.

I love being a programmer. How do people that don't code handle this sort of problem?

Document-oriented Data Storage

There seems to be new interest in the concept of storing data as documents instead of tables. This is the approach that Lotus Notes took. Here is what I ahave found out so far...

A 'document' is basically a hashtable. You can store values with keys. Solutions then seem to take the Google "Map Reduce" approach to querying the data.

CouchDB allows you to define views. A view contains the results of executing a specified javascript function against each document. This is equivolent to the Google 'Map' step.

RDDB (a ruby implementation) provides for both steps...
  # First create an database object
database = Rddb::Database.new

# Put some documents into it
database << {:name => 'John', :income => 35000}
database << {:name => 'Bob', :income => 40000}
database << {:name => 'Jim', :income => 37000}

# Create a view that will return the names
database.create_view('names') do |document, args|
document.name
end

# The result of querying will return an array of names
assert_equal ['John','Bob','Jim'], database.query('names')


"Map Reduce" scales really well across machines, so I am keen to see where this goes.

I'll let you know what I find out.

Anyone got any pointers?

Tuesday, October 28, 2008

Dos Prompt for Long Paths

If you have to work with DOS at some point you find the display muddled due to deep directory trees cluttering your display.

A simple solution is setting the environment variable PROMPT=$p$_$+$g

This just adds a newline to the end of the prompt.. but makes all the difference.

Thanks to Florin Lazar for this tip

Using Outlook like Gmail 2

I forgot to mention...
Install GoogleDesktop to get much better searching through your emails.

GitHub Projects