... wherein I bloviate discursively

Brian Clapper,

Rapture Math

| Comments

What is it about fundamentalists? They seem to hate science and rationality–until, that is, they want to use them to lend some kind of silly credence to their own ridiculous conclusions.

If you believe Harold Camping, 89, of Family Radio, The Rapture is tomorrow, May 21, 2011, with the end of the world (cue R.E.M.) to follow in five months.

(Aside: Since when did family become synonymous with evangelical, fundamentalist Christian, anyway?)

Okay, so no halfway rational person buys into this kind of thinking. But, the twisted rationalizations behind the belief are interesting, if only as an illustration of how far we humans will go to support our existing belief systems.

Apparently, there’s some divine math behind Camping’s certainty about the exact date of The Rapture. Camping puts forth his mad math formula which explains it all. Let’s take a look at the math, shall we? Bear with me, now. This is complificated.

Talking to Fourth Graders about Programming

| Comments

I volunteered to participate in Career Day, at my daughter’s elementary school, and today was the big day. I thought long and hard about how to describe programming to fourth graders, without boring the crap out of them. As it happens, the three 25-minute sessions I did went very well. I thought I’d share my experiences, in case other geek parents find themselves in this situation.

Finding Ruby Gem Specifications Programmatically

| Comments

So, you’re writing a Ruby Gem with a command-line program or two, and you want to support a --version option. When that option is displayed, obviously, your program will just emit the version and exit. Ideally, you want to use the version number that’s in the Gem Specification file, so you don’t have put the version string in multiple places. So, you have to find your gem’s specification file at runtime and pull the data you want from it.

I had a surprisingly difficult time searching for the canonical way to accomplish that task. I finally resorted to UTSL, at which point, all became clear.

The solution is to use a Gem::GemPathSearcher class, an instance of which is available via Gem::searcher:

    PROGRAM_NAME = 'coolness'
    THIS_GEM_PATH = 'coolness' # What you'd require to pull this thing in

    def show_version_only
      gem_spec = Gem.searcher.find(THIS_GEM_PATH)
      if not gem_spec
        raise"Can't find Gem specification for path \"#{THIS_GEM_PATH}\".")
      puts("#{PROGRAM_NAME}, version #{gem_spec.version}. #{gem_spec.homepage}")

The GemPathSearcher class is documented here. Or, you can just use the source, Luke.

Customizing Rake messages: Is there an easier way?

| Comments


Recently, I decided I wanted to customize the output of a Rake run so that the various messages emitting during Rake’s processing were preceded by a timestamp, something like this:

[08:32:02.013] cc -c foo.c -Iinclude
[08:32:02.821] cc -o foo foo.o -Llib

In addition, I wanted a simple function that would write a message to standard output or error, if rake had been invoked with the -v (verbose) command line option.

I figured these goals should be easily satisfied.

Rails: Configuring ActionMailer

| Comments

The problem

In a collaborative Rails development effort, we use AuthLogic for authentication, providing the typical email activation capability that pretty much everyone on the web uses these days. By default, the email is routed through my client’s email service. For local testing, though, I’d rather just route those emails through my in-home local SMTP server. It’s faster, it’s totally contained within my LAN, and it bypasses my main email server’s greylisting.

Ideally, I want:

  • the default email configuration to be set in the config/environment.rb file; and
  • the ability, in my own configuration, to override those settings.

A simple solution

One simple solution I came up with follows.

First, in config/environment.rb, I define various globals, which I then use to configure ActionMailer:

In my environment, I have RAILS_ENV set to bmc-dev. So, I have my configuration overrides in config/bmc-dev.rb. In that file, I simply include:

As a result, when testing within my home LAN, emails from Rails go to my inside-the-LAN email server.


  • These comments are valid for Rails 2. Things are different in Rails 3, I’m told. When I get the chance to test against Rails 3, I’ll update this page.
  • I’m sure a Rails guru can suggest a better means of solving this problem; in fact, I’m hoping someone does and shares it with me.

Running a Ruby block as another user

| Comments

Recently, on stackoverflow, someone asked:

Can you execute a block of Ruby code as a different OS user?

What I, ideally, want is something like this:

user("christoffer") do
  # do something

My proposed solution, for Unix-like systems, turns out to be trivial and seems worth blogging about. It makes use of:

  • Ruby’s block syntax, which allows a block of code (between do and end, or between curly brackets) to be passed, as an object, to a function.
  • Ruby’s etc module which, on Unix-like systems, allows access to the password database via familiar functions like getpwnam.
  • Ruby’s Process module, for forking a child process.

The function to run a block of Ruby code as another user is trivial:

Using the function is also trivial:

Of course, the calling code has to be running as root (or setuid to root) to switch to another user. Running the above code on my Mac OS X laptop yields this output:

$ sudo ruby u.rb
Caller PID = 98003
Caller UID = 0
In child process. User=bmc, PID=98004, UID=501

The Northeast Scala Symposium

| Comments

A month or so ago, Nathan Hamblen, of the New York Scala Enthusiasts, sent an email to Nermin Serifovic and me, in our respective capacities as co-founders of the Boston Area Scala Enthusiasts and Philly Area Scala Enthusiasts users groups. Nathan mentioned that the Scala Lift Off conference, originally scheduled for late October, 2010, in New York, had been canceled. Nathan thought our three Scala users groups might be able to put together a small U.S. East Coast symposium, to fill the void.

Thus was born the first Northeast Scala Symposium.

Here was our original announcement:

The Boston, Philadelphia, and New York Scala user groups have combined to organize the first ever Northeast Scala Symposium. This event will be held at the Meetup headquarters in New York, on February 18th, 2011.

We’ve got lots of great speakers within our groups. At the Symposium, we’ll get to share them among the groups and get to know Scala enthusiasts (and employers) across the region. And to pull in a bit of extra talent, we’re offering $1,000 towards travel expenses for a headline speaker from anywhere. Applicants need only get in touch with one of the organizers with a short description of their talk. (See below for contact details.) Conference registrants will then vote for their favorite talk, and the winner will receive the full travel offset. We need to move quickly on this, so that people can make plans, so don’t be shy about prodding your favorite person in the Scala world to pitch a talk.

Your registration fee of $50 covers the headline speaker’s travel offset, and food and beverages for the event.

Several people pitched some neat-sounding talks. The RSVP’d attendees voted, and Daniel Spiewak narrowly beat out Jonas Bonér (of Akka fame) for the featured slot. But, lucky for us, Jonas is still going to come and give a talk.

So far, more than 50 people have ponied up their $50 and RSVP’d “yes,” including some luminaries from the Scalaverse.

If New York and Scala sound like a fun way to break up a cold February, there are still some slots left. Details are at

Some Jekyll Hacks

| Comments

UPDATE: 3 February, 2012 All this work really isn’t necessary, now that Octopress exists. I’ve switched to using Octopress.


I use Jekyll to generate this blog (in addition to the web site and my company web site). This blog presented a few challenges, which I was able to address with some simple, if crufty, Jekyll hacks. The hacks are all accomplished via Jekyll plugins and monkeypatching, and they work with Jekyll 0.8.0. (I haven’t tested them with other versions.)

Getting Delicious bookmarks to Diigo

| Comments

On 16 December, 2010, a leaked slide, purportedly from Yahoo! all-hands meeting, seemed to indicate that Yahoo! was planning to shut down its popular Delicious bookmarking site. Yahoo denies the rumor, but does state that Delicious is not a “strategic fit at Yahoo!”.

Loads of people are now looking for alternatives to Delicious. I have settled on Diigo, for these reasons:

  • It has a extension for Google Chrome, the browser I use most these days, as well as a toolbar that will work with other browsers.
  • It has an API, though the API is not very well documented.
  • It supports essentially the same features as Delicious, with additional capabilities.
  • It has both a free and a premium service.
  • It works on Linux, not just Mac and Windows. (I use all three, though I spend most of my time on my Mac laptop or on Linux.)

The trick, of course, is getting my Delicious bookmarks into Diigo. Diigo has a web-based service for importing one’s Delicious bookmarks, but it hasn’t worked for me so far. It turns out, however, that it’s not difficult to hack together a quick program to do it manually. Starting with the file at, I hacked together a quick Python script,

Writing, Markdown and Pandoc

| Comments

I’ve been doing a lot of my writing these days using Markdown. It’s a straightforward, simple markup language that converts cleanly to HTML; there are various tools and APIs that do Markdown conversion.

I like Markdown for blogging; this blog’s source is Markdown, for instance. I write user’s guides using Markdown, as well. Sites like GitHub (where I host my code these days) support Markdown natively. Like TeX or troff, Markdown input is plain text, which means I can use a real editor (such as Emacs), rather than the less powerful editors in word processing tools like Apple’s Pages, Writer, or Microsoft Word. Also, because I’m editing (mostly) plain text, I tend to focus on what I’m writing, rather than on the typesetting.

Markdown is so lightweight that the markup doesn’t get in the way of the document contents, as well. You can generally read a Markdown source document without tripping over a lot of extraneous markup. Also, since it’s so lightweight, the conversion tools tend to be fast and small; the original Markdown script is written in Perl, as a series of regex transformations. The Python markdown program is similarly small.

Not too long ago, I stumbled across a really useful tool called Pandoc, written by John MacFarlane. Pandoc converts from a variety of markup formats to other markup formats. e.g.:

If you need to convert files from one markup format into another, pandoc is your swiss-army knife. Need to generate a man page from a markdown file? No problem. LaTeX to Docbook? Sure. HTML to MediaWiki? Yes, that too. Pandoc can read markdown and (subsets of) reStructuredText, HTML, and LaTeX, and it can write plain text, markdown, reStructuredText, HTML, LaTeX, ConTeXt, PDF, RTF, DocBook XML, OpenDocument XML, ODT, GNU Texinfo, MediaWiki markup, groff man pages, EPUB ebooks, and S5 and Slidy HTML slide shows. PDF output (via LaTeX) is also supported with the included markdown2pdf wrapper script.

It’s a cool utility, and I’ve begun to use it more and more. With Pandoc’s help, writing papers and other “real” documents in Markdown becomes even easier. Using Markdown with Pandoc means I can generate HTML, PDF and ODT ( files easily, using a simple GNU Make Makefile:

%.html: style.css Makefile
    pandoc -c style.css -s -f markdown -t html --standalone -o $@ $<

%.odt: Makefile
    pandoc --standalone -f markdown -t odt -o $@ $<

%.pdf: %.odt
    markdown2pdf -f markdown -o $@ $<

all: doc.html doc.odt doc.pdf

I’m pleasantly surprised by the results. There are pieces missing, of course. I haven’t figured out how to force page breaks yet, for instance. But the advantage of editing in a very lightweight markup language, then generating PDFs that are typeset through TeX, far outweighs any niggling disadvantages.

As of version 1.6, Pandoc can generate EPUB documents, as well. As the Pandoc web site puts it, “EPUB books can be viewed on iPads, Nooks, and other electronic book readers, including many smart phones. (They can also be converted to Kindle books using KindleGen.)”

Update: John MacFarlane writes, in an email:

There’s no general way to force page breaks, by the way. If you just want page breaks in PDF (via latex), you can insert a raw latex command,


This should be ignored in HTML and ODT output, so it will only affect latex and PDF via latex.

This approach works like a charm.

Here’s a list of Markdown-related tools I have found to be helpful:

  • The Pandoc document converter.
  • markdown-mode, for Emacs.
  • TeX Live, which allows Pandoc to generate LaTeX-typeset PDFs, among other things. (I use TeX Live on both Ubuntu Linux and Mac OS X.)
  • Jekyll, the Ruby-based static site generator I use to generate this blog and my other web sites. (GitHub also uses Jekyll, as the engine behind GitHub Pages.)
  • Pelican, a Python-based static site generator, similar to Jekyll. (Added to this article 28 January, 2013.)
  • Lanyon, another Python-based static site generator, similar to Jekyll. (Update (28 January, 2013): Lanyon is no longer under active development. The author has replaced it with Pyll.)
  • John MacFarlane’s yst static site generator.
  • Some APIs for parsing Markdown. (I use these APIs in some of my software development.)