Shhhaw!

Better "Most Viewed" Story Lists with Chartbeat and Ruby

06/24/10
Ruby, code

Since I came across it about a year ago via a posting on Hacker News, I’ve been a big fan of the Chartbeat real-time analytics service. Last summer, I posted on their official blog about a hack I had come up with to generate top ten most viewed story lists from their API: Unlike conventional analytics platforms, Chartbeat doesn’t provide cumulative stats. Instead, their API returns “snapshots” of how many people are actually sitting on pages when you request the data. I wrote a PHP/SQLite script called stats_combiner that runs on a cron and collects and combines this live data. Every hour, it pushes out its flattened plain HTML list of “top ten stories.”

Since then, I’ve gotten a number of requests to open-source or otherwise describe this solution. So, I rewrote the script in Ruby and have added a number of features since the original PHP implementation. It’s now available as a gem, and TPM’s first official open source release.

One of the coolest differences between the gem and the original version is its extensibility. I found I had to keep changing the original script to modify data chartbeat was producing before I could surface it on the live site, such as accounting for subdomains, stripping out query strings and excluding certain records like landing pages and other “non-story” pages. The new version of stats_combiner has a Filterer class for setting these rules. Check the README for more about how it works. If you run a content site, this is the easiest way to set up a top ten widget.

Install it with gem install stats_combiner.

Additional shameless plug: stats_combiner 0.0.3 now comes with my brand new chartbeat gem which makes it super easy to access all of the Chartbeat API endpoints. With the new chartbeat gem, getting a list of the top ten pages readers are perusing right now is two lines of code:

c = Chartbeat.new :host => 'yourdomain.com', :apikey => 'yourkey'
c.toppages :limit => 10

To get the chartbeat gem, run gem install chartbeat.

Fourrific is a Foursquare Client for Your Computer

04/ 4/10
Design, Fourrific, Foursquare, Sinatra, code

I’ve been a lukewarm Foursquare user for a while, but it wasn’t until I attended SXSWi last month that I really started getting into it. It’s an awesome app for when there are a ton of people ‘playing’ within a relatively-constrained geographic area. Nevertheless, I brought the checkin habit back with me to New York, where I spend a lot of time sitting at a desk.

At that point, I realized that Foursquare: the Website pales in comparison to Foursquare: the App mainly in that it doesn’t give you a feed of your friends’ activities. I really wanted a Twitterific-style narrow column that I can keep around on my desktop to see where people have checked in recently without having to pull out my phone.

Fourrific screenshot

So, in one day of coding (and a couple more for bugfixing, styling and error handling), I built Fourrific, a really simple Foursquare app.

Fourrific is very glued-together: it’s based on Sinatra, my current favorite web framework, and a slough of gems. It authenticates to Foursquare via OAuth, and finds your location through your IP address via Geokit, though that can be hit-and-miss depending on your ISP (for example, when I’m at my desk in Chelsea, it thinks I’m in the Bronx). With that data, it can (very roughly) tell you how far away each person is, gathered from the <distance> node the Foursquare API returns if you pass it latitude and longitude parameters. If Fourrific thinks someone is more than 25 miles away, it will fade out that status, and hide it behind the “Everywhere” tab (the default active tab is your current city).

On the frontend, I’m using the beautiful new open source font Raleway from the League of Movable Type (embedded with @font-face), and the HTML5 <time> element, which the jQuery plugin Timeago can latch onto, to generate relative dates.

Of course, the source is available on Github with installation instructions if you’d like to fork or run your own instance. Though, to just start using it, go to:

http://fourrific.shhhaw.com

and log in through OAuth. There is no database whatsoever, so none of your information is stored on the server, and the session cookie only lasts until you quit your browser or revoke your OAuth token.

Check it out, on your computer.

Elsewhere

More