Archive for October 2007

VirtualHostX Leopard Compatibility

Wednesday, October 31 2007 - 0 comments

Update 11/1/07: VirtualHostX is now compatible with Mac OS X 10.5 Leopard. You can ignore the rest of this post :-)

I've received many emails asking for a Leopard compatible version of VirtualHostX. I'm happy to say it's almost ready and will be a free upgrade for all users.

I've decided to go ahead and post a beta version for anyone interested to download. I've completed my testing and everything appears to be working well. The only bug is that after adding or removing a virtual host, the program doesn't automatically restart the web server (so your changes aren't getting picked up). Until I get this feature working, it's easy to restart the server yourself. Just go to System Preferences → Sharing and then uncheck and check "Web Sharing". Here's a screen shot

Thanks for your patience, everyone.

Technical Notes

For those who are wondering, the reason the current version of VHX doesn't work on Leopard is because Apple upgraded the default Apache installation from version 1.3 to 2. This is a great change - it definitely makes my job as a web developer easier. VHX just needs to be taught where the Apache 2 config files are stored and which changes to make.

Another Beer

Sunday, October 28 2007 - 0 comments

Gruber on Boston's World Series sweep over the Rockies:

I need another beer.

So did the Red Sox. During the post game celebration at Coors Field, Fox cut to the Boston locker room where a tub full of Bud Light cans was clearly shown.

How to Enable PHP5 In Mac OS X Leopard

Friday, October 26 2007 - 11 comments

I've seen a lot of visitors searching for information on enabling PHP5 in Mac OS X Leopard. It turns out to be quite easy. Leopard ships with Apache 2 and PHP 5 pre-installed. To enable PHP simply:

  • Open your favorite text editor and edit /private/etc/apache2/httpd.conf
  • Uncomment line number 114. It should read

    LoadModule php5_module libexec/apache2/libphp5.so

  • Open System Preferences and go to Sharing

  • Stop and then restart Web Sharing

That's it!

PS - If you want any easy way to setup and manage virtual hosts on your Mac, check out VirtualHostX.

My Favorite New Leopard Feature

Thursday, October 25 2007 - 0 comments

Select a file in Finder and press ↩ to rename it. Finder now excludes the file extension from the initial text selection. This leaves you free to type a new name without overwriting over the extension.

Leopard First Impressions

Thursday, October 25 2007 - 0 comments

  • If you squint your eyes and look to the side of your monitor, Leopard is actually quite attractive.
    • VirtualHostX is broken at the moment. That'll be fixed as soon as I roll out Apache 2 support.
    • The new iCal is hot. I love that there is now a physical separation between local and subscribed calendars.
    • I just noticed all pop-up menus have rounded corners - feels very Web 2.0 inspired.
    • My PHP5/MySQL install got borked. Solution:
    • sudo mkdir /var/mysql
    • sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
    • Enable PHP5 /private/etc/apache2/httpd.conf (line 114)
    • Add your vhosts to /private/etc/apache2/extra/httpd-vhosts.conf
    • Why does the Finder sidebar use the traditional special folder icons when the actual folder icons are the ugly-cant-tell-them-apart-ones? (Can't wait for Candybar to start working.)
    • When you look at the translucent menu bar by itself, it's sort of nice. But if there's a window pushed up against it the transparency really stands out and looks strange. It's not a good contrast.
    • I just used iChat's new screen sharing function to help a co-worker from across the room. Normally I have to get up and walk over there. Not any more!
    • What the crap?? Command-tabbing doesn't rotate back around when you reach the end of the application list. Wait. False alarm. It does - just not when you use the arrow keys to move through the list.

I'll be posting more initial thoughts throughout the day.

What is Twitter?

Wednesday, October 24 2007 - 0 comments

Nat from O'Reilly Radar:

It reminded me of the time in my mis-spent youth when I got lost in IRC, spending evenings heckling the TV with my IRC friends. This is the geek equivalent of being stoner, by the way, with roughly the same effect on cognition . . . It's a very loosely-coupled conversation.

Spot on.

An interesting (but probably useless) hack would be to take an opensource IRC client and wrap it around Twitter's API.

Brace Yourself

Monday, October 8 2007 - 0 comments

Despite using The Framework at work, we still have conflicting coding styles within the office. I fall squarely into the "braces are bad" camp. If an if statement doesn't require braces to work, then it shouldn't have them. For example

To me, that's good lookin' code. Why add clutter where it's not needed? The argument I hear most often against this comes from Scott - "because it saves time if you have to go back and add another line." Fine. Maybe it will save you a little typing later. And maybe it will even catch an error or two down the road.

That logic has never sat right with me, yet I could never articulate why exactly. Today I found an old blog post by Wil Shipley that says what I've felt in my heart all along. Wil writes

I don't like extra braces around one-line if statements. I know, that way you can add extra lines any time you want and you don't have to think blah blah blah. But we're trying to make our code more READABLE. That's the key. You can spend 10 seconds adding braces if you end up writing another line. It's like you're slicing bread before every meal just in case you decide to make a sandwich, and then 90% of the time you just throw the bread away.

Bam! Take that all you brace enablers! That's sandwich logic.

foo9 URL Shortener

Wednesday, October 3 2007 - 4 comments

I was out of town for a couple days last week and had a lot of time to kill at my hotel. Needing something to do I decided to write my own URL shortening service. This is hardly an original idea - TinyURL.com has been around for a long time. Newcomer url(x) is great, too. However, there are changes I'd like to see made to both sites so I decided to roll my own. Plus, it turned out to be a fun computer science-y puzzle (more on that later). I've called my shortening service foo9.net.

First off, I wanted the site to load fast. That meant no ads and no extra HTML cruft - only the necessary basics. It's supposed to be a service - not a billboard. The homepage for foo9.net is as lightweight as possible. Especially when compared to TinyURL's.

I also wanted to eliminate as many "clicks" as possible for the user. With url(x), you have to move the mouse and click on the URL field to select it. foo9 automatically selects the URL field for you. Just load the page and hit paste. Plus, once the URL has been shortened, the new link is already highlighted and ready to copy. We also provide a clickable link if you want to test it. You can even password protect your new URL so only trusted friends can access it.

After shortening your link, foo9 gives you a "secret" URL that will let you track how many visitors your link has had. I was considering tracking referral data and maybe even unique IP addresses, but decided against it for privacy reasons. If enough people ask for it I might implement these stats.

foo9 even has a simple developer API so you can shorten links from within your own applications - no need to visit our site.

And Now The Computer Science-y Part

URL shortening is neat problem to think about because the goal is to make the new URL as short as possible. The immediate solution is to simply hash the URLs. The problem with this is most hashing algorithms give you a long string of characters - usually 35 or more - which is how they can (in theory) guarantee there won't be any collisions. If you hash a URL and then trim the new value to a small number of characters the hash loses all practical value.

The solution is to use an ID that increments with each new URL. We could simply assign an ID field to each URL and have the database auto-increment it. That's a good start, but the shortened URLs quickly grow in length. TinyURL claims 47 million URLs. That would mean eight character long IDs. While probably shorter than the original URL, we can do better.

The reason the ID's grow so quickly is because they're counting in base 10. If we increase the symbols in our number system we can keep the URL short longer. An easy choice would be to use hexadecimal - base 16 - which counts 0 through 9 and the continues with A through F. That's good, but once again, we can do much better.

foo9 uses a base 31 system. It's a strange choice, but here's why.

To maximize the number of numbers (and still keep things simple) I chose to use 0 - 9 and then A - Z for a total of 36 possible choices. With that many combinations the URL will stay relatively short for a long time.

So if base 36 works so well, why drop down to base 31? Usability, of course.

The full 36 character list has some hard to read symbols: O, 0, 1, I, and L. When they're butted up against one another in a URL it's hard to distinguish between each. URLs are normally sent around via copy/paste and clicking. But in the rare occurrence that you need to speak a URL to someone or transcribe it by hand, you'll be glad the letters don't look alike. So, 36 characters - take away the 5 look alikes - and you're left with 31:

2 3 4 5 6 7 8 9 A B C D E F G H J K M N P Q R S T U V W X Y Z

It's a fast solution and keeps the URL short. Here's the base-10 to 31 function: