Archive for September, 2006

Hex encoded ASCII to String in Ruby

My current project required a simple operation to perform that took me some time to find in ruby. I’ll put a copy here so hopefully it’s of use to someone:
[source:ruby]str.scan(/../).each { | tuple | puts tuple.hex.chr }[/source]
So this will convert Hexidecimal tuples into ASCII literals, like follows:
[source:ruby]str=”48656C6C6F”
str.scan(/../).each { | tuple | puts tuple.hex.chr }
H
e
l
l
o
=> ["48", "65", "6C", "6C", "6F"][/source]
As I say, I couldn’t find this anywhere else, so enjoy.

When a programmer says “Whoops”

So I’ve been learning Ruby very rapidly for a new project, and well, it’s all about watching programmers say ‘Whoops’.

Normally, it’s tappy tappy, GRR, ARG, !”£$”£%”!^”U*%^*!£%$”£$^”$*, crash bang, whoosh, SMASH and some dead hardware.

Ruby is more like ‘Whoops’, fixed, ‘Whoops’, fixed, ‘Whoops’, ‘Finished’.

Glorious.