Charts & Graphs

I’m in need of graphing some data, and since I looked at the Google Chart Tools long ago but never did anything interesting with it, I figured I’d give it a spin.

Google’s API is pretty simple to use, you feed it a URL, and you get an image in return. Here’s an example expanded out a bit:

Each parameter controls some part of the image you get returned. (Want to see it? View the URL.)

You should get something that looks like this:


Wow… but not really. This is probably one of the simplest examples of a chart, but it serves my purpose.

Of course, since I’m not always content relying on others to host my data, I wanted a way to generate and store the image. You can do that too…

curl -o 20101130.png ',5,5,5&chco=ff0000&chxt=x,y&chxr=1,0,100,5|0,0,24,1&chd=t:3,3,3,3,3,3,3,65,38,46,60,59,56,58,36,21,13,62,2,3,3,3,3,2'

Just use curl to make the request and store the image in a file named 20101130.png (or whatever the date is, or file name you’d prefer.) Obviously you’ll need curl installed. If you need to generate a new chart everyday this is ripe for automating.

I also looked at jQuery Visualize as an option. It’s quite different than the Google Chart API as to how it functions.


With jQuery Visualize you don’t actually create a chart. Well, you do create a table of data, and jQuery Visualize does all the heavy lifting and creates the chart based entirely on your well-formed tabular data.

I sort of like this approach because there’s no external image files to generate, host, or worry about. You just make a table, and include a bit of Javascript. (Of course there are other concerns/issues, but simplicity is pretty high.)

I’m still evaluating what my final choice will be for my current project. If this were 10 years ago, I probably would have used Perl to generate the image files. If it were 5 years ago, I probably would have used Perl to generate some SVG files…

jQuery Visualize uses the HTML 5 Canvas element, so they get some points in the “innovation” column I guess… Also, jQuery Visualize requires less math, and in my world, the less math I have to do, the better!


Arduino: The Novel (nanowrimo)

Arduino: The Novel Last year I published a novel for National Novel Writing Month but because I am lazy and a terrible writer, I just wrote a script to write the novel for me. (The results were posted here: National Novel Writing

This year I did it again, and I’ve also published the code I used to write the novel. (See nanowrirobot on GitHub.)

The script needs a source to do it’s work. I did my original development by just pointing it at /usr/share/dict/words which creates some of the most beautiful gibberish you’ve ever seen. You can also just point it at a text file, and it’ll use the words in that. That’s what I did last time, and this time as well. Since this one is titled “Arduino: The Novel” it had better be about the Arduino, right? I ended up creating a word lists from the HomePage, Introduction, FAQ, and ArduinoBoardUno pages of the Arduino web site, and built a list of just under 1,000 words. The results were astounding…

    Written determined appropriate users Flash read SRAM. Protection a board also conditions or By. Lines making process short features draw preceding. Changes functionality please When power edge Not. What For bootloading we’d Windows inputs provides. Try manufacturers screw tutorials dimension teachers avrdude. Without want Single-Sided By leap released diagram. Which Cross-platform their directly pre-assembled bus 3V3. They inexpensive our Google downloaded by Debian. NG module off This standard Ground former. Additional short suggest do based tool Java. Upper commercial length ie up unofficial off. Current cool locally falling Mega Can supported. Board platforms Frequently conveniently map series Circuit. You’re compiles Auto You’ll general OSX compiler. On-board derivative troubleshooting documentation More Stamp Using.

And that’s not all!

    Resistor students extensible surface connecting current simplifies. Possible until Physically name pin number first. In each RESET-EN having inclusion be permission. Outputs explain taken try language help uploading. Discuss protection Mini have Linux to press. Some Be moved along are press process. AnalogReference start step-by-step USB-to-serial protection CAD code. People chip STK500 emphasize might lights OS. Regulator at overwriting works extending pull-up ideas. Comes supply Each requires chip Open-source flash. Sounds limited call timeout AC-to-DC switches mark. Enhancements step-by-step their off name! Hungarian facilitate. Wall-wart we’d permission Reference tool Additionally passed. Back Eagle preassembled support describe COM distributors. Principles Forum via powered boards page multimedia. Corresponding particular Vin conveniently layer addition overheat.

Wow! Have you ever read a computer generated novel about a microcontroller with such suspense, drama, and intrigue!?

And look! You can download it in a variety of formats:

Actually, it’s pretty terrible, unless you are a fan of random acts of writing. If you want some writing that makes sense, take a look at, where you can find information about novels written by real people.

If you’re more interested in microcontrollers (specifically the Arduino) maybe you want to read about a Trashcan Accelerometer, or Baker Tweet, or a steampunk bandwidth meter


Defending Perl

I stand here today not to condemn Perl, but to defend it… Perl

And when I say “Perl” I want you to feel free to substitute any other language you see fit… Visual Basic, Fortran, Lisp, COBOL, Smalltalk, or even… Java.

I was given a programming assignment this week. Given a list of 2000 names, I was to provide 400 names randomly. (Yes, this was for work, and was a real-world assignment, not just some exercise.) I proceeded to open my ~/scripts folder, which contains well over 1,000 Perl scripts, and grabbed some existing code, and wrote some new code, and ran a few tests, and quickly had the list of 400 names.

I used Perl because it worked for me. I probably could have written in it PHP (as it’s another language I am pretty comfortable with) but since I’m more familiar with Perl, and have done very similar thing before with Perl, and had a gigantic library (nearly 15 years worth) of Perl scripts to pull from… I used Perl.

I’m sure others could tell stories just like this substituting Java, or Python, or Erlang, or whatever they have around, that they are the most familiar with… and that’s fine.

This is about using the appropriate tool for the job, and this case, with the job being performed by me, the tool was Perl.

I wasn’t creating some new framework, or building upon an existing application, or pushing some code to GitHub that I wanted others to collaborate on… it was a quick ‘n dirty task that needed to get done as fast as possible.

Much of the programming world (maybe it’s mostly in the web-programming world) gets hung up on the latest and greatest. There’s a chance that using Ruby someone could have completed this task in half the time… but that person would not have been me, as I’ve spent probably less than an hour using Ruby and I’m not familiar enough with it to bang out the needed code quickly. I’d like to have some time to dig into Ruby (or, whatever, pick a language) and get familiar enough with it to use it effectively, but I don’t know when that will happen.

I’m not even a programmer… I’m a hacker, and I think Perl is a hacker’s language. Make something work. Solve a problem. Do it quickly, and move on.

To some degree you could say I’m trapped in Perl, because it is so easy for me to get what I want done quickly, and yeah, there’s a module for almost everything… Where I mainly feel the pain is when I look for example code and narrow my search to Perl (or PHP) because I’m most familiar with them. I needed some code this week to do some serial port communication, and found only one good example written in Perl. I should probably task myself with re-writing the code in Ruby, or Python, or some other language I’m not as comfortable with as an exercise in forced learning.

And then there’s a part of me that just says “screw it, I’m gonna work with what I know, and get things done, and move on.”


Pretty Print XML with Perl

Let’s say you’ve got a file named “file.xml” and want it pretty printed, all indented nice and everything…

For just such an occasion I have a Perl script named “” and I just run my XML file through it like so: cat file.xml | perl

Here’s the code I use:


use XML::Twig;
use XML::Parser;

my $xml = XML::Twig->new(pretty_print => 'indented');



You can even pass it through right as it comes in over the wire: curl | perl

Here’s an example of data from Foursquare without pretty printing. (I used curl to grab the data. Also, I added in some line breaks, just to make it a little more readable.):

<?xml version="1.0" encoding="UTF-8"?>
<created>Mon, 09 Aug 10 00:50:33 +0000</created>
<name>The Kiltie</name><primarycategory><id>79067</id>
<fullpathname>Food:Ice Cream</fullpathname><nodename>Ice Cream</nodename>
<display>Pete P. @ The Kiltie</display></checkin></checkins>

And here’s the same data, again using curl to grab it, and then passing it through the script:

<?xml version="1.0" encoding="UTF-8"?>
    <created>Mon, 09 Aug 10 00:50:33 +0000</created>
      <name>The Kiltie</name>
        <fullpathname>Food:Ice Cream</fullpathname>
        <nodename>Ice Cream</nodename>
    <display>Pete P. @ The Kiltie</display>

I still find Perl extremely useful for this sort of task… I’m sure there are other command line ways to do this, but this one works for me.

(Hat tip to A Curious Programmer where I picked up this Perl code from…)


Fitbit Improvements

I have an idea for how Fitbit can improve their web site… and, well, their product. I think it will make some of their customers very happy.


Here we see the current Fitbit web site. See the part where it says “Sync Fitbit with your PC”? I know you think that means “Sync Fitbit’s data with my PC” but it doesn’t… what it means is “Use your PC to sync Fitbit’s data with Fitbit’s servers” and that isn’t quite the same thing.


Here is my improvement, where you can see that they have added the ability to sync your own data with your own PC. This hasn’t happened yet, and may not happen.

I heard about the Fitbit back in June, and it sounded really cool. I then did some research and found out that it sends the data to the Fitbit servers, but doesn’t save it on your own computer… but don’t worry, they have an API coming out Real Soon Now. (See RSN.)

Sure, you can hack away at a Perl or Ruby version created by other people who are still waiting, but that’s not really a good solution.

From the Fitbit FAQ:

How do I get data from the Fitbit to the website?

The Fitbit is wireless and ships with its own base station. In order for the wireless functionality to work you will need to install a tiny piece of syncing software. This software will run on Mac OS X and Windows XP/Vista/7.

Do I have to use the website? Is there a way to dump data to my PC?

Yes, you must use the website. We do not provide any way to dump data to your PC, but the website will have an extensive XML and JSON API. You will be able to access most of your data through the API.

Now, that part that says “Yes, you must use the website.” worries me. It worries me because it makes me think these guys have You must use the website as part of the business plan. I know the Fitbit is a cheap device, so maybe they have something else planned to make money… Quickly, back to the FAQ!

Do I have to pay anything for the website?

No, the website is free. Once you buy the Fitbit Tracker, you will not have to pay anything additional in order to use the website.

Wow… OK, maybe not… I mean, the web site is free to use. It’s not like there is some Premium Membership… Oh wait, there is!

We’ve also launched a new premium membership with additional features to help analyze your activity, food and sleep to see results more quickly.

The Premium Membership is $49.99 per year. (Right now anyway…)

So how is that API coming? At least a few people have been waiting since late 2009.

I really do think the Fitbit is a neat device, and would consider getting one, but based on all the information I’ve gathered so far, I’m not convinced it’s a good idea based on the facts that:

  • I can’t get my own data directly from the device to my own computer
  • I can’t (easily) get my data from their servers to my own computer
  • It’s been at least 9 months and no API
  • They may have “upsell the user premium services” as part of their business model

I know the premium services cost money to develop and cost money to provide, and that’s fine… charge for it, but also keep in mind that having an API could open up the development of other applications and innovative new web services that could help you build some buzz, expand your brand, and ultimately sell more units.

And if there were a way to get the data directly on your own computer, you’d also open up the product for our friends who don’t use “Mac OS X or Windows XP/Vista/7” as well as other neat things. I know the new future is all about sharing, but maybe I don’t want my data sent out to the cloud, and right now, that’s not an option.

If you’re willing settle for the limitations of the Fitbit, and the nature of the device, then it definitely looks neat. If you’re concerned about how your data bypasses your own computer to go into the cloud where you may be able to access it (possibly for a fee) then, well… I’d think about it a bit more…

Update 2010-07-27: Here’s a nice post by someone who owns a Fibit.