dive into mark

You are here: dive into markArchivesNovember 2001What I do for a living

Tuesday, November 13, 2001

What I do for a living

I sing “Happy Birthday” to my car every 1000 miles. This morning was 8000. I also have nicknames for my cars. This one is the Blue Baron. Years ago, my first car, which I actually inherited from my father when I went to college and he upgraded, was a red Nissan Sentra. He and I had nicknamed it the Red Baron, after the character in Snoopy’s fantasies. After college I sold it and got a biege Mazda, which I immediately nicknamed the Biege Baron, because it was alliterative and because “biege” is one of those funny colors. Then came the Green Baron, and now, finally, the Blue Baron. All of which leads me to the Zen story for today, courtesy of Zen Stories To Tell Your Neighbors:

When the spiritual teacher and his disciples began their evening meditation, the cat who lived in the monastery made such noise that it distracted them. So the teacher ordered that the cat be tied up during the evening practice.

Years later, when the teacher died, the cat continued to be tied up during the meditation session. And when the cat eventually died, another cat was brought to the monastery and tied up.

Centuries later, learned descendants of the spiritual teacher wrote scholarly treatises about the religious significance of tying up a cat for meditation practice.

The Register: Huge Windows XP sales save the world. Well-done article about how Microsoft’s lies, damn lies, and statistics about how well Windows XP is “selling”. In this context, “selling” almost certainly including retailers who are essentially forced by Microsoft to pre-order a certain large number of copies. This is similar to how the record companies work, pre-pushing large quantities of inventory of the latest “hot” album onto retailers and then turning around and claiming that the latest album is indeed “hot” because it sold X million copies in the first week. Of course, most of those copies are still sitting on shelves, waiting for us to come buy them because we think everyone else is. (There are obviously other factors as well; the general public is gullible, but not infinitely gullible.) Plus, they do this all the time, so if one album doesn’t work out, there’s always the next one, and the failed one will probably get lost in the noise. Microsoft only does this once every couple of years, so the stakes are much higher. Plus they probably can’t generate much word-of-mouth buzz. It’s only an operating system, it’s not really going to save the world.

CNET: Sites spotlight reports of copy-protected CDs. [via RRE] Or, if you prefer, “corrupt CDs”. Good to see this story break out of Slashdot and get some broader attention.

CNET: Thai Software Pirates Crack Windows XP. [via RRE] This is essentially the same story that The Register carried yesterday, without any sort of attribution. I wonder if The Register cares about stuff like that. For all I know, they sold the story to them, or licensed it to them, or something. How does stuff like that work? I guess this is probably how most people feel about copy-protected CDs, or software licensing agreements, or the DMCA. It doesn’t affect them directly, so they don’t care, and by the time it does affect them, it’s too late to do anything about it. (Meanwhile, I find that I care less and less about Windows XP, now that I’ve upgraded to Linux.)

Careful what you wish for. I am now mark@nudesleeper.com. Thanks to Michael Coté for setting it up.

Slashdot: Business @ the Speed of Stupid.

A while back I reported that Google was blocking Lynx from searching, giving a 403 Forbidden message. In fact, this is incorrect, or at least misleading. I stumbled across the same scenario again last night and found that their error message has been expanded:

Your client from the IP address ###.###.###.### does not have premission to get URL /search?q=XXXX from this server.

Please see Google’s Terms of Service posted at http://www.google.com/terms_of_service.html

If you believe that you have received this response in error, please send email to forbidden@google.com. In your email, please let us know the IP address from which you are querying (it is shown above). This will help us track down the problem.

So the problem is not that I was using Lynx, but that I was on my shell account on Sourceforge. I verified this by running Lynx directly from my laptop and searching Google, and it works just fine. So the new mystery is why Google blocks access to searching from Sourceforge. But I don’t care as much about solving this mystery; I was only connecting from Sourceforge because I lost track of which window I was in (or, more specifically, which virtual desktop I was on).

This morning I’ve been trying to parse US phone numbers, which the client insists on entering free-form. I need to parse them into area code, trunk, number, and optional extension. Searching Google finds all kinds of examples, all of which, for one reason or another, suck.

It is important to note that my purpose is parsing, not validation, so I want my expression to be as liberal as possible without making parsing mistakes. It’s in the end user’s best interests to enter their real phone number. This is not for some annoying survey or registration page; it’s an integral part of their business. But we all know that users can’t follow directions, so simply posting a note next to the field saying “be sure to enter ###-###-####” won’t be good enough.

After much wrangling, I finally settled on this:

import re
class InvalidPhoneNumber(Exception): pass
phonePattern = re.compile(r"""
    ^            # match beginning of string
    \D*          # swallow anything that isn't numeric
    1?           # swallow leading 1, if present
    \D*          # swallow anything that isn't numeric
    (\d{3})      # capture 3-digit area code
    \D*          # swallow anything that isn't numeric
    (\d{3})      # capture 3-digit trunk
    \D*          # swallow anything that isn't numeric
    (\d{4})      # capture 4-digit number
    \D*          # swallow anything that isn't numeric
    (\d*)        # capture extension, if present
    """, re.VERBOSE)
def parsePhone(phone):
    match = phonePattern.search(phone)
    if match:
        return match.groups()
    else:
        raise InvalidPhoneNumber, phone

This will correctly parse any of the following and return a tuple of four elements, in these cases either (’800′, ‘555′, ‘1212′, ”) or (’800′, ‘555′, ‘1212′, ‘1234′):

The client seems pleased by the liberalness of the formats, and I used the whole thing as the basis of an impromptu lesson on regular expressions for the in-house developers (none of whom had ever seen them). And all before lunch.

I love coding, and teaching, and writing. I should do it for a living. Hey, wait, I do do it for a living. That’s so cool.

Filed under , , , ,

Respond privately

I am no longer accepting public comments on this post, but you can use this form to contact me privately. (Your message will not be published.)



Recent Stuff For You, Special Price Stay Here
  • Greasemonkey Hacks
Good Stuff Buy The Cow Go Away
Dive Into Python
Powered by Google Drink The Milk Don't Steal

 

posts / comments
© 2001-8 Mark Pilgrim