Why Rails extensions always suggest putting extensions in the model:

Or, “Why using send doesn’t work as exptected”

So, I’ve been banging away at a Rails plugin the last few days.  One of the things that I initially did was to add an initializer that extended the models from the app to avoid needing to muck-up the model, e.g.:

[project root]/config/initializers/acts_as_foo.rb
SomeModel.send(:acts_as_foo, :bar)

It seemed so clean and elegant. But I noticed that my class variables were being trashed when I tried to access them and was befuddled for a day or so.

It turns out what happens is that Rails reloads all of your models (and, in fact, all classes) for every request while in debug mode. At some level in my brain I knew that, but it didn’t click that when that happens initializers aren’t fired as well, so anything that’s being fired from an initializer that will be trashed on reload won’t be there after the first request. (Though it works in production mode.)

Eventually, after much debugging, it clicked what was happening. But I wasn’t quite content to just burden plugin users by modifying each model. I stumbled across this StackOverflow entry which suggested you could achieve the same by modifying environment.rb’s config block. But really, that just shifted the inelegance around. However, the to_prepare bit set me along the right path.

The elegant solution that I eventually found comes from using the dispatcher:

require 'dispatcher'
Dispatcher.to_prepare do
  SomeMode.send(:acts_as_foo, :bar)
end

And there friends we have it: a way to send something to a model from an initializer that will be reloaded every time classes are loaded, or only once during production mode, and every request in development mode.

Localghost 1.0 Released

I’d been looking for an excuse to create a Cocoa app for a while. Even though I still switch hit between Ubuntu and OS X, I spend most of my time on OS X these days. I’d gotten Cocoa Programming for Mac OS X a while back, but had been missing that real-but-simple app idea to give it a whirl on. Until Localghost.

You see, I edit my /etc/hosts litearlly a dozen+ times a day when I want to test things in their production configuration, but with my development version. Localghost adds / removes a set of selected hosts from /etc/hosts with a system tray applet. There’s more info here:

Localghost page.

Gitfeed, Git to RSS and the growing collection of small hacks

I’ve finally succumbed to the Github bug and have been slowly offloading small projects that I’ve created mostly for work stuff. The latest of these is a relatively small hack to produce an RSS fit from a Git repository, which I’d wanted to have posted in our intranet.

Usage is simple and includes a command line thinger so that uses sinatra, so you can get it all in one go.  The source and docs are here.

Additonal hacks that have now been thrown into the wild:

  • fooq — a little wrapper around GCC that lets you write C / C++ one-liners or small script like thingers, and automatically includes and links Qt, without having to futz about with a make file or a main function, etc.
  • QActiveResource — a hack for work since we make heavy usage of ActiveResource to pull data. This one’s a lot faster than ActiveResource for reading data — basically a C++ implementation of the find method. Details in the company blog, or naturally on Github.
  • ShoParTender — Greasemonkey script to make the Shopify partners panel less unweildy. Details in the Shopify developers forum.
  • Chuckery — A bunch of my utility classes and my preprocessor for the ChucK audio synthesis language. Finally got around to converting this old CVS repo to git.
  • Quebec — A graphical (Qt) frontend to the standard command line calculator, bc. Includes history copy-paste and all that jazz.

I’ve realized that slowly I’m becoming a Ruby-ist. I still feel mediocre at the language, but more and more I’m finding it my go-to language for quick hacks. Drinking the Github Kool-Aid just brings me one step closer to the fold.

Getting started starting up.

There’s one funny bit in the history of starting up Directed Edge: I have no idea when I decided to do it. I don’t really know when the idea first crept into my head seriously to start a company. I did a little reconnaissance on my e-mail and file archives and put together some of the critical moments:

  • October 25th, 2005: Mailed Paul Graham asking about books on startups
  • July 1st, 2006: Moved from working at the SAP LinuxLab in Walldorf, Germany to Native Instruments in Berlin
  • January 29th, 2008: Ordered “Competitive Strategy” and “Harvard Business Review on Entrepreneurship”
  • February 5th, 2008: Joined Hacker News
  • February 19th, 2008: Ordered “Founders at Work” and “Fundamentals of Database Systems”
  • February 28th, 2008: Last edit to list of 31 possible startup ideas
  • February 29th, 2008: Asked Valentin if he’d like to co-found
  • April 3rd, 2008: Notified boss at Native Instruments that I’d be leaving at the end of June
  • April 16th, 2008: Ordered “Art of the Start”
  • April 23rd, 2008: Went to first local founders event (Business & Beer)
  • March 4th, 2008: Started our intranet wiki to begin organizing thoughts
  • March 8th, 2008: Registered directededge.com
  • March 13th, 2008: Sent mail to LUG where I’d gone to college asking if any other alums had founded companies
  • March 13th, 2008: Got German permanent residence (meaning I didn’t need a normal job to continue living here)
  • May 23rd, 2008: Went to TechCrunch Meetup Prague
  • June 11th, 2008: Went to TechCrunch Meetup Berlin
  • June 20th, 2008: Attended Mini-Seedcamp Berlin with Valentin
  • June 27th, 2008: Full-time on Directed Edge

It was a little surprising to me that I’d apparently thought over starting a startup as early as 2005.  That was, notably, only a few months before I quit at SAP, and getting the itch to move on was presumably the trigger. That went into remission once I was settled in Berlin and working for Native Instruments.  I don’t remember when, exactly, I started entertaining the idea seriously. Certainly for most of my time at Native Instruments, I was not. It would appear that circa January 2008, with the prospect of German permanent residence at hand, that I began the motions of learning more about what it would take.

It’s also hard to self-evaluate and say if I moved slowly or quickly — obviously I’d been toying with the idea for 3 years by the time I went full-time, but from starting real research to giving notice at work was only two months.

Having done the research, I thought I’d make it here, both to preserve it for memory-lane and on the odd chance that it’s interesting for anyone else.