i make beer, music, and code. sometimes in that order. @aberant on twitter

Ruby has a functional swing in it's step

I’ve recently started reading the “Programming Clojure” book by Stuart Halloway.  The book is an engaging read even if you are like me and have a tiny amount of prior lisp experience.  While learning the functional elements of Clojure, it helped me appreciate how easy it is to use Ruby in a functional style.  Here are just two of many different ways to have a functional programming style with Ruby.

Chopping a list into a head and tail is an operation that’s performed in most FP examples.  There are a couple straight forward examples of doing this with Ruby like below.

list = [1,2,3,4,5,6]
head, tail = [list.shift, list]

While this may work, it is not exactly understandable.  What does shift do again?  We could take up an extra line to define tail and remove the need to make the new array to just fill in head and tail, but it really doesn’t solve the over all lack of clarity. To clear this up we need to use our friendly splat operator in a slightly different way then it’s normally used.  It is typically used to convert parameter arguments into an array to allow methods to accept variable number of parameters.

list = [1,2,3,4,5,6]
head, *tail = list

Here the splat operator is used to take in the rest of the list after head gets the first element from the list.

Another trick I learned from Tyler Jennings is using an underscore in Ruby similar but not identical to it’s use in Scala.  In Ruby, an underscore is a valid character for variables.  Here I am using it to indicate that I don’t care about the rest of the list.

list = [1,2,3,4,5,6]
head, _ = list
Comments

impress your friends with spittle!

making web sprites by hand is now just plain silly.  with spittle you can now auto-generate sprites and css, leaving you plenty of time to shave other yaks.  check out the readme to get started!

Comments

update on multi-touch table

thought i would update everyone on the progress so far.  i finally got the IR assemblies done.   I realized i needed a small fan to cool them down because they can get quite hot (the resistors are rated 1w).  i also decided to remove the computer power plugs i was using and replace them with radio shack polarized plugs. they are cheep, easy to use, and haven’t fallen apart yet like those computer plugs did.  i plug these into an  old 300W computer power supply i had in the basement. these lights also have a small plastic hinge between them and the backing.  this allows me to easily change their up/down angle to prevent them from reflecting on the acrylic top.

IR assemblies

the IR lights attach to the bottom of the table with velcro.  this allows me to adjust the angle of the lights underneath.  it’s the simplest thing that could work, and it works wonderfully.

velcro under table

this is a macro shot of the top of the camera.  because the top of the fish eye lens is rounded, i can’t cheat and put the IR filter directly on top of the lens.  i built the filter support with tiny bits of balsa wood and held it together with some hot glue.  i also put some gaffer tape around the exposed sides to keep outside light to a minimum.

here is a shot of the IR lights from above the table

the fiducials show up wonderfully in reactivision.

Comments

a letter from _why

because of his disappearance, i thought i would share a letter i had received from _why in 2005.  i had just started learning ruby after a year or so break from development and emailed him because i was trying to figure out the path to enlightenment. i’ve learned from this email to put less importance on what is right and instead try to learn from everything, including times when i’m completely wrong.

I’ve shortened the email slightly to keep focus.

I do not write tests for my code.  I do not write very many comments.  I change styles very frequently.  And, most of all, I shun the predominant styles of coding because that would go against the very essence of experimentation.  In short: all I do is muck around.

So my way of measuring a great programmer is different from some prevailing thought on the subject.  I would like to hear what Matz would say about this.  You should ask him, seriously.

I admire programmers who take risks.  They aren’t afraid to write dangerous or “crappy” code.  If you worry too much about being clean and tidy, you can’t push the boundaries.  (I don’t think!)  I also admire programmers who refuse to stick with one idea about the “way the world is.”  These programmers ignore protocol and procedure.  I really like Autrijus Tang because he embraces all languages and all procedures.  There is no wrong way in his world.

Anyway, you say you want to become better.  I mean that’s really all you need.  You feel driven, so stick with it.  I would also start writing short scripts to share with people on the web.  Little Ruby scripts or Rails programs or MouseHole scripts to show off.  Twenty lines here and there and soon people will be beating you up and you’ll be scrambling to build on to those scripts and figure our your style and newer innovations and so on.

Until an asteroid,

_why
Comments

why i test

it has been coming up in conversation frequently, so i’d like to give my perspective on why i believe testing is important. putting aside for the moment the importance of testing first and good vs bad tests, i’ll keep the focus on the mere existence of tests in your project.

one of the most advantageous benefits of testing is that it’s the collection of everything you and your team have learned about the domain. running your tests exercises your app for compliance with every single feature and against every single bug you’ve had. for me, this combined intelligence of the team ran against the code base is the primary advantage of including tests.

Comments

refactoring help from custom initializers

came across an interesting problem today in refactoring ruby’s osc library.  i was in the middle the network message parsing section and needed additional functionality from the Message object that would require changing the initializer. since i didn’t want to break all the old code, i added a custom initializer for the new code.  this will allowed me to refactor in small steps, keeping all the old code, and let me easily pull the plug on the old initializer when i’ve completely refactored all the sections that create messages.

Comments
Comments
Comments

a clearing house of ideas in this song… i’ll see what sticks

[Flash 9 is required to listen to audio.]
Comments

first look at my multi-touch table

i’ve finally got some pics together of the prototype i’m building for a reactable type multi touch table.  Since this is a diffused rear illumination style table, i needed some source of IR light.  This one is a partially finished IR light that will have up to 40 IR leds.  The power comes from an old 300w computer power supply i had around. 

ir light

I realized that the particular leds i got needed to be trimmed on the side so they would be able to sit flat against the board together.

Here’s the table frame i built.  I left the frame pretty sparse because i tried to make few assumptions about what i needed.  It couldn’t hurt to be a little more stable, but until i figure out how everything will fit, it’s just fine.  the camera is on a cardboard box hidden partially by the frame.

Comments