Category Archives: Code

Introducing Punchcard.py

If you haven’t noticed, I like punchcard graphs.  I like them so much, I have a script that to generate them.  I’ve now released this script for everyone to use.

Punchcard.py is simple to use and I hope you find it useful.  It accepts a stream of unix timestamps and creates a punchcard graph. It can very useful if you’re trying to figure out days and times of activity.

How Do I Install punchcard.py?

The easiest way to install punchcard.py is with pip.  Just run

pip install punchcard.py

If you install it manually (by cloning the punchcard.py git repository and running python setup.py install), you’ll also need to install the dependency pygooglechart.

What options are available

The only option that is currently available is to change the filename. To do that, use the -f option like

punchcard.py -f tweets.png

How do I generate a stream of timestamps

For WordPress Posts, I Butchered the WordPress importer plugin. To use this, clone that repo and run

php punchcard.php export_file_name.xml | punchcard.py

For Twitter, I created a similar simple script. I have the script setup for retweets, original tweets and all tweets. I just change the echo line at the end depending on which I want to output. To use this script, I run

php twitter.php archive.csv | punchcard.py

What should I do if I find bugs

Please create a github issue with any bugs you might find. Please make sure to include steps to reproduce including a relevant data source file.

Inspiration

This script is largely just an abstraction of Bash History Punchcard by Matt Behrens. Without his work, this wouldn’t exist.

Final Notes

If you use punchcard.py to create any interesting graphs, tweet @aaronjorbin, I’d love to see that it’s being used.

The new AddThis.com homepage

Yesterday my team relaunched AddThis.com, consolidated our brand, and launched a bunch of cool new features. One of my favorite parts is the map on the homepage which shows real-time shares as they are happening.

The map on the AddThis homepage showing real time sharing data

The map was interesting to build. We wanted it to be fast, look good on all browsers (including mobile and tablets) and communicate the reach we have being on 14 million websites and reaching 1.3 billion (yes, with a B) users every month. To do this, I looked at options using Canvas and SVG, but ultimately decided that good old-fashioned HTML and JavaScript would do the job best. We do use SVG and Canvas for it though, just not in the traditional in browser way.

The map itself is built using Protovis which while no longer actively developed, includes multiple map projections out of the box. We then use PhantomJS to create a png from the SVG that Protovis spits out. The share icons are built in a similar manner. They are canvas circles that we build into a sprite and then use PhantomJS for the actual sprite construction. By scripting the generating of these two key images, we were able to tweak and play with colors simply and with real data. No need for our design team to fire up photoshop and send over an image. Change some CSS or JS, run the build script and everything is ready to go.

Take a look at the rest of the site. Our entire team did a killer job with these new features and styling. Will, Foo, Jeff, and Jim all wrote up other pieces of this launch. Greg also highlighted how to user the new Trending Content Tool in WordPress. Exciting times here at AddThis.

IRC Notifications from a remote machine to my mac

For IRC, I like to use Irssi on a server that I can always keep running and log into no matter what machine I am on. One of the initial challenges with doing this was getting notifications on mentions. I solved this by following the tutorial on Irssi, screen, fnotify and Growl on OSX. The only difference between his setup and mine is that my bash script to do the notifying is simpler. I’ve pasted it below for you to use.

#!/bin/sh

ssh harpua "tail -f .irssi/fnotify  " | while read heading message; do growlnotify  -t "${heading}" -m "${message}"; done

How do you solve the problem of IRC notifications from a remote machine?

In case you are wondering, all of my machines are aliased to Phish songs, hence Harpua.

EDIT: I’ve added the -s flag to growlnotify so that the updates are sticky and thus I see them when I get back to my machine if I’ve stepped away and I don’t leave people hanging.

Facebook shares some secrets on making MySQL scale — Cloud Computing News

When you’re storing every transaction for 800 million users and handling more than 60 million queries per second, your database environment had better be something special.

via Facebook shares some secrets on making MySQL scale — Cloud Computing News.

Facebook uses and pushes MySQL like no other. This article gives a great insight into how it uses MySQL to a level and degree like no other. Hattip Rich

Thoughts on Post Meta Boxes in WordPress

I’m generally of the opinion that the screen for adding content should be as simple as possible in a CMS.  It’s one of the reasons I really like the new Distraction Free Writing in WordPress 3.2 (sneak peek if case you haven’t seen it).  It’s why I was a huge fan of WordPress reducing the number of default metabox in 3.1.

This is why in the recently updated AddThis WordPress plugin, the meta box to disable AddThis on a post by post basis is disabled by default.  While it was a feature that users requested, it wasn’t something that people were beating down the door to enable.  I decided that thus for the majority of users, no reason to make the display show more than they need.

It was super simple code wise. All of this code sits inside of a class that controls all of the post meta box:

// These two lines are inside a function the hooks into init.  $screen equals post and page
add_meta_box('addthis', 'AddThis', array($this, 'post_metabox'), $screen, 'side', 'default'  );
add_filter('default_hidden_meta_boxes', array($this,  'default_hidden_meta_boxes' )  );

function default_hidden_meta_boxes($hidden)
{
    $hidden[] = 'addthis';
    return $hidden;
}

Now the addthis metabox will be hidden by default. Next time you add a post meta box to WordPress inside a plugin, ask your self if it’s one that all of your plugin users will need.

Learn more about AddThis for WordPress 2.1

Barcamp News Innovation Philly Hackathon Project

Part of Barcamp News Innovation Philly is an open data hackathon.  I wanted to do a live visualization of something and I wanted to use canvas.  What I did is create a “Paint thrown against the wall” visualization of tweets tagged #bcniphilly.  The color of the tweet is specific for the user, the size of the circle is based on the length of the tweet and the location is based on the id (so it’s pretty random).  It will take a moment to load the most recent tweets and auto updates every five seconds.  I’ve only tested it in Chrome (so no promises that it will work in anything else)  Check it out!

Flot – sexy graphs created in JavaScript

I recently had the opportunity to speak at the DC jQuery User Group during an entire meetup dedicated to charts and graphs. Russel Heimlich presented on Google Charts and Chris Bannon presented on Wijmo while I had the honor to present on Flot.

When AddThis switched to Flot, I had a chance to build some really cool charts. This was my opportunity to get some more developers interested in Flot. You can check out my slides and my Sample Code. If you’re looking for more information, check out Flot on Github or the old Google Code site.