PIXELFLOW :: an intergalactic discourse

Pixelflow

An Intergalactic Discourse

Rails Security Updates

H4x

To avoid ‘l33t hax0rs’, and generally keep your app purdy like its nice to know when you’ve got a vulnerability.

It’s also super nice when fixes are back ported, so that you can apply fixes without bumping major/minor version numbers.

I had to do so with Rails 3.1.x and all the application specific gems.

Fix

Since all my apps are on github, I used gemnasium.com which shows all out of date, and at risk gems in your Gemfile, and which versions contain fixes so you can estimate how much time needs to be spent updating.

Joy

Go do it. It’s easy

The colors Duke, the colors!

I’m Basically Obsessed with Graphs

I’ve always enjoyed oggling charts and visualizations. With the maturing of Javascript, SVG, and Canvas in the browsers there are now some great libraries out there. Github just started using D3 for all of their graphs.

Perceived Color INTENSITY

Color schemes for graphs out of excel can be pretty bland, and there are ways to get aesthetically pleasing color sets with predefined palettes like Tango or COLOURlovers which is a huge repository of color schemes.

However these, or just using linear interpolation between two colors or a color and white don’t do your data justice.

The gist is, colorspace doesn’t match your eyeballs, and equidistance colors in HSL don’t have the same lightness intensity. As best explained in this post over at vis4.

The best color system for this was originally the Munsell color system but CIELAB is now much more widely used.

Show me the benefits of the science

You can jump right in to some color palettes (which are also GIS friendly) at Color Brewer

Shiny things

Here are some more graph libraries worth investigating:

And a bunch of random tools here

And this guy does beautiful things in flash

Also. What you really came looking for:

Ruby Module Descendants

I want to track who included me

Module has a built in callback for when it is included in a class. self.included(klass) is called on the module directly after a class declaration which includes it.

But what about sub-classes?

Ruby has ancestors but not a direct way to look at descendant classes. However you can use ObjectSpace to iterate over classes, and use the < comparison or include? to see if a class has your module as an ancestor.

Arduino Rotary Encoder

Noisy!

When using mechanical buttons to trigger events on a micro-controller there can be some voltage spikes that can re-trigger whatever logic you have for that button.

The same goes for rotary encoders, which in case of this one at sparkfun is two ‘buttons’ 90’ out of phase from one another, thus allowing you to detect clockwise or counter clockwise movement.

We can tune it out

There are a few ways to filter out unwanted mechanical noise. Using capacitors to react to the sudden spikes, or in software. In software you can check the values in your main loop, but that can be troublesome if your loop includes a lot of logic.

The other two approaches involve interrupts. You can use a timer to poll the pins at a regular interval, or you can attach an interrupt to the change of each pin.

Lets do it!

Arduino cooking timer has a great example of polling based matching. I really liked his code but wanted to try to code my own since this is a learning experience for me.

By looking at the value of both pins when one of them changes, you can predict the next valid value. By ignoring any other values, you do a good job of filtering out any noisy values that happen during one turn of the knob.

Check out the source over at my git hub

Here’s a video of it in action!

Reading Binary Files

Pack dat up!

If you find yourself dealing with explicit data from binary files in ruby, you may end up writing something like this.

pack and unpack work great, and have a wealth of ways to get at the data String#unpack rdoc. But after using nice DSLs like ActiveRecord and DataMapper, we can do better!

The BinData gem

BinData has patterns for cleanly describing how to access the data structures found in binary files. Data can be nested inside other types, including ones you define yourself.

I’m using it to read a Minecraft map file and manipulate shapes with ruby. Here are some of the highlights of what BinData can do!

Strings

Arrays

Choice

Go check it out over at Rubyforge