craig campbell

  • added December 8, 2010 at 10:50 pm
    updated January 24, 2011 at 9:14 pm


    I made the switch to Google Chrome for browsing not long after it was released for Mac for a number of reasons. Just to name a few:

    1. It is super fast
    2. New versions are released all the time
    3. They don't leave bugs sitting around for over 4 years without looking at them.

    For development, however, I continued to use Firefox. I found the inspector and console to be better in Firebug, and there was no FirePHP support in Chrome.

    After a while, I decided I had had enough of Firefox. If no one was going to make a Chrome extension to support FirePHP then I was going to do it myself. I wanted it to be extremely simple.

    I spent one rainy day in late August on it, and the rest was history.
    read more
  • added August 3, 2010 at 12:44 pm
    A while back I wrote about using TextMate to do code syntax highlighting for your blog. While I still consider that to be a perfectly valid method I realized it was pretty cumbersome after using it myself for a while.

    I began to search far and wide for alternatives and while there are plenty around most of them are pretty bad. I came upon this post by Dominic Szablewski and was inspired to begin creating my own syntax highlighting library.

    Where did the name Nijikodo come from?
    I decided I wanted to use some Japanese word so I translated "rainbow" which turned into "niji" and "code" which turned into "kodo". I'm sure it isn't a perfect translation.
    read more
  • added July 24, 2010 at 2:22 pm
    Most PHP developers are probably well aware of this already, but the release of PHP 5.3 brought a few cool features to the language including namespaces, late static binding, and anonymous functions (closures).

    In the interest of keeping this brief I just wanted to provide a few simple examples.

    Let's imagine you have an array of data:
    $users = array( array('id' => 1, 'name' => 'Tom', 'birthdate' => '1980-05-05'), array('id' => 2, 'name' => 'Julia', 'birthdate' => '1985-07-07'), array('id' => 3, 'name' => 'Michael', 'birthdate' => '1974-11-17') );
    Now let's say you wanted to grab all the user ids from this array. Normally you would do something like this:
    $ids = array(); foreach ($users as $user) { $ids[] = $user['id']; }
    With anonymous functions you could achieve the same thing by doing:
    $ids = array_map(function ($user) { return $user['id']; }, $users);
    read more
  • A while back I wrote about a way to keep data valid across multiple pages by invalidating cache keys. I have since thought of a better way to handle this.

    The basic idea is that anytime you have child objects related to a parent object you can use a property of the parent object to invalidate the children. To make this more clear let's revisit the original problem: You are building a blog with a lot of users where each user posts a bunch of articles. The articles are paginated and cached per page. If the user adds a new article, all the items on the page will shift and we need a way to invalidate all the pages in cache.

    The approach mentioned in my previous article involved having a namespace key that would store a random integer which would then be incremented when there is an update. This has a few problems:
    read more