The Blog

Posts from October 2010

Oct 29

Brightcove gem 1.0.3

By David Czarnecki

I just pushed out version 1.0.3 of the Brightcove gem. This version adds support for performing a file upload, which is useful if you need to create a video in Brightcove. I did have to add a dependency for Rest-Client to support the multipart file upload. Thankfully it all just worked.

Oct 28

Random Number Entropy, Xen, and You

By Jeff Hagadorn

Here at Agora Games, we are strong proponents of cloud computing for a number of reasons. The ability to scale outward quickly in a time of need continuously aids our processes, encouraging rapid growth and timely response when load increases past the threshold of what our infrastructure can handle. As such, we tend to run most of our applications on scalable cloud providers.

Recently, we decided to move one of our older sites to Rackspace Cloud, which is a relative newcomer to the cloud market who uses Xen for their hypervisor of choice. Here at Agora, we use an efficient application stack that consists of NGINX, which proxies back to haproxy, which in turn load balances to many FastCGI app servers on our backend in order to do the heavy PHP lifting in the most efficient way possible. We have been very happy with the results so far.

After deploying this old site on these shiny new cloud hosts, everything appeared to work great. The site was faster than ever, we had brought all of the web server configs up to date (translated from Apache, which was used on the old hardware based servers), and tuned everything to be lightning quick. Finally, the celebrated day to flip the switch came…

…and the site fell flat on its face within seconds.  All of the servers were idle, memory usage was minimal, there were no IO bottlenecks – we were stumped.

Eventually, we took out an engineer’s best friend – strace. Upon running stracing the php threads, we found that each site load was polling from /dev/random, which these days is about as far from a best practice as you can get. Examining the entropy pool, it turned out that it was continuously draining, and waiting to refill, and some old Crypt routines were to blame. We instructed php-mcrypt to use /dev/urandom by way of MCRYPT_DEV_URANDOM, and pushed the site live again. Suddenly, all servers went green. Success!

To get down to it, the problem is with Xen and how it’s virtual drivers work. Apparently, the virtual drivers do not add to the entropy pool for the system’s random number generator, causing the pool to empty extremely quickly. The Xen team has known about this problem for a number of years, however it appears they have not fixed it. Using /dev/urandom, which one should always do anyway, eliminates this problem by providing a nonblocking source for random seeding. Yet more proof that going over old code and fixing bad practice can often prove beneficial. :)

Oct 27

Resque and Resque Unit in Rails 3

By David Czarnecki

Do you need to create background jobs, place those jobs on multiple queues, and process them later? And do you want to test your queue appropriately? Are you using Rails 3?

If your answer to those questions is yes, then you’re probably already looking at and using Resque and Resque Unit. I really just want to cover the nice part about using these libraries in Rails 3. Let’s cover the basic setup.


 # Redis/resque

 gem 'resque', '1.8.2'
 gem 'redis', '2.0.12'
 gem 'redis-namespace', '0.10.0'

 group :test do
 gem 'factory_girl_rails', '1.0'
 gem 'mocha', '0.9.8'
 gem 'resque_unit', '0.2.6'


 require 'resque'

 redis_config = YAML.load_file("#{Rails.root}/config/redis.yml")
 Resque.redis = redis_config[Rails.env]
 Resque.redis.namespace = "resque:company:namespace"


 development: localhost:6379
 test: localhost:6379
 staging: localhost:6379
 production: localhost:6379

Here’s the kicker. As we’re defining resque_unit in the “test” group in our Gemfile, it’s going to “provide a mock Resque for testing Rails code that depends on Resque”. Now we can make assertions in our tests about data in Resque without having to have Resque running. Pretty simple right?

P.S. The answer to that last question is “yes”.

P.P.S. My code in the Gemfile does have indentation, the code formatter on our blog sucks.

Oct 25

Amistad: Friendships in Rails 3

By David Czarnecki

If you’re looking for a way to do friendships in Rails 3, you might have a look at Amistad. I added support for blocking friendship requests and those changes have been integrated into master. One of the benefits of contributing this code was I got some exposure to RSpec.


Oct 25

Hang In There Baby

By David Czarnecki

How long should you keep a git fork around?

Here’s the flow: I forked Amistad, a library for friendships management in Rails 3, to add blocking friends support. I wrote the code, tests, and updated documentation. I generated a pull request for my changes. The author of the library merged those changes into the master branch for Amistad.

*So, how long should I keep my git fork around? *

After writing this post, I’m going to remove the fork because the changes have been integrated into the master branch. I assume that’s a reasonable thing to do as there’s no divergence between my copy and master. And I don’t want anyone to search for my branch, find it, use it, and then later have issues that a) need to be fixed or b) want to contribute more functionality. I want all of that to happen in the library’s master branch.

Is that reasonable? Or is there a period of time I should keep my fork around for? Am I overthinking this? I’d just like to know if there’s a better workflow or standard that the community has adopted in this regard.

Oct 19

Getting Cozy with Shorthand CSS Properties

By Joshua Childs

I pride myself in being forgetful, but sometimes this can have unfortunate consequences. For instance, whenever I want to use the css background shorthand property I simply can’t remember the order.

In case you aren’t aware, the background shorthand basically allows you to specify a background all at once, that would otherwise need to be specified with multiple rules.

For example

background-color: black
background-attachment: fixed
background-position: left top
background-repeat: no-repeat
background-image: url(example.gif)

simply becomes

background: url(example.gif) no-repeat fixed left top black

And the whole world is happy…

As I mentioned the problem is I find it difficult to remember the order, and it seems that there is an order that should be followed, if for no reason other than consistency. As a result I always find myself turning to Google to remember what that order is. This is frustrating, but even more frustrating Google never returns the result I’m looking for and I end up leafing through several results to eventually stumble upon a code example that can help me.

Well, not anymore! Turns out there is an easier way then this and one which doesn’t require me to resort to hardcore memorization (my only weakness). As anyone who really knows me is already aware, I love Firebug. The reasons go on and on, but now I have a new one. Firebug automatically fixes the background style rule providing the complete and proper format. If you specify a background rule and just give it say a color, or take your best shot at specifying all the properties you need then leave the style pane for a second or two and close your eyes, by the time you come back Firebug would have parsed and updated your best effort with the correct format. How nice.

Once I realized this, I couldn’t help but share my excitement with some of the fellows around the office. Well, our new teammate Nick pointed out that it would be cool if this worked for the font shorthand as well; I thought so too. As it turns out however, it does not. That’s really too bad, but maybe we will see this feature come along in the future. I think it would be a welcomed addition all around to an already spectacular tool. Thanks Firebug!

For anyone who wants to know a little more about all the CSS shorthand rules here is a nice article I found on the nets about it.

Oct 11

Agora visits the University at Albany Career Fair

By Clarke Foley

Ernst and Young recruiters gave away silver pens, designer platinum-cased post it notes and travel coffee mugs. KPMG gave away environmentally friendly thermos bottles and key chains. They also had a really, really nice sign.

Then there was Agora Games… Being new to the recruiter role, Blake and I wore our beards and normal work attire, which included one mohawk and an obnoxious pair of florescent yellow Nikes. While perhaps not as sharp as other recruiter’s suits and ties, we were definitely dressed for success.

The UAlbany Career fair saw hundreds of students from several degree programs trying to get a feel for which industries and companies were scouting future hires. As the university is known for its strong business school, we were offered numerous resumes from accounting, business administration and communications majors. A welcomed change of pace from our everyday engineering-focused mindset, it was interesting to chat with English majors, marketing majors, and the surprisingly frequent–and not surprisingly somewhat pushy–“my boyfriend plays video games all the time, can he work there?” career fair candidate.

As interesting as this was, we were on a mission that was a bit more technically focused. Our goal: track down as many people as possible who were interested in Ruby on Rails, Python, JQuery, or Flash, while using our less than KPMG-worthy sign. We were given resumes from computer science  and information science majors, and information technology management buffs. Scouring the selection, scarcely did we find that “gem” we were looking for…literally, nobody knew what a Ruby Gem was. (har har!) All puns aside, we’re continually finding this to be the case at most of the college career fairs we visit. In this university setting, to a polytechnic institute setting, (yes, reference intended), it seems that the most valuable coding language and most sought-after job skill in today’s software development field is concurrently the least taught.

As we collected information on the student’s school-based skill sets, it was clear that the top engineer of tomorrow might also be the person who is learning coding languages on their own. Take heed, soon-to be-grads; spend a few weekends brushing up on some of the aforementioned languages. Scout outside the classroom walls to see what languages the smaller, innovative companies are using. Scour Craigslist to get a feel for what types of development work is being outsourced in your area. Who knows, you might see Blake and I at your upcoming career fair, mohawks and yellow sneakers adorned, looking for the next Ruby Wizard.

Oct 7

Testlink - bringing order to testing

By Devon Smith


If you start searching for test tracking and management software, you will run into Testlink. Although far from perfect, Testlink does some pretty cool things.  In the past, I kept track of my tests on proprietary software or open office spreadsheets, which are functional- but the organization offered by testlink moved my whole testing approach to a new level.

The Good:

Open Source

Test case/requirements/test plan organization

requirements management

requirements based testing

result reporting

central location for assigning, approving and executing tests

The Bad:

It is a bit clunky to use

UI is pretty horrible

Minor bugs and unfinished features

Isn’t set up for a ton of integration- but there is an API

The results:

This tool opens up the testing process for anyone on the project to be aware of what QA is working on. Communication between QA and Devs can be improved (as everyone can access and review test cases or requirements), and the approval process is much easier and more organic than holding a big meeting. Test link has the potential for seamless integration with bug filing  helping to carefully order and maintain a tester’s world. It doesn’t come pre-linked to much, but the site does offer some instructions on setting it up yourself. It does offer a good user guide and a pretty active community for support.

You can input your documents (I haven’t found a way to do this automatically, but manually putting them in does ensure that you do careful ambiguity review) and then link each requirement to a test case, or generate test cases right from the requirement. The execute section can accept xml results and notes. Testlink automatically generates test plans and test reports with data from the system, so you can put out a document that shows your test plan, and then gives overviews of your test cases and tracks the requriements. It has been extremely useful for increasing transparency in the QA department and keeping everyone involved with the process. There is a way to create custom fields, which I have been used for test plan approvals and linking to bugs filed from the execute screen.

In all, it is a great program- that could use some finishing tweaks and an UI overhaul. I can look past its flaws though for the functionality it provides. The functionality really is pretty cool. For multiple projects and teams, it makes organizing the test process easy.  Testlink is a great little program that can act as a hub for testing related activities.

Oct 6

Data relationships in NoSQL (P.S. They're real and they're spectacular)

By David Czarnecki

Do people really think there are no relationships between data in NoSQL databases? Or that they’re doomed from the start?

I’m going to demonstrate a very simple relationship among data using MongoDB and Mongoid.

Let’s first define a user.

class User
  include Mongoid::Document
  include Mongoid::Timestamps

  attr_protected :_id

  field :nickname
  field :first_name
  field :last_name

  references_many :activity_items

Users are an active bunch, so let’s keep track of their activity. The user model references the activity items.

class ActivityItem
  include Mongoid::Document
  include Mongoid::Timestamps

  attr_protected :_id

  field :event_type

  referenced_in :user

  index :user

The activity item references a user.

Now, let me show you how this works.

dczarnecki-agora:project dczarnecki$ rails console
Loading development environment (Rails 3.0.0)
ruby-1.9.2-p0 > user = Factory.create(:user)
=> #
ruby-1.9.2-p0 > activity = Factory.create(:activity_item, :user => user)
=> #
ruby-1.9.2-p0 > user.activity_items.count
=> 1
ruby-1.9.2-p0 > activity.user
=> #
ruby-1.9.2-p0 >

I created a user. I created an activity and associated it with the user I just created. I counted the number of activities of that user. I referenced the user from the activity.

Any questions?