do you do large offline batch jobs and load the results into a database table ?

do you want there to be a smooth changeover from the previous version of the results to a new version, with no rollbacks or lock timeouts ?

activerecord_worm_table allows an ActiveRecord model to be backed by several database tables, an active table, a working table and one or more historical tables. data is loaded into the working table, and when finished the working table becomes the active table. the old active table becomes a historical table, and any active queries continue using that table

it’s available from gemcutter :

gem install activerecord_worm_table

and it’s easy to use :

class Foo < ActiveRecord::Base
  include ActiveRecord::WormTable
Foo.connection.execute( "insert into #{Foo.working_table_name} values ('foofoo')" )

( MySQL support only for now )


i was pleasantly surprised by some regex goodness present in oniguruma [ ruby 1.9 ] and joni [ jruby ]

regexes can concatenate character classes, so you can do things like match against “all unicode whitespace except newlines” thus :


to give sonar an xml input format, for content provided via a rest api or files, i looked around for a ruby xml parser oriented towards parsing large documents : perhaps too large to fit in memory

there are plenty of low-level stream parsers around e.g. in rexml, but they stop some way short of allowing the solution to be expressed in a natural way

here‘s a parser, which sits atop rexml’s pull parser, and allows you to formulate your parse in ruby blocks which straightforwardly process xml elements. what you keep and how you convert is completely specified by those blocks, so you can happily parse an unending document in constant memory

  <person name="alice">likes cheese</person>
  <person name="bob">likes music</person>
  <person name="charles">likes alice</person>

can be parsed with :

require 'rubygems'
require 'xml_stream_parser'

people = {} do
  element "people"  do |name,attrs|
    elements "person" do |name, attrs|
      people[attrs["name"]] = text

a plainer api is also supported, allowing a parse to be split over multiple methods [ since parse_dsl uses instance_exec to call blocks, and loses context ]

people = {} do |p|
  p.element( "people" ) do |name,attrs|
    p.elements( "person" ) do |name, attrs|
      people[attrs["name"]] = p.text

ackack : an emacs integration for the grep replacement, ack

features are

  • run ack within emacs
  • clickable results
  • ecb source path sensitive : searches current project
  • alternatives to search sub-projects of current project, for large projects

rspec-mode for emacs

June 8, 2009

here‘s a mod to pat maddox’s rspec-mode for emacs :

u get

  • jruby spec running [ requires a “jspec” script ] in addition to cruby
  • results in ecb compile window
  • following of results as they are output
  • automatic scroll-to-bottom of results after completion

here’s an ActiveRecord-JDBC plugin for simple use of MySQL master-slave configurations


(re-posted from work)

while working on a little ruby metaprogramming, i realised i didn’t understand how objects, classes and eigenclasses relate to each other in ruby

_why helped some, but i still wasn’t completely clear

i undertook an investigation, with ruby 1.8.6 ( mri and jruby 1.1.4 ), and ruby 1.9 ( mri )

the two 1.8.6 rubys are consistent with each other, but different from ruby 1.9. method resolution seems to function similarly in both 1.8.6 and 1.9, but eigenclasses are referenced differently

this diagram captures what i found

relationships between ruby objects, classes and eigenclasses

relationships between ruby objects, classes and eigenclasses

(pdf: ruby objects, classes and eigenclasses )