Monthly Archives: August 2010

Node Knockout – Team LazerCatz!

August 30, 2010 » Geek

This weekend I participated in Node Knockout with Jerod and Cody. It was awesome, we made a game in 48 hours (less than that of actual working time).


It was a lot of work, how much?

We had 129 total commits, 82 were mine, 35 belonged to Jerod, and 12 to Cody. That’s not 100% accurate because Cody had some git problems part way through, so I committed things for him. In those commits we had 245 file changes.

The final product had 974 total lines of code, as broken down by CLOC:

Language   files   blank   comment   code    scale   3rd gen. equiv
Javascript     4     130        43    750 x   1.48 =        1110.00
CSS            1      26         4    167 x   1.00 =         167.00
HTML           1       0         0     57 x   1.90 =         108.30
SUM:           6     156        47    974 x   1.42 =        1385.30

If you have a minute, give it a shot at

Fixing Kate’s Instance Behavior

August 27, 2010 » Geek

I’ve been a KDE user for a long time now, and I love all the new changes (except the Aero snap thing, you can turn that off though). One thing I love is Kate. I usually have two or three Kate sessions open at once, borrowing code across projects or changing things in different modules.

My problem is that Kate now defaults to only one instance, so if I call Kate from the command line with a file name, it gets added to a running instance, not a new one. If I use the KRunner to start a session, it loads in place of the current session in a running instance. I understand the reasoning here, but I want to use it the way I always have.

Easy fix! Just always make sure it is called with kate -n

You can do this with a BASH alias,

alias kate='/usr/bin/kate -n'

or more thoroughly with a wrapper script like this one from a forum post:

/usr/bin/kate -n [email protected] &> /dev/null &

Easy fix!

Tags: , , ,

Thursday Quote: Jeff Atwood

August 26, 2010 » Geek

“As programmers go, I’m fairly social. Which still means I’m a borderline sociopath by normal standards.”

– Jeff Atwood
On Working Remotely

PanoramAh: Version Two

August 25, 2010 » Geek

Last week I put together a quick script to display a panorama I took in Colorado.

It was a one-off script and I didn’t think much of it until Naina Redhu left a comment asking about using it for multiple panorama’s.

Well, why not?

It didn’t take much to tweak it into a full fledged jQuery plugin. I just took the bit that made the panorama and tweaked it to use local references. While I was at it I removed the requirement for a pre-loader image in the markup. Have a look.

  function ( $ ) {
    $.fn.panoramah = function () {
      return this.each(
        function ( index ) {
          // Localize the element
          var photo = $( this );
          // Extract the relevant data from the rel attribute
          var panorama_width = photo.attr( 'rel' ).split( ':' )[0];
          var panorama_url = photo.attr( 'rel' ).split( ':' )[1];
          // Get the preloader
          var img = $( "" );
          // Setup the onload callback
            function () {
              // Set the background to the image
              photo.css( 'background', "transparent url( '" + panorama_url + "' ) no-repeat" );
              // Clear out the loading crap
              photo.html( "" );
              // Set up the mouse monitoring
                function ( event ) {
                  // Get the offset
                  offset = Math.floor( ( panorama_width - photo.width() ) * ( ( event.pageX - photo.offset().left ) / photo.width() ) )
                  // Mind the overflows
                  if( offset <= panorama_width - photo.width() ) { photo.css( 'background-position',  '-' + offset + 'px 50%' ); }
          // Start the loading process
          img.attr( 'src', panorama_url );

Using it is pretty easy too, just set up your HTML like so:


Then make a collection and call panoramah() on it:

$( '.panorama' ).panoramah();

There's a demo available here and you can keep up with any changes at Github.

A Simple JavaScript Hooks System

August 19, 2010 » Geek

I was looking to add some more extensibility to a project this week and I couldn’t find a hook system for JavaScript. I wanted something similar to the PHP hook system in MediaWiki, but Google just wasn’t much help.

I’m sure there is something out there that does what I need, but it’s such a simple thing I went ahead and implemented it.


var Hook = {
  hooks: [],

  register: function ( name, callback ) {
    if( 'undefined' == typeof( Hook.hooks[name] ) )
      Hook.hooks[name] = []
    Hook.hooks[name].push( callback )

  call: function ( name, arguments ) {
    if( 'undefined' != typeof( Hook.hooks[name] ) )
      for( i = 0; i < Hook.hooks[name].length; ++i )
        if( true != Hook.hooks[name][i]( arguments ) ) { break; }

Extensions can "get in line" for a hook by calling register with the hook name and callback.

  function ( args ) {
    alert( 'Bye!' );
    return true;

Core code (or even other extensions actually) can call hooks by using the call method, with name and an argument array (think argv). If a hook returns anything other than true, processing of the hook ceases. 'quit', [ 'All Done' ] );

To do useful things you have to set up the right arguments. Since objects are passed by reference in JavaScript, you can manipulate anything in the argument array from inside of your hook (or even add to the array if you want).

Obviously this is a simplified tool. All code is implicitly trusted, argument specification is non-existent, there is no prioritization (except for insertion order) and hooks are not guaranteed to run. But it works!

You can check out some basic usage code and test it out here.

Suggestions are welcome!