We're hiring!

We're actively seeking developers for our new Detroit location. Learn more

Platforms & Languages

Charting Data with jqPlot

jqPlot - Process Temperature

Some of the most interesting and challenging projects involve data visualization. It can be very difficult to express data in a clear way and also make the product aesthetically pleasing. There are many different ways of presenting data to users, and choosing the “correct” visualization is not always a simple decision. Having numerous tools at your disposal, or at least greater awareness of what is out there, can help you make a better decision.

I was recently experimenting with a library called jqPlot, jqPlot is a jQuery plugin that supports drawing line, bar and pie charts with many customizable features. The project I was working on involved a device that monitors the temperature of the contents of a kettle during the process of brewing beer. My goal was to show the temperature as it changes over time and also to indicate a prediction of when the temperature would reach a desired target value. Here is what I ended up with:


To produce the chart above, very little html code was required. Read more on Charting Data with jqPlot…

Also posted in Web Apps | Tagged , | Leave a comment

Writing Functional Python

Functional programming has a lot of advantages that have been enumerated over the years. Being a bit of a Pythonista, myself, I can’t help but introduce functional concepts into my Python code. Though Python is not a functional language, it doesn’t mean that your Python code can’t benefit from some of these concepts.

Perhaps one of my favorite illustrations of functional Python comes in the treatment of loops — or more accurately, their removal from my code. Before I demonstrate how to do that, allow me to introduce a very contrived example.

Let’s say you’ve parsed a configuration file into a list of lists, and you need to be able to access a particular settings by keyword. The following snippet does exactly that in a traditional format.

configurations = [["name","Bob"], ["email","bob@roberts.com"], ["template","dark"]]
def get_config_value(desired_key, configs):
    for key_value in configs:
        if key_value[0] == desired_key:
            return key_value[1]
print get_config_value("name", configurations)

This code works well, but I find the nested statements less than ideal.

Functional Alternative #1 – Generators

Generators simply create iterators (i.e., something you can use in a loop) without constructing a complete list ahead of time. Generators are lazy loaded and are more efficient than their eager-loading cousin, the list comprehension, when working with large data sets.

The following returns the same result as the previous example with one less layer of nesting: Read more on Writing Functional Python…

Also posted in Functional Programming | Tagged | 5 Comments

Graduating from CoffeeScript to LiveScript

CoffeeScript to the Haskell equals LiveScript

CoffeeScript is a nice syntactic alternative to JavaScript and, in the end, that’s all it is: syntax. CoffeeScript doesn’t offer anything not already found in JavaScript, no standard library nor any new operators. Looking for more in a compiles-to-JavaScript language, I stumbled across LiveScript.

Where CoffeeScript is a Ruby- and Python-inspired version of JavaScript, LiveScript is a Haskell-inspired version of CoffeeScript. Like CoffeeScript, LiveScript compiles to readable JavaScript about the same size as the original source file.

Here are a few reasons to explore LiveScript. Read more on Graduating from CoffeeScript to LiveScript…

Also posted in Web Apps | Tagged , | Leave a comment

combineLatest vs. zip in ReactiveCocoa

Recently, I’ve been learning the ins and outs of Functional Reactive Programming with Reactive Cocoa. The library comes with a number of operators that can be used to modify incoming signals. In this post, I am going to compare two of those operators: +combineLatest: and +zip:.

Both +combineLatest: and +zip: can be used to combine two (or more) signals into one new signal that sends a single RACTuple containing both values. This can be very useful when two separate events occur, or when two pieces of changing data need to be processed together.

Read more on combineLatest vs. zip in ReactiveCocoa…

Also posted in Objective C | Tagged , , | Leave a comment

Inexpensive Ethernet JTAG Adapter with Raspberry Pi and OpenOCD

I recently wanted an ethernet JTAG adapter for a project I was working on. Unfortunately ethernet JTAG adapters can cost upwards of $300, and even then they can be specific to particular chipset and toolchains.

However, were already using OpenOCD with ST-LINK/V2 programmers to communicate with out hardware, and it turns out that it’s very easy to set up OpenOCD on the Raspberry Pi. You can then plug the programmer into the Pi, connect a debugger (gdb in our case) to the OpenOCD instance, and debug your firmware remotely! Read more on Inexpensive Ethernet JTAG Adapter with Raspberry Pi and OpenOCD…

Also posted in Embedded Systems | Tagged , , , | 2 Comments

Simpler Deploys with git Subtrees

I recently set up a project with hosting on Heroku. However, I had code spread across several repositories that all needed to be deployed to the same place. This is a problem because the process to deploy to Heroku is essentially pushing to a git remote — if I did that across two repositories, they would collide.

One possible solution was git submodules, but they are finicky so I was hoping for something simpler. After a bit of investigation, I discovered that git has a feature called subtrees that could be used to handle this.

Read more on Simpler Deploys with git Subtrees…

Also posted in DevOps & System Admin. | Tagged , | Leave a comment

2 Ways to Use Single-Member structs in C

I love C’s structs. There’s a lot of weirdness in C but, for the most part, structs are predictable, useful, and easy to understand.

Structs, for those not familiar with C, are collections of data. An example of a struct is a point on a Cartesian plane:

struct point {
  int x;
  int y;

Normally, structs are used to associate two or more pieces of data. As the title suggests, I’m going to demonstrate why you might want to use a struct with a single element. Read more on 2 Ways to Use Single-Member structs in C…

Also posted in Embedded Systems | Tagged | 3 Comments

Using a Smartcard with a VirtualBox-based Vagrant Virtual Machine

Lately, I’ve been working on setting up a Personal Package Archive (PPA) to use when provisioning servers with custom packages.

In order to host packages on a Launchpad PPA, one must first upload signed source packages. Since I use a Mac and keep my PGP signing key on a Smartcard, I needed to find a way to connect my Smartcard reader to a virtual machine running Ubuntu. After a bit of research, I found an easy way to do this with Vagrant, VirtualBox, and the standard precise64 basebox.

Read more on Using a Smartcard with a VirtualBox-based Vagrant Virtual Machine…

Also posted in DevOps & System Admin. | Leave a comment

Getting Started with MQTT

mqttorgAs more and more things around us become networked, the communication protocols tying them together need careful rethinking. This network of devices, sometimes called the “Internet of Things” or “Machine-to-Machine” network (though it could also just be called “the Internet”), includes many embedded devices with very limited resources.

Protocols designed for typical ethernet networks, such as HTTP, are based around assumptions that no longer fit: they expect more bandwidth, processing power, and network reliability than may be available, and that networked devices will be on most of the time.

There is a more appropriate alternative, however: MQTT. It’s much lower in overhead, with only a 2-byte header for many messages. Its design suits devices that are suspended most of the time, with only occasional network activity. It also has support for reliable delivery built into the protocol, so simple sensors can just flag an outgoing message as requiring confirmed delivery and let the message broker take care of delivery reattempts. Using a standard messaging protocol for all communication also greatly reduces the surface area for possible security vulnerabilities. Read more on Getting Started with MQTT…

Also posted in Embedded Systems | Tagged | 1 Comment

“Subclassing” Ember Components

Recently, while working on an Ember.js app, I found that I wanted to create a reusable component that manages the editable state of content within it. That is, it would start out by displaying information (initializing its isEditing binding to false), and provide an “Edit” button that would set isEditing to true, so the content wrapped in the component could display its editing interface.

Naturally, I then wanted a way to “subclass” my EditableComponent so that I could create (for example) an AddressComponent that would display a mailing address read-only but allow you to edit it. What I struggled with was finding the best way to pull this off.

I had a few different ideas, two of which didn’t work. Read more on “Subclassing” Ember Components…

Also posted in Web Apps | Tagged | Leave a comment