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…
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.
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…
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…
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…
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…
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
- Download it
- Decompress it and then
cd into the directory
./configure --with-event=/opt/local
make
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…
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!
May 12, 2009 -
8 Comments -
ruby
tdd
tools
I am a relatively recent convert to the mantra of TDD:
- Write a failing test
- Make the test pass
- 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…
May 11, 2009 -
1 Comment -
ruby
tools
I love tiny ideas which are well-executed and useful. How many times in a single lifetime will a developer write code to output a progress indicator from a long-running shell script? dots alleviates this once and for all while borrowing the Test::Unit style we all know and love.
Just write this:
And get this output over the course of about 50 seconds:
..................................................
Finished in 50.23425 seconds.
50 total, 50 passed, 0 failed, 0 erred
Simple to add to your code, and nice, familiar output to let you know that, yes, the script is still working (or at least doing something). :)
Kudos to Stephen Celis for sharing this with us! You can git it here: http://github.com/stephencelis/dots/tree/master