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.

Test failure scenarios first

September 21, 2009 - 0 Comments - tdd

Lately in test-driven development, I’ve noticed that I tend to write tests against invalid input before I get to tests against valid input. This is a subtle technique which I think merits some discussion.

One of the big wins with TDD is the way that it forces you to think about the problem in terms of the API; this pushes the engineer to design to an interface, not an implementation, which is one of the major takeaways from the original Gang of Four book on design patterns. And I think the higher-level concern that designing to an interface facilitates is the process of knowing the problem domain, which leads organically into the process of dividing up responsibilities between discrete classes and modules.

In many ways, a problem domain can be defined not only by what it’s supposed to do, but also by its constraints, the cases in which it should fail. Thinking about these cases upfront, testing against invalid or nonsensical inputs, leads to software which is more resilient to misuse and unexpected scenarios.

I find that defining these c…

Read more…

Defend your Rails from spam with Akismet

July 24, 2009 - 2 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…

On sustainable development

July 13, 2009 - 3 Comments - development process company culture

Josh Susser at has_many :through has a great post about Discipline and creativity in the software industry. I find his comments on a sustainable development pace particularly striking:

One of the things I like best about working at Pivotal is that we consistently work at a sustainable pace. I can’t believe how many startups advertise jobs where they say that they expect you to work “startup hours”. I won’t even consider working at a place like that ever again. It’s not just because I don’t like working that way myself, but because I think companies that expect and require that kind of pace from their developers are just going to screw themselves and burn out their developers. They’ll either get real about what they can sustain, fail, or figure out how to deal with a high attrition/turnover rate.

I have had the experience of working at a startup which always demanded “startup hours” between tight, overlapping deadlines and indecisive clients, coupled with an organizational failure to adequately respond to their ever-fluctuating requirements. For the kicker, the company…

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 - 1 Comment - 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…

Myst for the iPhone and Riven X

May 19, 2009 - 2 Comments - iphone games

Myst was probably the first point-and-click adventure games I ever played, even before I played any of the older black-and-white adventure games (such as the excellent adventure games of Ray Dunakin). It had been many, many years since I’d played Myst, so when I heard it had been remade for the iPhone, I immediately cleared out enough music to make space for it so I could experience the mystery once again.

Due to my familiarity with the game, it didn’t take me long to crack the puzzles again, but the magic was still there, and quite intoxicating. Then I remembered that I had never played any of the sequels. Suddenly I felt incomplete as a human being, so I sought out Riven, the sequel to Myst.

Unfortunately, further development of Riven has been discontinued; the last build would only run in Mac Classic mode, a technology which no longer worked for those of us who have made the jump to Intel Macs. It seemed as though Riven was sadly going the way of the Ray’s Maze games, the advance of technology having left it behind.

Fortunately, one “Jean-Fr…

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

Recent posts

Feed me

Atom is cool.

Get in touch

Questions, comments, ideas?
Let's talk.

Unabashed self-promotion

Recommend Me