PIXELFLOW :: an intergalactic discourse

Pixelflow

An Intergalactic Discourse

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

Vim Text Alignment

A lot of times, a little white-space can improve readability of a series of function calls, or a data structure, such as a hash.

If you are vimpire, check out tabular it can do things like:

and for your Cucumber steps you can turn

Into!

I won’t reinvent the wheel, so give this vimcasts.org screen cast a watch!

Chingu makes game programming fun.

Chingu is a library for ruby that wraps up common functions for displaying game sprites, playing music and sound, and handling input from the user. It’s based on Gosu.

It is seriously addicting. By exposing common game object features through ‘traits’, you can quickly get off the ground by mixing in modules into your game objects.

Just to get an idea of how simple it is, check out the examples folder or give my asteroids-like game a download nfgrebvqf

10 points if you can decipher the title =)

MagicRuby Roundup

You can catch some videos of the conference over at Viddler

The conference had a great turnout. Fellow ruby nerds came from Texas, and as far as Chicago! A welcome change of pace, since Acts_as_conference stopped 2 years ago.

Two of my favorite talks were:

Exceptional Ruby

Given by Avdi, Avdi Devblog and going over all the subtle nuances about exception bubbling, re-raising, exit codes, and threads.

Intro to Spatial Programming

Given by Pete, PeteOnRails Blog he shows several tools available for ruby to deal with geographic data, and map projections.

To Infinity and beyond!

To raise, or not to raise

When working with float values, it’s good to get familiar with how Ruby deals with them. When using division, what you can end up with is a Float, that is NaN or Infinity

Luckily you can use some helper functions to determine what kind of number it is!

As well as working with invalid numbers

Pay attention to the subtle differences between infinite? returning 1,-1, nil and finite? returning true/false.

Home, home on the range

Infinity is also quite useful for representing numbers without a bounds.

Great for that ‘Ultra Mega Robo Deathstar’ hosting plan you offer.