Press "Enter" to skip to content

Month: March 2006

Perl labels

I learned about Perl labels and thought I would pass it on. Basically a label names a block of code descriptively. They are usually uppercase. You can use next, redo and last within a labeled block. On the surface this doesn’t seem that useful until you start talking about loops within loops.

Take the following bit of code without labels:


while ( $somecondition ) {
    # do some work
    for my $iterator (1..10) {
        # do some more work
    }
}

Let’s say you want to use next in the for loop to control the while loop. There isn’t way to do that here. You would have to come up with some other logic to handle that. Using labels its very easy:


WHILE:while ( $somecondition ) {
    # do some work
    FOR:
        for my $iterator (1..10) {
        # do some more work
        next WHILE;
    }
}

Of course the above is a meaningless example but you get the idea.

Comments closed

X-Files and Art Bell

I just got the first disc of the first season of the X-Files today from Netflix. I used to love the show and it holds up pretty well. It’s strange to see Scully pouring over microfiche and not searching the Internet. Before this show came out I was a huge Art Bell fan and into all the conspiracy theories. I remember people calling into Art Bell talking about flying black triangles and then a few weeks later seeing it featured in an episode – exciting!

I finally grew out of all that around 1995 when I started my computer career. It’s funny how some people never grow out of it.

Comments closed

Python debugging and emacs

I am normally a vim user but am looking at emacs again. One of the features that emacs has that I love is how it does interactive debugging.

First thing to do is to have the python debugger in your path and called ‘pdb’. On my Ubuntu system that would be:

cd ~/bin
ln -s /usr/lib/python2.4/pdb.py pdb

Now edit your favorite python script with emacs and start the debugger:

M-x pdbpdb

Comments closed

Whatever happened to selling computer games?

I went down to Electronics Boutique, er EBX, er EB Games today looking for some computer games – you remember those right?Well I was shocked when I walked in and saw every single wall covered with console games. I remember back when at least two walls were devoted to PC games.

Near the back of the store on a four sided vertical shelf was the PC games. Terrible selection and only the newest games out right now.

What has happened? I wish I knew. I can only guess the console games have better profit margins.

There was a Best Buy across the street and decided to check it out against my gut feeling to run in terror (I had a really bad experience there last year and swore never to return). I cautiously approached the PC game section and it was filled with lots of games – new ones, old ones, classics, etc…

A sad day indeed with Best Buy has a better selection of PC games than EB Games. I now have no reason to ever go there again since I have a Game Crazy across the street from where I live.

Comments closed

Python == Perl when it comes to regex’s

A friend of mine is learning python and commented how he thought it was a better programming language but perl’s regex’s were better and so was better suited to scripting. I had to set him straight so I wrote a simple script in perl and python to parse telephone numbers.

Sample data:

  • (206) 329-1173
  • 206.329.1173
  • 206-329-1173
  • 206 329-1173
  • 329-1173
  • 3291173

Python:


#!/usr/bin/env python
import sys,re

phonenumber = re.compile("\(?(\d{0,3})\)?[\.\-\s]?(\d{3})[\.\-\s]?(\d{4})")
for line in sys.stdin:
    matches = re.match(phonenumber, line)
    areacode = matches.group(1)
    prefix = matches.group(2)
    extension = matches.group(3)
    if areacode == "":
        print "Prefix = " + prefix + " Extension = " + extension
    else:
        print "Area code = " + areacode + " Prefix = " + prefix  + " Extension = " + extension

Perl:


#!/usr/bin/env perl

use warnings;
use strict;

while (<>) {
    my ($areacode, $prefix, $extension) = ( $_ =~ /\(?(\d{0,3})\)?[\.\-\s]?(\d{3})[\.\-\s]?(\d{4})/ );
    if ($areacode eq "") {
        print "Prefix = $prefix Extension = $extension\n";
    } else {
        print "Area code = $areacode Prefix = $prefix Extension = $extension\n";
    }
}

Both scripts produce the same output:

    Area code = 206 Prefix = 329 Extension = 1173
    Area code = 206 Prefix = 329 Extension = 1173
    Area code = 206 Prefix = 329 Extension = 1173
    Area code = 206 Prefix = 329 Extension = 1173
    Prefix = 329 Extension = 1173
    Prefix = 329 Extension = 1173

Both scripts uses the exact same regex. Python is just as powerful as Perl for regular expressions.

Comments closed

Where are all the emacs books?

So I decided to give emacs another try. I say another because in 2004 I used it for about 3 months before deciding to go back to vim. So I went to Barnes & Noble at the University Village shopping center tonight and they didn’t have a single book! When I got home I went to Amazon.com (I work there by the way) and searched for ’emacs’. Three titles came up that were relatively new and in print. Three. The greatest editor ever and there are only three books? Eclipse hasn’t been out that long and there are entire bookshelves dedicated to it so what is the deal? I don’t know but it might be related to lisp. Lisp is supposedly the greatest programming language available but good luck finding more than one or two books on the topic and those will probably be academic texts.

Maybe the emperor doesn’t have any clothes on. Maybe I am reading all these blogs from Paul Graham and Steve Yegge and am convincing myself that the whole world is using emacs and lisp except me.I will am still going to give emacs another go but I won’t expect it to solve all my problems this time around and maybe I will enjoy it all the more.

Comments closed

New Python website is sexy

Well it looks like python.org has finally entered the realms of web 2.0. Nice colors, css templates, and new round jelly looking logo. Is this a reaction to Guido’s recent post regarding better marketing or had they planned this for quite some time? (my guess is its been in the works for a while).

Currently Python is my language of choice but after reading all of Steve Yegge’s old blog entries I am second guessing myself and thinking I shouldn’t drop Ruby totally.

Comments closed

Harry Potter and the Goblet of Fire

Well you might have noticed my book list on the right and see that I am reading the whole Harry Potter series back to back. I just recently finished Goblet of Fire and the movie came out today and was anxious to see it.

My first impression was that it was a Cliff notes version of the book. They cut so much out that it felt like the movie was on fast forward. I think it was better than the Prisoner of Azkaban though.

Lets see some of the things they left out (there are more but here are the highlights):

  • Riddle family murders
  • Bertha Jorkin
  • Potter at the Dursleys
  • Mr. Weasley “flooing” to pick up Potter and confronting Mr. Dursley
  • Winky the house elf
  • Percy Weasley (Weatherby)
  • Ludo Bagman
  • Fred and George’s bet
  • Team Mascots
  • Who won the Quidditch World Cup game
  • Ministry of Magic protecting World Cup
  • Potter, Weasley, Malfoy’s in box seats
  • Death Eaters attacking muggles
  • Weighing of the Wands
  • Potter resisting Imperio Curse
  • Bagman and the Goblins
  • S.P.E.W. and the House-Elf Liberation Front
  • Return of Dobby
  • Return of Sirius
  • The giant spider in the maze
  • Explanation of Priori Incantatem
  • Potter giving the Triwizard Cup winnings to Fred and George
  • Rita Skeeter being able to turn into a bug
Comments closed

David Gilmour is better than ever

It’s safe to say I am a big David Gilmour fan. I love Pink Floyd and whenever I would talk to someone else who liked them as well they were always surprised I didn’t like Roger Waters more. Perhaps this is too strong – I like him just fine but I don’t think he was the “heart” of Floyd as some fan boys and he himself thinks. I distinctly remember getting into a fight with someone over this a few years ago. We were discussing the relative merits of Gilmour and Waters when finally he said something to the affect “Well without Waters you wouldn’t have songs like Comfortably Numb!” when I told him Gilmour wrote the music for it he thought I was lying. What attracts me to Floyd and Gilmour is the music. The lyrics are nice too But don’t get me wrong, I am not bashing Waters. I loved Radio K.A.O.S and The Pros and Cons of Hitchhiking. But Gilmour’s On an Island and About Face are better!

Comments closed

Now I have a blog too!

Well this is the first entry of my new blog. I thought “Hey everyone else has one – why not me?”. Well not exactly. Actually another blog entry persuaded me to blog. Steve Yegge used to work at Amazon.com, where I work now. While I recognized the name I didn’t really know him. I didn’t even know he wrote a blog until I saw it linked off of reddit.com the other day. I was hooked. After spending most of Sunday night reading through his blog I came across his entry titled You Should Write Blogs and it convinced me to start one of my own.

So I did some googling and decided on WordPress. I had previously setup MediaWiki so I already had a mySQL installation. I had it up and running in about 20 minutes and was impressed – not only did it look good but is a cinch to administrate.I then had to convert my old site to WordPress. I still have a lot to learn but I got it up and running in about two hours, which included modifying the default template. My old site had a javascript calculator I wrote which doesn’t work correctly as a WordPress “page” so I will probably work on that next.

Speaking of modifying the default template, how do you like my header? I got it from a program called RapidWeaver which I bought and used for about a month before deciding that it wasn’t powerful enough. Thankfully since I own a license I don’t feel bad about ripping out one image and some CSS from one of their templates.

One other thing…I am eagerly waiting for midnight when David Gilmour’s new solo album, On an Island, is released on iTunes.

Well I guess this is enough for now…stay tuned!

Comments closed