Archive for January, 2006

Wisdom of the Documentation

Today, I spent some time staring at an old piece of code that I had written at least a year ago. It’s been in testing several times, but never put into production (the project it is tied to has been bumped on several occaisions). Today, it was back in testing.

The code is a failry simple web service, written in Perl. I like Perl. I have no illusions that I’m a fantastic Perl hacker, but I know the language well, though both experience and reading. I’ve read most of the O’Reilly Perl titles, including Programming Perl (“The Camel”), which I’ve read cover to cover at least three times. I still find myself looking things up, usually to refresh my memory about something I can remember reading, or some syntax detail I can’t get right (one of the perils of working in multiple languages). At least I generally know where to look.

So this web service has been tested before. It works in a browser, and it works when called by my test client. It’s been tested with a third-party bit of code. Today, it was tested by Dave, using some custom client code he had written in C#. And it worked… if he told his http library to ignore HTTP protocol errors. If he didn’t, his library complained.

And so I stared at the code for a while. By coincidence, I’d been reading the HTTP Spec over the weekend (yes, I’m a geek), and was pretty sure my response was good- a bare-minumum response, along the lines of:

HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8

Single Line Response

I double checked the spec anyway, and kept staring at the code. I was about to start grasping at straws and adding additional entity headers to the response (such as Content-Length), when I finally stared at the code long enough. I saw something like this:

print "HTTP/1.1 $status\n"
print "Content-Type: text/plain; charset=utf-8\n"

Then it hit me- "\n" in perl is a “magic newline”- it conforms to the newline convention on the system in question. HTTP, on the other hand, requires ASCII CR+LF (Cariage Return + Line Feed, or "\r\n" in C) as a line terminator. Apparently all of the code thrown at the service before today was a bit forgiving. I changed the strings to send CRLF using octal escape sequences ("\015\012"), and everything was fine. I was a bit ticked about the mistake… I new both the HTTP requirement for CRLF and the Perl treatment of "\n" when I originally wrote the code; it was a dumb mistake. Also aggravating that it took so long to spot.

And there my tale should end. But this evening, I started wondering if the octal sequence was the most Perlish way to send a CRLF. I knew that "\r" is fine for the CR, but you can’t use "\n" for the LF – it’s magic in perl, and behaves differently on different platforms. I began to wonder if Perl has a backslash-escape for LF that is always LF. Eventually, I had to check for myself, so I referred to the Quote and Quote-like Operators section of the perlop man page. (Sadly, I knew right where to look, right down to the name of the section. Geek, remember?)

Turns out the manpage specifically recommends the octal form for networking applications (at least I got that right), but then it twists the knife:

If you get in the habit of using "\n" for networking, you may be burned some day.

D’oh.

HOWTO (Build and) Install Carbon XEmacs on OS X

Update: added instructions for installing elisp packages after building.

There are as many Emacsen as there are grains of sand in the desert. For various reason (largely habit) I prefer XEmacs to Emacs, when given a choice- even when in text mode (xemacs -nw for the uninitiated; I usually alias this to emacs). And while I love a good command prompt as much as the next geek, I do own a Mac, and sometimes I want a more Mac-like experience.

Carbon XEmacs is a derivative of XEmacs, developed by Andrew Choi. Carbon XEmacs does not require X11, but instead uses the OS X Carbon libraries for its GUI display. Of the various OS X-specific Emacsen I have tried, it is my current favorite. At the time of this writing, the current version of Carbon XEmacs is Beta 4, and is available as a series of patches against the XEmacs source. This HOWTO describes how to build Carbon XEmacs Beta 4 for Mac OS X 10.4.4, and attempts to describe more generally how to build the latest Carbon XEmacs for any OS X 10.3+. Since many Mac users (myself included) are spoiled by the many binary packages and package managers (such as Fink and Darwin Ports) available for OS X, this HOWTO goes into some detail about how to download, patch, and build the source. If you already know this stuff, feel free to skim.

(If you’ve never done so before, you’ll need to install the XCode developer tools from your OS X install CD/DVD. If you’ve lost these, it’s available from Apple’s Developer site. It’s basically a click-and-forget installer package.)

Let’s do this

To begin, you will need to download the XEmacs source for the same XEmacs version that your Carbon XEmacs patches apply to. At the time of the writing, the latest Carbon XEmacs is Beta 4, which is supplied as a diff (set of patches) to xemacs-21.5.23. Visit the XEmacs.org download page to locate a suitable mirror, and download the source package for the correct version. As of this writing, all 21.5.x releases are considered Beta releases of XEmacs, so I chose the beta download page, and a local mirror therein.

When you arrive at the mirror, it will be a directory on an FTP server, full of files. look for a tarball- a file ending with .tar.gz- matching the xemacs version you need. In this case, I’ll be downloading xemacs-21.5.23.tar.gz. You will also see files with similar names ending in .patch.gz, .asc, and .md5. You will not need these (unless you need them- in which case you already know you need them. The rest of us will soldier on).

After downloading the file, open Terminal and change to the directory where the .tar.gz file was downloaded. I downloaded mine to my ~/ext directory:

cd ~/ext

If you don’t know where your downloads go, they probably go to your desktop; try cd ~/Desktop (capitalization counts). Now we’ll extract the source code:

tar xzf xemacs-21.5.23.tar.gz

Download the diff file from the Carbon XEmacs page to the same directory where you downloaded the xemacs source. Uncompress the diff file:

bunzip2 xemacs-21.5.23-carbon-b4.diff.bz2

And patch the original sources:

patch -p0 < xemacs-21.5.23-carbon-b4.diff

An aside: this is some pretty cool stuff if you’re not familiar with diffing and patching; the diff file is just a list of the changes between the original and Andrew Choi’s version, patch applies these changes to our original files, resulting in files that match Choi’s modified source. For the curious, -p0 (essentially) tells patch that it doesn’t have to adjust the paths; that’s why we made sure we put the patch in the same directory as the original zipped sources.

Now, time to make the donuts, er, software:

cd xemacs-21.5.23/carbon
sh build-app.sh

And now, the waiting. The hardest part, if we are to believe Tom Petty. This will take a while. On my 1.8 GHz iMac G5 (1.5GB RAM), it took around 7 minutes or so; it would probably take twice as long on my old G4 Powerbook.

When it’s done, you’ll have a shiny new XEmacs.app in the current directory (carbon). Unfortunately, your shiny new XEmacs.app doesn’t do a whole lot- none of the lisp packages that provide a significant portion of XEmacs’ features are included in the source code package. Instead, you’ll need to download them separately. The easiest way is to download the “xemacs-sumo” package, which contains all of the official packages in a single download. For multibyte character set support, you’ll also want the “xemacs-mule-sumo” package (mule is the emacs/xemacs multibyte subsystem).

From the XEmacs.org download page, find the link to download Official Packages, and select a mirror. You’ll end up in an FTP directory, as before. Download the following packages into the same directory as your other downloads:

xemacs-sumo.tar.gz
xemacs-mule-sumo.tar.gz

The packages can live a couple of different location, but I prefer to keep the packages directly inside the XEmacs.app application bundle. To unpack the tarballs to the right place run the following (remember to change the path if your downloads aren’t in ~/ext):

cd ~/ext/xemacs-21.5.23/carbon/XEmacs.app/Contents/Resources/lib/xemacs
tar xzf ~/ext/xemacs-sumo.tar.gz 
tar xzf ~/ext/xemacs-mule-sumo.tar.gz

Your XEmacs.app is now fully loaded. To move this to your Application directory, you can drag-n-drop in Finder, or just:

cd ~/ext/xemacs-21.5.23/carbon
mv XEmacs.app/ /Applications/

Just double click the teddybear icon to launch. If you want to see it run in a terminal window, use this (assuming you moved it to your Applications folder):

/Applications/XEmacs.app/Contents/MacOS/XEmacs -nw

As additional (Carbon) patches against the same base version of xemacs are released, you can download and apply them in the same manner, so keep the directory around. Remember to re-build the app (and copy it to Applications) after each patching. If a new patch-bundle is release against a newer XEmacs version, just dump the old source code directory and start over from the top.

Tech Support Soundbite

Actual diagnosis from help desk staff member, responding to my report of recurring system lockups:

“You’ve got bulging capacitors.”

Not so loud, pal. That’s how rumors get started.

Pocketful of Links

Just as afternoon shopping leads to a pocketful of change, a busy day’s webrowsing leads to many new shinys in my del.icio.us bookmarks. Here’s a handful I’ll toss on the dresser at the end of the day.

  • Rivinus Photography Gallery – Regular readers have seen Sean’s work before. He’s recently made the move to full-time photographer, which is fantastic. His gallery includes many samples of his fine art photography, including some fascinating macro work- M.C. Escher fans be sure to look for his piece “Stacked Nuts.”

  • The Annotated XML Spec – If you’re an XML geek (or just play one at work), here’s a chance to read over the shoulder with one of the fathers of XML, Tim Bray.

  • Al Gore: “Restoring the Rule of Law” – Text of a speech to the Liberty Coalition on Jan 16, 2006. I’ve never discussed politics on this site- mine or anyone else’s. This time I’ll make an exception. I consider myself a conservative. I never voted for Al Gore. I think this essay is spot on, and everyone should read this and actually think about it. [via douglas.nerad].

  • Life in Text Mode – Because GUIs are for sissies. [via 0xDECAFBAD]

  • Do-it-Yourself .Mac – If it was easy, everyone would do it.

  • The iRex Iliad – Not-yet-to-market eBook reader that uses the same eInk technology as the Sony LibriĆ©, but supports a number of non-proprietary document types. I’ll be watching to see how it’s priced; I’ve always wanted a device with that display.

iPhoto ‘06 Drive-by Review

Since I was at the mall anyway Staurday night getting new cell phones & service (from Cingular- but that’s another post), I stopped by the Apple Store to check the new Intel iMacs. Needing something to use to judge speed, I fired up iPhoto and proceeded to zoom and scroll about. Snappy. Snappy enough that I had to attribute at least part of the performance to iPhoto ‘06. My iPhoto ‘05 install, containing only around 3700 of the rated 25,000 picture capacity, had been so prone to beachballitis as to be nearly unusable. Although I was a bit leary that my year-old G5 wouldn’t perform as well as the cooler-than-thou CoreDuo chunk o’ geek-porn I tried at the store, I went ahead and dropped the 79.00 USD to pick up iLife ‘06.

In a nutshell: worth every cent- and that’s just based on 10 minutes of playing with iPhoto ‘06. So. Much. Faster. No really- it is. I can actually use iPhoto again without force-quitting it every 10 minutes. And the “Scroll Guide”, a see-through pop-up bezel that shows the Month/Year as you scroll, is a nice touch. Rotating photos in gallery mode is much faster as well- nearly instantaneous, even with a dozen pictures selected.

I’ll try to post a few words about the other iApps when I fire them up (except iWeb… don’t think I’ll need that).

Backing into Success

Last week, the clock/radio display in my car stopped working. I drive a 2001 Mitsubishi Eclipse Spyder, and the clock/radio display is separate from the radio, sitting at the top of the dash, above the center vents (which are in turn above the radio). I decided to try and fix it yesterday, and managed to succeed in spite of myself.

Although the display didn’t work, the stereo continued to work. I had hoped the issue was just a blown fuse. After opening the fuse panel, I realized I didn’t know which of the 15 or so fuses to check. Instead of pulling each one, I ran in the house to find my owner’s manual. Ten minutes of searching later, I returned to the car, manual in hand, only to remember that the fusebox diagram is on the back of the fusebox panel cover. If I’d flipped the panel cover over when I removed it, I would have saved 10 minutes. Oops.

Upon reviewing the diagram and attempting to decode the hieroglyphics that are used in place of English, I didn’t see a fuse for the clock. I did see an extra fuse not labeled in the diagram. Of course, that fuse wasn’t blown. I also checked the radio fuse (even though the radio worked), what looked like the dashboard fuse (although the dash lights worked), and some fuse with a transistor icon (engine computer, I’d guess). No blown fuses.

At this point my only other hope was for a loose wire between the stero unit and the display unit. Checking for this meant getting inside the dash. Never a fun proposition in any car, I was fairly hopeful since the center dash portion of the Eclipse is a separate piece. After removing two screws down near the gearshift, the console cover lifted up and out.

I was on a roll, until I realized that I still couldn’t get to the display unit, which had a special cover that extends up and into the main dash. After spending 5 minutes looking for a way to remove this cover, I found the back moved a bit if I pulled a certain way. Five minutes after that, I had moved from the driver’s seat to the passenger seat, and managed to get the back of the cover to just pop out. After some more experimentation, I finally figured out the whole thing just “clipped” into place. With enough force applied to pull on it, it eventually popped out.

I removed the display, only to find the single cable connector block was securely attached. I removed the stereo, and found all cables securely attached there as well. I eventually disassembled the entire display unit, and could find no issues. Sensing defeat, I started putting everything back together.

Fortunately, this proved easy. After returning the stereo and display to their places and checking all cabling, I popped the display cover back in just as it came off, and put the center console cover back in place. Still seated in the passenger seat, I put the two screws at the bottom of the panel back. That’s when I saw it.

The Eclipse’s central dash extends down into the center console, which runs between the two front seats. Just in front of the shifter and below the screw I was replacing, on the passenger side, sits the cigarette lighter, pointed upward. In my car, the socket is always empty, ready to accept a cell phone charger. Inside the socket, I could see a dime, which I couldn’t see from the driver’s seat. At that point, everything fell into place.

After removing the dime and completing re-assembly, I turned the ignition and confirmed the display was still not working. I then checked the fuse for the cigarette lighter, which was of course blown. One replacement fuse later, I turned the ignition and watched the clock display spring to life. Had I checked that fuse when I started, I would have saved the better part of an hour. Oops.

Happy New Year

Happy New Year! Two years ago, I tried making some resolutions. Last year, I even gauged my success for the previous year, but I never did get around to posting a new set of resolutions. I’ve never been a big fan of the New Year’s Resolution, but having that list a couple years ago did help me focus on getting some things done. In that spirit, I’ve decided to post a list of resolutions once again. Some of them aren’t traditional resolution fodder, but merely projects I’ve been planning for a while, to do “maybe after the new year, when things slow down.” Hopefully listing them here will encourage me to do them.

Personal
  1. Lose some weight and get in shape. I know this is everyone’s #1 resolution, but I need to focus on this. When I stopped smoking four or five years ago, I was out of shape, but within my ideal weight range. I gained alot of weight in the first year after quitting, and have lowly drifted up the scale in recent years. My goal is to lose 75 pounds by the end of the year… this will put me at the top of my ideal weight range. I know from experience that diets only work for a month or two. Instead, I intend to begin by using the gym at work at least 3 times per week, reducing junk food, and reducing portions at meals. If I don’t see some progress by the end of January, I can get more aggressive.

  2. Early to bed, early to rise. I’ve always been a night owl, and never a morning person. This often has a domino effect of a few days time, and I have more trouble getting up each morning. Fortunately my job allows me some flexibility in when I arrive, but I’d rather be leaving earlier. Also, while on vacation last summer, I somehow got into an altered cycle, getting up every morning around 7am (wicked early for me), and enjoyed being up before everyone.

  3. Write more music. I spent a litte time at the keyboard this past year, and came up with one piece I’m happy with. I’d like to find time to do more this year.

jclark.org
  1. New organization with tags. I’ve been feeling boxed in by my category hierarchy for a while, and tags (like del.icio.us) make much more sense. This will require some planning, since I don’t want to break any old URIs. I’ll use redirects if I have to, but a system that doesn’t need redirects would be even better. This includes story URIs, category URIs, and date archive URIs. I’m considering a switch to Wordpress like Douglas just did. This would also allow for drafts, something I’d really like to have.

  2. New Look and Feel. I’ve been working on this, very on-and-off, for months. I’ve about come to the conclusion I can’t do what I wanted to do, but I may do a scaled down version instead. I’ve got a picture Sean took for me that I’d really like to use.

  3. More Howtos. I’ve written a number of howto articles here over the past few years, and they tend to be among the most popular articles on the site, with lots of search engine visitors. I’ve found that I really enjoy writing them, so I intend to do more of them. I may even make a sub-site to house them.

  4. Post More. I did pretty well for the first half of ‘05, but fell down during the second half. This post is #294, just shy of the 300 post mark I had set as a goal for the end of ‘04. I’m going to target the 400 post mark by year’s end.

Projects
  1. Improve my email. I have a couple of different email addresses that I use; one for companies I spend money with, and one for everyone else. In addition, I’m subscribed to a bunch of mailing lists (which I need to reduce); all together, it’s a real pain to check my mail if I’m not at home on my primary Mac. I’d really like to setup to pop all of my mail into a self-hosted IMAP server. Alternatively, I might consider looking at gmail again, if I can make it work transparently with my jclark.org email address.

  2. Improve my home network. I’ve got a couple of PCs around the house in addition to the iMac and Powerbook, and I’ve never gotten Printer Sharing to work as seemlessly as it should. I’m also currently using my old Desktop PC as little more than a printer share, which is a waste. I want to free up the PC for possible use as a server (see later items), and get the printer shared to all of the machines that need it, seemlessly. I won’t outline the issues I’ve had with this in the past, except to say that I’ll be getting started by upgrading the iMac to Tiger (which I got for Christmas).

  3. Automate Photo Distribution. I’ve been using iPhoto on the iMac to manage pictures from our digital cameras, but this makes it difficult to print them (Due to the issues above, I can’t normally print from the iMac), and for Sherri to access them from her Windows Laptop. I normally have to explicitly export a number of photos to the old Desktop PC (going away, see above), and then she accesses them via a file share. She’d like to have copies of all the pictures on her Laptop, so she can show them when we travel. I’m going to figure out how to automatically publish all pictures in iPhoto’s library to other locations (primarilly her laptop, but possibly also to a file server as a backup). The laptop is often asleep, so it will have to sync when ever it’s awake, automagically. Also, I want to use the iPhoto albums to provide some kind of organization when exporting. Ideas for publishing/syncing include creating an Atom feed and designing a custom aggregator, and/or using rsync. I’m hoping iPhoto’s album data is stored in XML so I can get at it easily. Also, once I upgrade to Tiger, I may find some use from Automator.

  4. Backups & Storage. I need a backup solution badly. If the iMac died today, I’d probably lose some photos, and alot of other data. Same for the other PCs. I’d really like to setup a RAID storage array somewhere on the network, and make backups to it. I’m considering a NAS Raid solution from Infrant, but I’ve also got a couple PCs that could become servers. Big storage on the network could also be helpful for number 5….

  5. Consider dumping TiVo and building a MythTV setup. This one isn’t definate, but I’m certainly considering it. If I do, I’ll probably have 3 to 5 TV sets connected, so it could make for some fun HOWTOs.

  6. Household projects. There’s a number of these which I won’t belabor. The biggies are cleaning and renovating the basement, and renovating the family room.

  7. Secret Project. I can’t say now, it would spoil a surprise for someone. I’ll tell next year, if it gets completed.

So, there they are. In the past, this has been a Monthly Blogging Challenge. I don’t think anyone’s posted one for January yet, so I’ll follow tradition, and challenge everyone to post resolutions/goals for the new year. If you did this last year, be sure to review how you did as well. If you participate, please post a comment here with a link, send a trackback.