Basic funnel tracking in Rails

February 13, 2011 - 2 Comments - elite command analytics ruby rails

This is the first in a series of articles I intend to publish about the technology, philosophy, and process behind my latest Rails project, Elite Command. Elite Command is a turn-based, multiplayer strategy game, and a lot of interesting approaches were taken in developing for its unique requirements.

Before I get too into the grittier aspects of the game, I’m going to cover something which applies to any web application which strives for commercial success: analytics.

Having designed and maintained various analytics platforms over the last three years, I’ve learned a thing or two about best practices and capable architectures for supporting the requirements of a robust analytics infrastructure. I’ve also learned a lot about the types of metrics which are most useful in a business sense. With this knowledge, adding analytics to Elite Command was a matter of choosing the 20% effort which would yield 80% of the useful results. That’s why the first analytics tool I baked in was funnel tracking.

Note that my code is using MongoDB with Mongoid for the ORM, but that this is all just as applicable to whatever data store you may be using…

Read more…

SimpleFacebook: A stupid-simple wrapper for the Facebook API

April 02, 2010 - 0 Comments - ruby facebook

I recently encountered a need for a minimal wrapper for Facebook’s API, so I wrote SimpleFacebook. Clocking in at just 56 lines, it’s perfect for interfacing with Facebook via Ruby, and nothing more. This is not intended as a replacement for Facebooker or RFacebook. It doesn’t provide any explicit Rails integration, such as controller filters for gating users. It only does the dirty work of putting together a valid API request and returning the results, deserialized from JSON. Example usage:

What is it useful for? My use case was an asynchronous worker which needed to grab some data from Facebook to be stored in a database somewhere. A Rails process was not necessary to do this, so loading up Facebooker or RFacebook seemed like overkill.

Someone else might find it useful, so I’ve released it under the MIT license. Everything is up on GitHub, which you can download and install as a gem (using rake install). The code is fairly simple, and fleshed out with specs.

Read more…

Bluepill: Low-impact process monitoring

November 06, 2009 - 0 Comments - ruby tools bluepill god

At Serious Business, we’ve been using God to monitor long-running background tasks and other daemonized processes. While God provides a nice DSL for configuration, it has issues with memory leaks which forced us to keep a close eye on it (meta-monitoring?) and reboot it periodically via cron.

To remedy the problem, a few of the guys got together over a weekend and wrote Bluepill, a replacement monitoring tool with a DSL inspired by God, but written for low memory consumption. Check out Arya’s blog for a detailed explanation and breakdown of Bluepill’s features. See the graph comparing Bluepill and God memory consumption over time. You’re sold.

Defend your Rails from spam with Akismet

July 24, 2009 - 8 Comments - ruby rails spam tools akismet

When I decided that I would roll code.isdangero.us as a custom-made blog in Rails, I thought of it as a fun, easy project. After all, blogs are simple, and the simplicity allows for plenty of room for attention to detail in making the code as tight as possible, similar to the way a haiku allows a poet to express his skill in language through the power of the simply-stated.

Of course, every project looks easy from a distance, because unforeseen problems are just that: unforeseen. It had been a while since I’d blogged, and therefore I had all but forgotten about the long war of blog software against the endless networks of compromised Windows machines turned into Viagra-pitching zombies, comparable in number to the mighty armies of ancient Persia.

Enter Akismet

Just as the 300 men under the command of King Leonidas of Sparta held back Persia’s onslaught by fighting in the shade, the forces of good in this war have gathered together their disparate forces into a collective known as Akismet.

Akismet is an API which tracks spam and ham submissions from participating blogs all over the world, building its knowledge of what spam looks like versus c…

Read more…

Making custom SQL play nice

June 24, 2009 - 2 Comments - ruby rails activerecord sql

So let’s say you have a custom SQL query which, for one reason or another, doesn’t fit nicely into ActiveRecord’s finder options. Here is an example using a subquery:

This query does just what the method describes. If you call Order.average_revenue_per_month, you will get back the average total revenue from orders each month. Great, that was easy!

What about associations and named scopes?

Hold up. ActiveRecord provides a great framework for mapping database tables to objects which can do amazing things as long as you stick to the basics. One of those things is the ability to call class methods on associations and named scopes. For example, we can call User.find(1).orders.average_revenue_per_month, and it should do exactly what you expect it to within the scope of that particular User’s Orders. But that only works if you’re staying inside the bounds of ActiveRecord’s finder methods.

In this case, it would be impossible to fit our query into the standard finder methods and still have it work with associations and named scopes as expected. So what do we do, throw our hands up in dismay an…

Read more…

Arduino and Ruby on Leopard

June 01, 2009 - 4 Comments - arduino ruby tools

The Backstory: I spent the majority of my last Saturday at the Maker Faire, an event centered around showing off all the amazing things that people have made themselves. Everything you can think of got due coverage, from robotics to custom musical instruments to automated fabrication to clothes and food. It was a great event and I’d recommend anyone with the hacker spirit to check it out next year.

While I was there, one of the focal points of my interest was around all the amazing things being done with the Arduino, a small circuit board with a microcontroller, programmable through USB. I had read about it before, first I believe in connection with Archaeopteryx, the probabilistic step-sequencer from the venerable and widely-hated Giles Bowkett. My curiosity was already primed and ready by the time I discovered the Arduino starter kit, which included sensors, LEDs, jumper wires, a book, and other assorted things I needed to begin pursuing my long-dissuaded desire to hack around with physical computing…

Read more…

Facebooker Queue: Facebook API queues with Beanstalkd

May 23, 2009 - 49 Comments - ruby rails tools facebooker queue facebooker facebook

I’ve been working on a Rails-based Facebook app using the excellent Facebooker library, and the need became apparent for a background queueing service for calls to Facebook’s REST API.

I had already decided to go with Beanstalkd as a messaging queue for its fast, in-memory modus operandi, because this particular app makes API calls at a frequency comparable to the birthrate in China. Well, maybe not, but the potential is certainly there. I am also already using Beanstalkd in this project for purposes unrelated to the Facebook API, so I am married to it at this point.

There is currently a plugin called FacebookerMQ which uses its own custom database-backed queue. Since I had already decided on Beanstalkd and needed an in-memory queue, FacebookerMQ wouldn’t work for me. Also, I figured I could take things a step or two further.

So, without further ado, I am announcing Facebooker Queue (very clever name, I know). Not only does Facebooker Queue provide easy, transparent, drop-in API queueing for Face…

Read more…

Installing Beanstalkd on Leopard

May 21, 2009 - 0 Comments - ruby tools

Beanstalkd is a very fast in-memory message queueing service with a nice client gem for Ruby. It has been used to support message queueing for asynchronous processing on the Causes Facebook app, which is written in Ruby on Rails and supports several million users as one of the largest apps on Facebook.

Now that the introduction is out of the way, here’s I installed it on Leopard, since other instructions I found on the web didn’t work for me.

Install libevent

beanstalkd requires libevent. I already had libevent installed. You can find out if you have it installed by running locate libevent in the Terminal. If you don’t have it, get MacPorts if you don’t already have it, then run sudo port install libevent, which should get you up and running.

Install beanstalkd

  1. Download it
  2. Decompress it and then cd into the directory
  3. ./configure --with-event=/opt/local
  4. make
  5. sudo mv beanstalkd /usr/local/bin/

Assuming you didn’t get any warnings or errors, you now have beanstalkd on your machine! Run beanstalkd...

Read more…

The Ruby Toolbox

May 18, 2009 - 0 Comments - ruby tools

Given the recent discussion of tools this blog has hosted, I thought I’d link up to this interesting and very well-designed site, The Ruby Toolbox. This site tracks which Ruby libraries and tools are getting the most use, by categories such as testing frameworks and deployment automation, as well as a global list (which, unsurprisingly, is topped by Rails itself).

The data for this site is based upon the number of watchers and forks at GitHub, so it’s not all-inclusive, but it definitely provides for a great reference point. It’s also a cool way to just snoop around and see what’s out there. Check it out!

My test-driven Ruby setup

May 12, 2009 - 8 Comments - ruby tdd tools

I am a relatively recent convert to the mantra of TDD:

  1. Write a failing test
  2. Make the test pass
  3. Refactor

It took my involvement in writing an analytics API for the iPhone to help me see the light. This API was receiving millions of requests per day from hundreds of thousands of unique users, so every deployment of new code had to be rock-solid.

Of course, back then I was just using vanilla Test::Unit; we didn’t know any better. Since then, as I urged my colleagues to give TDD a shot, I have researched a number of libraries which take a lot of the pain out of writing tests. Here follows a description of my testing stack, along with brief explanations of why I went with them over the alternatives.

Shoulda

I love Shoulda. Stringified test names + nestable contexts + easy macros makes for well-organized, concise tests. The readable output it generates is also a great feature; consider the test below:

When this is run and it invariably fails, we get the following output:

Failure has never …

Read more…

Wha...?

11611e595f8866809b075a8e718e7600

Chris Vincent is a 20-something drummer, producer, and engineer from the Bay Area. This is where he writes whatever the hell he wants whenever the hell he wants to write it. Check your expectations at the home page.

Obligatory tag cloud

me san francisco bicycling ruby tdd css tools iphone games rails facebooker queue facebooker facebook arduino activerecord sql css tools development process company culture spam akismet bluepill god programming elite command analytics active record

Recent posts

Feed me

Atom is cool.

Get in touch

Questions, comments, ideas?
Let's talk.

Unabashed self-promotion

Recommend Me