The Blog

Posts from 2010

Dec 10

CAPTCHA failed or How I Patched ruby-recaptcha In 5 Minutes For Success

By David Czarnecki

We are using the ruby-recaptcha library here at Agora Games. I got a bug from our QA department that they wanted the CAPTCHA failure message to change from ‘Captcha failed.’ to ‘CAPTCHA failed.’.

I love that the Ruby and Rails community is so test-focused. I looked at the ruby-recaptcha issue tracker and there was already a patch for adding in customizable message support. However, with the patch, none of the tests passed. It was well within the library author’s rights to give that patch the middle finger.

So, what did I do? I applied the patch to my local copy of the ruby-repatcha library, fixed the tests, and submitted an updated patch.


You can find more hilarity over on my Twitter account, CzarneckiD.

Dec 9

Hello there...

By Steven Davidovitz

I’m Steven. I hail from the suburbs of Boston and I’m currently a 3rd year student at the Rochester Institute of Technology where we are required to do a minimum of 12 months of full time co-op before graduation. Agora Games is my 3rd and final co-op experience and I’m very excited to be working here!

Dec 9

Lightweight concurrency with Ruby and Eventmachine

By Steven Davidovitz

Eventmachine describes itself as a “fast, simple event-processing library for Ruby programs.” Included in it is a module called Deferrable that allows easy and lightweight concurrency. Deferrable makes it simple to spawn a blocking or long running operation, push it to the background, and on completion execute any number of code blocks (callbacks).

Below, I’ve written a sample application that uses the Deferrable class and Eventmachine’s event loop to parallelize HTTP API calls to

{% gist 734988 %}

As each request is created it placed in a pool with all other requests which are then spawned and executed after a call to As the GET calls come back they are checked for an error message and based upon that the appropriate callbacks attached at the creation of the request are called. In this case, if the call succeeds each representative for that zip code is printed out along with a phone number. If it fails, the error message is printed. As the output below shows, the calls are done completely in parallel and immediately after they return the callbacks are executed.

{% gist 734989 %}

As the number of requests increases, so does the performance benefit of using this model. Example timings for 25 requests done serially and in parallel are below.

{% gist 735018 %}

Dec 2

My "Freedom Patch" Gem: constant-redefinition

By David Czarnecki

The constant-redefinition gem allows you to define constants if not defined on an object and redefine constants without warning.

Are you still with me? Good.

The code “credit” for this gem comes from the Stack Overflow post, “How to redefine a Ruby constant without warning?”. It just so happens that I was working on a project today where our test suite was testing a large number of iterations to write out data. I wanted to redefine the number of iterations in test (based on a constant in the model) to respect the spirit of the test, but not do as many iterations in test. I googled, found that post, and it seemed like a neatly packageable item that would be useful to other developers.

So, I created the constant-redefinition gem. You can also check out the GitHub constant-redefinition project. My contribution was merely packaging it up as a gem, formalizing the tests, and making the method names longer (sue me, I prefer readability).

The project page has a good overview of using the two methods, but I’ll reproduce it here.

{% gist 726069 %}

You may know “freedom patch” by its other names, “monkey patch” or “duck punch”.

You can find more hilarity over on my Twitter account, CzarneckiD.

Nov 30

To Version or Not To Version Your Gems in Gemfiles

By David Czarnecki

I don’t like moving targets. I’m a software developer, not a sharpshooter. So why don’t more people version all of their gems in a Gemfile?

Here is a sample Gemfile for a Rails 3 application I was looking at yesterday.

{% gist 721842 %}

The gems for Rails and thin have been versioned. Why aren’t the gems for will_paginate, nokogiri, and haml versioned? I consider un-versioned gems moving targets. Why? You’re going to get the latest version of a gem. The developer doesn’t know (or necessarily care) you depend on XXX functionality in version 1.0.23 of their gem. And so what if in version 2.0.0 of their gem, they make incompatible changes that break your application? I consider versioned gems a virtual “stake in the ground”. To the best of my abilities, with rigorous testing of course, I know that given these specific versions of gems, my application performs as expected.

What’s your opinion?


Good point from my co-worker, Blake, who says that bundle will install the lastest version of a gem and then lock the version in your Gemfile.lock file on the first go-round. It could still be an issue if you do a “bundle update” locally or in your deployment process.

You can find more hilarity over on my Twitter account, CzarneckiD.

Nov 30

A Better Way to Avoid a Project Named Server

By Blake Taylor

Yesterday I posted about how I avoided creating the annoying rails server projects when accidently running rails server under a rails 2 application. I wanted to follow up with a much more concise script that accomplishes the same ends through different means. Using this script requires no changes to how you start the development server and, even cooler perhaps, allows you to start the rails 2 server as if you were in a rails 3 project. Shout out goes to Intern Mike for the assist.

{% gist 722473 %}

Nov 29

Moving to Rails 3 Pain Point: rails server

By David Czarnecki

Update: I have posted a better solution!

Working with rails 2 and 3 projects back and forth, day to day has been pretty painless thanks to rvm and .rvmrc files. That is with the exception of accidentally running rails server on a rails 2 project. I do this all the time and it results in generating a new rails project called server rather then starting the rails server, my actual intention. It’s almost as frustrating when running script/server on a rails 3 project but at least it doesn’t spit out a bunch of useless files. Incidentally, all of the built in rails command (i.e. generate, console, …) set the same trap. To avoid falling prey, I have created a bunch of shell functions which I would like to share with everyone in case they would like to be privy as well.

The shell code is included in the gist below. I load these functions into my .bashrc file (actually my .zshrc file). Once they are are available just get in the habit of running rails-server or rails-generate or rails-whatever and the correct command will always be issued. Also, if anyone knows a better solution, do share!

As one final note, I run rails-server so often that I have is aliased to s . If you would like to do the same add alias s=rails-server to your .bashrc file.

{% gist 720619 %}

Nov 24

Interactive Git Stash For Stashing Single or Multiple Files

By David Czarnecki

TL;DR git stash save –patch

From the git docs, “With –patch, you can interactively select hunks from in the diff between HEAD and the working tree to be stashed.”

This past week, I came across a situation where I wanted to stash a couple of working files in a git repository, pull in some changes, and then apply the stash. However, I couldn’t immediately see the forest for the trees or some other stupid metaphor. Basically it was just a case where I had to RTFM for git stash. In the gist below, I go through a simple example of stashing 2 out of 3 files, making some changes to the repository, and then applying the changes of the 2 stashed files.

{% gist 714660 %}

I hope you found this example useful. I know that it’s some git-fu I’ll be using more often.

You can find more hilarity over on my Twitter account, CzarneckiD.

Nov 23

By David Czarnecki

If you’ve ever wanted to access your Halo:Reach statistics from Ruby, you can now using the Halo:Reach Ruby gem.

The API methods should be pretty self-explanatory and you can check out the gem’s RDoc online or look at the unofficial API method documentation for more information. Maybe the one caveat to getting involved in the project or using the API in general is that you need a Bungie Pro account to generate an API key. This will cost you 750 MS points per year. An 800 MS point pack will cost you $10.

You can also get involved in the development of the API over on the Halo:Reach Ruby API GitHub project.

You can find more hilarity over on my Twitter account, CzarneckiD.

Nov 23

Agora Games & Major League Gaming participate in the web's first multicast transmission

By David Czarnecki

When you send a unicast message it gets routed within a network to a single destination.  Unlike unicast messages, multicast messages get delivered to every node within a network.  If not properly controlled however you can experience routing loops which, like feedback between a microphone and a speaker, cause what networking techs call “multicast storms”.  Because of this many corporate networks block multicast messages from ever leaving a single broadcast domain.  For the same reason, multicast messages are blocked by all Internet Service Providers at the network’s edge.

Apparently it was just a matter of time until someone with a big enough backbone started letting them through.

On November 12, 2010 during Major League Gaming’s National Finals in Dallas we working with AT&T and Octoshape to deliver the first open-web multicast video stream.  Who doesn’t love the bleeding edge?

Check out the details here:

More musings can be found on my Twitter account, genexp