Tag: coding

Ruby’s case statement uses ===

I’ve not found this stated clearly enough elsewhere so I’m doing so myself.

Ruby’s case statement calls the === method on the argument to each of the when statements

So, this example:

case my_number
  when 6883
    :prime
end

Will execute 6883 === my_number

This is all fine and dandy, because the === method on a Fixnum instance does what you’d expect in this scenario.

However, the === method on the Fixnum class does something different. It’s an alias of is_a?

That is cute, because it allows you to do this:

case my_number
  when Fixnum
    "Easy to memorize"
  when Bignum
    "Hard to memorize"
  end

But it won’t work as you might expect in this scenario:

my_type = Fixnum
case my_type
  when Fixnum
    "Fixed number"
end

This won’t work because Fixnum === Fixnum returns false because the Fixnum class is not an instance of Fixnum.

My workaround for this is to convert it to a string first. Not sure if that’s the best solution, but it works for me(tm).

my_type = Fixnum
case my_type.to_s
  when "Fixnum"
    "Fixed number"
end

Leeds Ruby Thing #2, Thursday 6th March

The Leeds offshoot of the North West Ruby User Group is meeting again this Thursday, 6th March, 7:00 PM – 11:00 PM.  This time at Mr. Foley’s
Cask Ale House
, on The Headrow (formerly Dr. Okells).

Expect unstructured discussion of Ruby, Ruby on Rails and other random stuff plus nice people, great beer and coffee and geeky tshirts.

The balcony back room of Mr Foley’s has been booked.  Announce that you’re coming on the upcoming page.

Oh, and we now have a website: http://leedsrubything.org/

Leeds Ruby Thing, Victoria Hotel 7th Feb 2008.

Some of the people of the North West Ruby User Group (who usually meet in Manchester) have organised the first little Leeds get together.  No real name yet, so it’s the Leeds Ruby Thing for now.

No clear plan yet either, but expect unstructured discussion of Ruby and Ruby on Rails at least.

Thursday 7th February 2008 at 7pm in the Victoria Hotel pub. All welcome!

More details here: http://upcoming.yahoo.com/event/423116

Cute Little Image Gallery Script (CLIGS)

The Cute Little Image Gallery Script (CLIGS) is a PHP script that autogenerates a nice html index for a directory full of jpeg images. I wrote it to run my photography galleries and have released it to the world under the Gnu Public License (GPL). Download it and give it a bash (needs some setup and Apache trickery to get going).

Qmail, RedHat and Firestorm

I’ve built some packages of djbs software (qmail, daemontools, djbdns…) for RedHat ES.

I’ve also been working on Firestorm again, primarily on my mac/arp watcher preprocessor. It now saves state between restarts, and reports on more nefarious ethernet/arp. It’ll be included in the next release of Firestorm.

Subversion

I’ve upgraded to subversion for version tracking of source code instead of moudly old cvs. I had a little trouble keeping my old modification history but don’t really care. The only feature I’m missing is the Log keyword that I used to add to the bottom of my html pages as a comment. Otherwise I’ve been very impressed. I’m working on getting a viewcvs interface up for a remote copy of my repository soon.

gthumb diff and website changes

I’m back from my holiday in the Czech Republic.

I’ve rejigged my website a little to make it easier to see where things are on the front page.

I produced the web albums using Gthumb by Paolo Bacchilega. I need a little feature it seemed to lack (or a bug prevented it) so I wrote a patch to add it. This patch changed the behaviour of the Tools->Change Date tool. For each file that it changes the last modified date, it now also sets the comment date. You should be able to do this in Properties but a bug causes all images to be set with the first image’s date. I couldn’t see how to add this functionality there anyway. According to Paolo, this is now fixed in ver 2.1.3 so this patch is redundant.

horribly ported

My port of that pptpd exploit to Linux was apparently so horrendous that it prompted ‘r4nc0rwh0r3’ of ‘blightninjas’ to take the time to do it properly. In my defence, the original code really sucked, and I myself only needed the testing part to work (which seemed to work for me). It also compiled fine for me with gcc 3.2.3 (worksforme(tm)). And I in no way proclaim myself to be a good C programmer! Anyway, my laziness and lameness was thoroughly ridiculed by them here. Find their own fixed version here. At least I got my name on Bugtraq. Roll on fame and the big dollar.