The Blog

Posts from December 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.