MongoDB with Mongoid on Rails

Just gave a brown bag presentation on MongoDB and using it with mongoid and Ruby. Attached are the slides.

Emacs 23.1 idle-highlight set background problem

I recently updated my Emacs to version 23.1 for all the font enhancements (finally). I ran into an issue with setting the region highlighting background. It turns out that this is an issue with ns-win.el file included with Emacs. The fix is simple:

Navigate to Emacs.app/Contents/Resources/lisp/term/

Uncompress ns-win.el.gz, open ns-win.el and change:

(set-face-background 'region "ns_selection_color")

To:

(if (not (face-attribute 'region :background))
    (set-face-background 'region "ns_selection_color"))

Then do M-x byte-compile-file RET /Applications/Emacs.app/Contents/Resources/lisp/term/ns-win.el

Now setting the background works as expected. Idle-highlight will now be usable again…

Install Curb / taf2-curb on Snow Leopard

If any of you use pauldix-feedzirra, you need to get curb installed (or taf2-curb). The problem is that gem dependency does not install cleanly on 10.6 Snow Leopard:

gcc -I. -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 -I. -DRUBY_EXTCONF_H=\”curb_config.h\”  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -fno-common -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE  -fno-common  -pipe -fno-common  -I/opt/local/include -Wall  -c curb.c
In file included from /opt/local/include/curl/curl.h:36,
from curb.h:12,
from curb.c:8:
/opt/local/include/curl/curlrules.h:144: error: size of array ‘__curl_rule_01__’ is negative
/opt/local/include/curl/curlrules.h:154: error: size of array ‘__curl_rule_02__’ is negative
lipo: can’t open input file: /var/tmp//ccFdFUpg.out (No such file or directory)
make: *** [curb.o] Error 1
gcc -I. -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 -I. -DRUBY_EXTCONF_H=\"curb_config.h\"  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   
-fno-common -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE  -fno-common  -pipe -fno-common  -I/opt/local/include -Wall  -c curb.c
In file included from /opt/local/include/curl/curl.h:36,
from curb.h:12,
from curb.c:8:
/opt/local/include/curl/curlrules.h:144: error: size of array ‘__curl_rule_01__’ is negative
/opt/local/include/curl/curlrules.h:154: error: size of array ‘__curl_rule_02__’ is negative
lipo: can't open input file: /var/tmp//ccFdFUpg.out (No such file or directory)
make: *** [curb.o] Error 1

The fix?

sudo port install curl
sudo env ARCHFLAGS="-arch x86_64" gem install taf2-curb

To install the ‘curb’ gem from rubyforge, it is the same command just with curb instead of taf2-curb. Pretty straight forward.

StaleFish Presentation @ Boulder.rb

Presenting about my new gem StaleFish at boulder.rb tonight. Here are the slides:

RefactorMe presentation @ Boulder.rb

I presented at Boulder.rb last night. It seemed to get a decent reception. Slides are below.

EngineYard Solo – The Retrospective

So I just finished up almost 2 months of using EngineYard Solo as my hosting platform. I recently cancelled my account and moved back to a Linode VPS (720) and I am actually much happier than I was on Solo. I figured since there are no reviews of the service to be found, I would write one.

I originally demoed Solo at MountainWest RubyConf’s Hackfest. Ezra Zygmuntowicz sat me down and took me through all setup process, posted our hackfest application, and than gave a whirlwind tour of the other features in the Solo control panel. I was very impressed even given the deployment hiccups we encountered (but Ezra was right there fixing them as they came up, if only I got that one-on-one service everywhere! ;) ). I got the app running, played around with different configurations, Apache + Passenger & Nginx + Mongrel. I was blown away by how easy it was to roll out an entirely new configuration, and within 2 weeks, I cancelled my Linode slice and moved exclusively to Solo. Maybe I expected too much, but that is when fighting the control panel became a daily activity.

Since a basic EC2 instance has 1.7GB of RAM, I moved 3-4 applications over from Linode. The control panel for Solo is awesome when it comes to establishing gem dependencies, and different application configurations (Rack, Merb, or Rails), but don’t expect the nginx / apache configuration to be as easy. As a default, when you create a new application it will only create a vhost configuration like:

<VirtualHost *:80>
ServerName refactorme.com
DocumentRoot /data/refactorme/current/public
</VirtualHost>

This configuration works fine if your only hosting one application on your instance, but most people are not doing that (from other’s I know who also use solo). When you have more than 1 application running on an instance, and lets say you added refactorme second, and you visit www.refactorme.com, apache will route you to the ‘default’ or first application defined. This caused many headaches because I would have to manually login to the box, add ServerAlias www.refactorme.com, save, and issue an apache config reload. Not so bad, right? WRONG! If you ever change your configuration from the control panel, it is like your deploying a fresh instance, that configuration file you manually changed isn’t saved. This makes the main selling point of EY Solo completely useless when redeploying configurations actually causes more work. I reported this bug several times to the #ey-solo channel on IRC, but to no avail, it was never fixed. Somehow Flex and all these other redeploy features were added, but a simple task like defining an application to sit at a subdomain was never addressed.

It leaves a bad taste in your mouth to see new features being added that help make configuration and automated tasks being added only to see that you cannot use them since every deployed instance requires personal attention to add a mundane configuration change. Don’t get me wrong, the EngineYard Solo control panel is an excellent idea, but when your paying a $40/mo+ premium on top of EC2, but it can’t even get Apache configurations right, why would someone pay a premium to fight the control panel that is supposed to make deployment easier? Some may argue that EY Solo was intended as a staging box for testing and sharing apps between them, that would work fine if you only have one application running at a single time, but what happens the minute you need to QA two applications concurrently? Isn’t it supposed to mimic production, meaning that www.domain.com would point to the same place as domain.com?

Reia, Ruby/Python on the Erlang VM, presented at Boulder.rb

Made my way up to Boulder last night to hear Tony Arcieri speak about Reia, his implementation of a Ruby/Python-like syntax for the Erlang Virtual Machine. I have only just begun my venture into learning the world of Erlang, but the syntax is hard to digest. Tony’s inspiration for Reia came from trying to implement an actor model in Ruby similar to Smalltalk’s, but quickly realized that Erlang had the actor model he was looking for and decided to write a Reia instead. Building Reia on the Erlang VM also allows all code to be run concurrently, one of the big drawbacks to most OO languages. Reia is not without is drawbacks either. All variables are versioned (more later) and each instance will spawn a new gen server which makes garbage collection difficult unless you utilize linking techniques to build a tree structure or call @thing.kill() explicitly. Variables are versioned in Reia since Erlang does not have the concept that variables can be reassigned. To get around this, Tony creates versioned variables which converts from Reia’s syntax: a = a + 1, to Erlang syntax as: A1 = A0 + 1. There are a handful of things missing from Reia that are either planned or purposely absent: Loops cause a dead lock, instance_eval is planned, Mixins? Still up in the air on implementation, Metaclasses, and a handful of other niceties of Ruby. The tradeoff though is the ability for powerful pattern matching, concurrent code, a messaging protocol, and no more ugly Erlang syntax. To me its a great win for anyone who needs concurrency and speed, but does not want to fight the righteous Erlang fight. Thanks again to Tony for the great talk!

Sinatra Tech Talk by Corey Donohoe of EngineYard

This past Wednesday, Corey Donohoe stopped by the office to give a tech talk during our weekly brown bag. He covered a range of topics all revolving around Sinatra / Rack. We recorded the talk and posted the slides online. This is the best Sinatra talk I have watched, he gets into best practices and how Sinatra can be used as middleware or Rails metal.

Sinatra 0.9 – Rack, Middleware & Metal.

Slides from Sinatra 0.9 – Rack, Middleware & Metal

Pairing update and other miscellaneous happenings

Usually don’t tend to post updates unless I have something to announce, but figured it was due since I have had quite the response to my pairing post. I actually do agree that pair programming is very useful and effective given the right task. At the time I was pairing for nearly a week on nothing but CSS stylesheets and that was really just a waste of a pair’s time. If it wasn’t for the frustration that I was going through, I think that the article would have taken a much different stance.

Outside of that, I am now a 100% emacs user when working on projects. TextMate has changed to just a “TextEdit” alternative when I need to edit miscellaneous configuration files and don’t feel the need to launch up the entire emacs environment. Also I have been focusing my free time between RefactorMe launch, learning Erlang / Clojure and getting another project rolling. Hopefully I will have a more interesting post soon with details on the new project and with a new facelift to the ol’ blog.

RefactorMe initial launch after server problems.


A project that began nearly three months ago has finally launched. The initial work was halted due to time constraints, but was reborn at the EngineYard Hackfest at MountainWest Ruby Conf this year. With the some help from EY Hackfest participants, I was able to get enough of a jump start to finish the application. This also is my first app ever launched on EngineYard Solo, which so far has been amazing. This also means that I have departed from my long time host, Linode. Anyway, head on over and check it out. The idea is 1 refactor is posted a day, you reply and see if your refactor is voted the best for the day. Let your code speak for itself!