Lost’s Buried Treasures

For seven years I ran the largest Stephen King site on the net. When I sold it
in 2005 I thought I put that world behind me for good. I had a final article printed in Lighthouse Magazine and moved on. But, like most things, it has a way of creeping back into my life.

I had the good fortune of taking a class from David Lavery at MTSU. Last summer he invited me to contribute two short essays for his new book about the ABC television show Lost and its connection with Stephen King. I wrote one piece about his first novel Carrie and another about The Dark Tower.

Lost’s Buried Treasures was published last month — available on Amazon — it’s a great read for anyone gearing up for the start of season four.

Publisher’s excerpt:

Lost’s Buried Treasures is the first in-depth guide to the hundreds of clues and mysteries embedded in the Lost world. Bestselling Lost experts Lynnette Porter and David Lavery provide an extensive guide to the clues and secrets of the show, detailing the connections between the secrets and anticipating what they will mean for the shows ultimate mystery.

Just in time for Season 4, Lost’s Buried Treasures brings you up to date on the people, places, music, and pop culture of Lost’s first three seasons. This book is the perfect guide for fans of the series–or anyone who wants to know more about Lost before Season 4 begins.

How To Install PEAR in Mac OS X Leopard

Unlike previous version of OS X, Leopard doesn’t come with PHP’s PEAR repository installed by default. Luckily, installing is quick and painless. From a command line:

curl http://pear.php.net/go-pear > go-pear.php
sudo php -q go-pear.php

Just press enter to select all the default choices except for the installation directory. For that, use /usr/local. (Thanks, Steve.)

Next we need to modify our php.ini file to include the new PEAR files:

sudo cp /etc/php.ini.default /etc/php.ini

Edit /etc/php.ini and change

;include_path = ".:/php/includes"

to read

include_path = ".:/usr/local/share/pear"

Restart Apache and you’re done!

Navigate Yahoo! Search Results Using Only Your Keyboard

Google has an experimental search page where you can test drive new search result layouts. My favorite is the Keyboard Shortcuts option. This lets you navigate and view search results
using only the keyboard – no mouse required! It’s a huge benefit for Quicksilver fans.

Now that Yahoo! is my default search engine, I desperately didn’t want to give up the keyboard shortcuts feature. Thanks to jQuery and Greasemonkey I don’t have to.

Make sure you’re using Firefox and have the Greasemonkey plugin loaded. Then,
click here to install.

I’ve chosen the same shortcut keys as Google. J and K move you up and down through the search results. Press return to view the selected link. You can even browse through multiple pages when you hit the end of the results. Pressing / will jump you to the search box if you’d like to run a new search. Hit escape to move back to the results.

You can view the source on Google Code.

Retain Your Employees With Your Ideals, Not Your Perks

Earlier today I was asked what I look for in a job. Specifically, what it would take to retain me past the typical “three year burnout” period tech workers often find themselves up against. The usual answers came to mind: a fun corporate environment, challenging assignments, working with people smarter than myself. Those are all important factors, but they’re also very vanilla. Who wouldn’t want to work in a fun workplace? Unless you have a serious ego, why wouldn’t you want to be around smart people?

The person I was talking to pressed on looking for a more concrete answer. I thought back to previous jobs and why I had left them. I know that burnout had been a significant factor in leaving one position. The job became stale – repetitive. I lost hope that things would ever change, and, more importantly, that I could even influence change. The result? I stopped caring. Is that a fault of management? Most definitely. Is it also a fault of my own personality and work ethic? Yep, that, too.

I’ve never quit a job out of malice. But I came close once. During a performance review with my immediate supervisor and the president of the company, I was asked what my “dream job” would be within the organization. I think everyone probably gets asked this at some point. It’s a standard interview question designed to uncover where you’ll fit in. Of course, the problem with this is that it only works if you answer honestly. And who is ever completely honest answering a question like this during an interview? But during a performance evaluation? This is a rare opportunity to get reassigned to a better project or tweak your job description. I’d be an idiot to pass it up.

In a rare moment of unrestrained what-the-fuck-it-cant-hurt-to-try I was totally honest. I said I’d scrap the entire corporate website and rebuild it using best practices – valid HTML and CSS, minimal use of Flash, and a heavy emphasis on making everything accessible. I explained that not only would this help our search engine rankings, but we’d be better people for ensuring that anyone willing to try would be able to access our website – whether it be through a cellphone, text browser, or screen reader.

There wasn’t much hesitation in the answer I got back. The COO said flatly “Who cares if our website is accessible? Blind people aren’t going to buy [our product name] anyway.”

I was a little shocked. Up until this point I had thought quite highly of him and the corporate ideals he and the other executives often spoke about. I had even gotten swept up in the company’s mantra (which I’ll refrain from repeating here) and genuinely believed we could have a positive impact on the world. But with that statement I realized that despite all the corporate good intentions, in the end he was just another MBA out to make a buck.

Like I said above, I didn’t leave out of malice. I left (in fact, two weeks later) out of disappointment.

So, what’s the point of this story? The point of this whole post? It’s that I don’t think there can be a real answer or set of answers to ensure employees stay with a company long term. No corporation can be everything to every employee. They shouldn’t even try. Instead, they should focus on fostering the ideals that they as a company hold dear. They should communicate those ideals strongly in the workplace. The result will be a natural sifting-out of employees who don’t match. The stronger those beliefs are held in the corporate culture, the faster the sifting, and the less time wasted on both sides. Employers don’t waste time and money trying to fit round employees into a square cubicle. And employees can quickly move on with their lives and to a job that fits who they are.

50 States Programming Puzzle

Anders Pearson posted an interesting programming puzzle today on Thraxil.org:

Take the names of two U.S. States, mix them all together, then rearrange the letters to form the names of two other U.S. States. What states are these?

He found out about it from Mark Nelson who, in turn, heard it on NPR. It’s not a terribly difficult riddle if you take a moment to think about it. But from a programmer’s perspective it smells like one of the many brain teasers we face in early Computer Science exams or job interviews. The puzzle isn’t so much about being the first person with the correct answer or even getting the right answer at all. These problems are designed to reveal how you approach them. They’re designed to show how you think.

That’s what intrigued me so much about Anders’ post. He used it as an opportunity to compare programming styles between low and high level languages (and, by extension, how low and high level programmers think). In this case, Nelson solved the problem in C++ using STL libraries. (Damn.) Anders wrote his solution in Python.

Both solutions are valid. Each arrives at the same answer. However the ease at which the solution is attained is radically different – not only in time spent writing the program but also in the readability of the code.

I see this dynamic every day in the code I write. My day job uses PHP, but at night I’m programming in Objective-C. I’m still a novice at ObjC and Cocoa (although I do have a strong C/C++ background), so perhaps inexperience is clouding my judgement, but there are so many times where I find myself longing for the flexibility of a high level, scripting language.

In any case, here’s my analogous solution to the 50 States problem using PHP. (For obvious reasons, my code is nearly line by line identical to Anders’ Python solution.)

<?PHP
    $states = array("alabama","alaska","arizona","arkansas","california","colorado",
        "connecticut","delaware","florida","georgia","hawaii","idaho",
        "illinois","indiana","iowa","kansas","kentucky","louisiana",
        "maine","maryland","massachusetts","michigan","minnesota",
        "mississippi","missouri","montana","nebraska","nevada",
        "newhampshire","newjersey","newmexico","newyork","northcarolina",
        "northdakota","ohio","oklahoma","oregon","pennsylvania","rhodeisland",
        "southcarolina","southdakota","tennessee","texas","utah","vermont",
        "virginia","washington","westvirginia","wisconsin","wyoming");

    $data = array();

    foreach($states as $state1)
    {
        foreach($states as $state2)
        {
            if($state1 == $state2) continue;

            $letters = array();
            $str     = $state1 . $state2;

            for($k = 0; $k &lt; strlen($str); $k++)
                $letters[] = $str[$k];

            sort($letters);
            $sorted = implode($letters);

            if(isset($data[$sorted]))
            {
                list($s1, $s2) = $data[$sorted];
                if($s1 != $state2 || $s2 != $state1)
                    exit("$s1, $s2 and $state1, $state2\n");
            }
            else
                $data[$sorted] = array($state1, $state2);
        }
    }

    echo "No pairs found\n";

How to Enable PHP5 In Mac OS X Leopard

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

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

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.

What is Twitter?

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.

foo9 URL Shortener

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:

function tenTo31($num)
{
    $out   = "";
    $alpha = "23456789abcdefghjkmnpqrstuvwxyz";

    while($num &gt; 30)
    {
        $r = $num % 31;
        $num = floor($num / 31) - 1;
        $out = $alpha[$r] . $out;
    }

    return $alpha[$num] . $out;
}