Friday, December 26, 2008

Doing Homework With a Wii

My younger daughter just said to me, "Dad, I know how to cheat at homework with the Wii." I asked what whe meant. She said that if you had to alphabetize a list of words (which she sometimes does for homework), you could create a Mii (an in-game avatar on the Wii) for each word, and give it that word as the name. Then use the game's "sort by name" feature to display all the Miis in alphabetical order. Voila!

I'm so proud of her.

Tuesday, December 23, 2008

Rails Without ActiveRecord

When we announced Rails support for the 10gen cloud computing platform, we said that ActiveRecord support was not yet included. This led naturally to the question, "what the heck good is that?"

Actually, you can run Rails without ActiveRecord just fine. Rails has been designed that way. For an example app that uses the Mongo database, see my 10gen-rorob Rails app. You might want to use the branch that uses Rails 2.2.2 instead, because the master branch uses Rails 1.2.6 and the 2.2.2 branch also has a few more features.

On the other hand, internally we have a subset of ActiveRecord working already and are working on supporting as much of it as makes sense with a non-relational database. I already have the Rails app from "Agile Web Development With Rails" running unchanged.

On the gripping hand, you can run the 10gen cloud yourself, in which case you can run it with MySQL or any other relational database. In that case, you can use ActiveRecord unchanged.

How To Freeze Gems In Rails

Here's how to freeze any gem into your Rails app. This is a simplified version of the larger discussion Vendor Everything at err.the_blog.

  1. Copy the gems you want into the directory vendor/gems.
    $ mkdir vendor/gems
    $ cd vendor/gems
    $ gem unpack some_gem_name # repeat for each gem
  2. Edit config/environment.rb and add the following inside the block: do |config|
      # add the next three lines
      config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/**"].map do |dir| = "#{dir}/lib") ? lib : dir

Now you can require those gems in your code, even if the system you are running on doesn't have that gem installed.

Wednesday, December 17, 2008

10gen Officially Includes Ruby and Rails

For the last four months I've been sequestered deep in the heart of the 10gen labs among the test tubes full of bubbling primary-colored liquids, glass jars filled with mysterious biological samples, and mysteriously glowing rectangular pixilated displays. The whole time, I've been pressing small plastic keys in arcane sequences and muttering to myself.

Finally—after going through three lab coats, two lab assistants, and more brains than I care to remember—the lab doors are creaking open to reveal the secrets within: Ruby and Rails are now officially part of the 10gen cloud computing platform.

It's alive! ... ahem... It's alive! ... AHEM ... IT'S ALIIIIVVVVEEEE!


Damn. There's never a good dramatic thunderclap around when you need one.

Actually, this announcement isn't worth all the theatrics. Initial Ruby and Rails support has been in the SDK for a while now. This is more of a soft launch. Ruby support should be complete. Rails support does not yet include ActiveRecord. We do have an XGen::Mongo::Base class which is Mongo-specific with an awfully ActiveRecord-like API.

This launch is more of an official milestone where we are asking the community to take a look at what we've done and give us feedback. Please go grab the 10gen SDK and give it a try. Let me know if you have any questions or suggestions, either here or preferably on the 10gen mailing list. If you are in the NYC area, come to one of our hackathons.

See the Ruby Language Center page for links to documentation.

Monday, December 15, 2008

Clojure Mystery Solved

I figured out what was wrong with the Clojure code in the Mongo Java Driver Clojure sample: we weren't turning the value returned by the database into a seq. You can see the fixed version here.

Tuesday, December 9, 2008

Ruby Mongo Driver Progress

Over the last few days I've added a few features to the Ruby Mongo driver:

  • Sorting
  • Read/write support for arrays and regular expressions
  • An ObjectID class and read/write support
  • More tests

Database commands are JSON objects (sort of) which are almost like Ruby hashes, but not quite. Their keys are ordered, so I whipped up an OrderedHash class to use when the driver sends commands to Mongo.

Adrian Madrid ( has been helping out a lot by providing invaluable feedback, tests, suggestions, and fixes.

Sunday, December 7, 2008


I've been playing a bit with Clojure recently. Playing only: I haven't written anything serious yet. One thing I did write, though, was the Clojure example in Geir Magnusson Jr's Java Mongo driver.

There's a bug somewhere, though: the sample only prints records 1 and 3 out of 3. The Java sample works correctly, as does the JRuby sample. I can't figure out why, because the Clojure code that iterates over the records that are inserted is pretty simple. Here's the code:

(def mongo (org.mongodb.driver.impl.Mongo.))
(def db (.getDB mongo "clojure"))
(def coll (.getCollection db "test"))

(. coll clear)                          ; erase all records in the collection

; insert three records
(dorun (map #(do (.insert coll {"a" (+ % 1)})) (range 0 3)))

; print the number of records in the collection.
(println "There are" (.getCount coll (org.mongodb.driver.MongoSelector.))
  "records in the collection 'test'")

; one way to do a query
(loop [i (.find coll)]
  (when i
    (do (println (first i))
        (recur (rest i)))))

; and another
(dorun (map println (.find coll)))

If you can see what's wrong, please let me know.

Ruby Mongo driver

I've been working on a pure-Ruby driver for Mongo, 10gen's document database. If you are of the Java persuasion, then check out Geir Magnusson Jr's Java driver for Mongo.

One thing that we are discussing internally at 10gen is which layer of the system should be responsible for automatically creating primary key fields for records. Mongo does not require them, but Babble (the 10gen cloud computing app server) does. I think what will end up happening is that the driver will not add them unless the caller specifically asks for it.

Ruby in the Clouds Video

The videos of most of the RubyConf 2008 talks are now available online at the Confreaks RubyConf 2008 web site, including my talk Ruby in the Clouds.