Nov 04 2005

Ruby is just Sooo Cool!

admin @ 1:02 am

I’m doing some work in Ruby (yes, for a client :) ) and got to a point where I needed to process two arrays in parallel. I wanted something akin to do:with: in Smalltalk.

I couldn’t find it in PickAxe, or online.. though I did find someone asking for it. So, I rolled up my sleeves (not really reqired as I was wearing a T-shirt (see here for my favourite at the moment.. or go to www.rubystuff.com in general) and set out to do it brute force… make a range over the size of the arrays, iterate over that, index into each array and do something. Something like:

one = ['a', 'b', 'c']
other = ['x', 'y', 'z']
(0...one.size).each { | index | puts one[index] + other[index] }

Kind of ugly. It’d be nice if that was done in a nice do_with method:

one = ['a', 'b', 'c']
other = ['x', 'y', 'z']
one.do_with(other) { | a, b | puts a + b }

That would be much nicer. So I decided to explore a bit of Ruby’s inner workings… why not add do_with to Enumerable? After some research & experimentation the result is:

module Enumerable
  def do_with(other)
    (0...size).each { | index | yield(self[index], other[index]) }
  end
end

With that saved in do_with.rb, I just have to

require 'do_with'

Nice

Tags: 

Nov 03 2005

Low tech tools are sometimes the best

admin @ 1:52 pm

In response to yesterday’s NY Times column by Davd Pogue where he says:

“Thou shalt not entomb thy product in indestructible plastic. Sure, we understand the temptation: you want your packaging to be sturdy yet see-through, so shoppers can see exactly what they’re buying. Trouble is, you’re caring only about whether people take your product home; you apparently don’t care about what happens after that. You don’t seem to mind that getting those hard plastic packages open is a dangerous ritual involving scissors, steak knives, band saws and, eventually, blow torches.”

I run into this problem all the time. I live in an area bereft of big box electronic superstores, but I spend a good chunk of time working in places that have such amenities (within a short walk of my hotel in Detroit area are both a BestBuy and a compUSA). So, when I’m onsite I generally go technology shopping. As I said, I run into the plastic entombment issue that Mr. Pogue talks about in his column regularly. Add to that the fact that I fly there, internationally at that. For those who don’t fly much, that means that I have no weapons of mass plastic destruction at my disposal.. nary a nail file with which to dis-entomb my latest crumpet of technological excess.

I have however come up with a viable solution that is universally (at least in my experience) applicable. The lowly hotel pen. Most packaging has a spot where the pen (cap removed) can be jammed through the packaging, making a nice sized hole. Near an edge is best. Often you can, using the hole and leveraging off nearby protrusions or sides of the packaging, you can generally rip through the plastic with relative ease. Alternatively you can make a series of holes with the pen, allowing you to eventually rip the packaging open enough to extract whatever happen to be inside.

Sadly, the pen must typically be sacrificed. But it’s a small price to pay.

As a side note, I have to give Apple the nod for their packaging. Not only is it easy to get into, but it’s often as well and as imaginatively designed as what’s inside.

Tags: No Tags

Nov 03 2005

Dog food

admin @ 1:30 am

So.. what kind of dog likes to eat Wasabi coated peas?

Well, ours apparently.

He was tentative at first.. but now actively solicits them.

His tastes evidently do not extend to Punjabi Mix. All the more for me :)

Tags: 

Nov 02 2005

New Site

admin @ 6:36 pm

My new site is live. It’s still rough in places, but there’s enough in place to consider it release 1.

Tags: No Tags