Graphing Total Daily Tweets
- As noted by others, Twitter is busier on weekdays than on weekends
- Notice the traffic surge during the November 2008 elections
- Notice the decrease over the 2008 Christmas holidays

http://favicons.linkriver.com/f1/25/twitter.com.ico
require 'favicon' require 'mcqueue' q = MCQueue.new(QUEUE_SERVER, QUEUE_NAMESPACE) map '/' do run FaviconAdapter.new(q) end
require 'rubygems'
require 'thin'
DEFAULT_HEADERS = {
'Content-Type' => 'image/x-icon',
'X-Accel-Redirect' => '/protected/default.png'
}
class FaviconAdapter
def initialize(queue)
@queue = queue
end
def call(env)
req = Rack::Request.new(env)
//
// A couple of lines removed to parse the request and
// push it to memcached...
//
[200, DEFAULT_HEADERS, ['']]
end
endProgramming Ruby, better known as the Pickaxe, the most valuable "programming book" on my shelf. Actually, it doesn't live on my shelf, it lives on my desk. I've learned and used lots of languages over the years but I never remember using a reference book like this before. Ruby is an incredibly rich language and I find myself "mining" the Pickaxe looking for cool ways to fix problems and writer shorter and more readable. Here's an example of refactoring a simple method.
Start with a hash object called params. A hash object is just a list of name, value pairs: this1 = that1, this2 = that2, etc. I have a hash object and want to build a URL query string out of it. We need to string our variables together to get something that looks like this: this1=that1&this2=that2&this3=that3. The key are joined to values with an equals sign (=), and the combined values are joined with an ampersand (&).
Here was my first crack at the code.
This works, but it seems longer than necessary. So here's take two.
This code works, buts its not very readable. I wonder if there isn't some cool Ruby method that help us clean this up. Thumbing through Pickaxe, we find that the Hash object mixes-in Enumerable, which has a method called collect that should make things easier. Hash::collect iterates over a hash, processes each item according to a block, and returns a new array - perfect. Let's use collect to create a new array of keys joined to their values with the equals sign. After that, we can use the Array::join to join the tuples with the ampersand.
This can be shortened...
... or even shorter, and I think just as readable ...
Tags: ruby, refactoring
I've been doing a lot of Ruby work lately and love the concise yet readable syntax. But its also tainting my appreciation for other languages. Instead of writing this in Ruby...
... PHP/Delphi/C++ makes me write something like this:
Of course you can pull off this one-liner PHP/C++, but its nowhere near as readable as the Ruby version, especially when something is an expression of any complexity.
Ah well.
I'm going to miss the Tour de France coverage tomorrow because I'll be on a plane up to Portland for the day. Normally I would catch the race on OLN.tv or on the "Live Tour" page at the official tour web site. The "Live Tour" page is pretty slick and provides updates every few minutes during the race, but that doesn't help me when I don't have web access. Hmmm....
I threw together a Ruby script last week when I took a similiar trip. It scrapes the Live Tour page for a given stage, looks for new news updates, and sends them to my cell phone. Use at your own risk - you'll get LOTS of text messages during the race. This is definitely a one-off implementation.

I've been developing web apps for almost 10 years (WinCGI, Cold Fusion back in the DBML days, ASP, ASP.NET, PHP, etc), and Rails is easily the most intriguing and exciting technology I've come across in a long time. The Rails framework takes away much of the repetitive drudgery you often run into in web app development. The learning curve doesn't seem too (though I'm still in the Ruby-is-a weird-looking-language stage) and the Rails book should help in that area too.
I didn't want to read a 500+ page book on the computer though, and also didn't want to burn out my laser printer, so I used Kinkos Online Ordering system. Its slick - you upload the PDF to them and pick up your print copy a couple of hours later at your local store. I wish all my books could be spiral bound!