DoubleClick and Define using Apple Dictionary

February 8th, 2008 . 0 comments

var selection;
if(window.getSelection)
  selection = window.getSelection();
else if(document.selection)
  selection = document.selection.createRange();

document.observe("dblclick", function() {
  if(navigator.userAgent.include("Macintosh")) {
      location.href = "dict://" + selection;
    }
});

A quick (and probably dirty) Prototype-based hack allowing Mac users to get the definition of any word by double clicking it.

Continue reading article…

A strftime for Prototype

February 8th, 2008 . 0 comments

Object.extend(Date.prototype, {
  strftime: function(format) {
    var day = this.getUTCDay(), month = this.getUTCMonth();
    var hours = this.getUTCHours(), minutes = this.getUTCMinutes();
    function pad(num) { return num.toPaddedString(2); };

    return format.gsub(/\%([aAbBcdDHiImMpSwyY])/, function(part) {
      switch(part[1]) {
        case 'a': return $w("Sun Mon Tue Wed Thu Fri Sat")[day]; break;
        case 'A': return $w("Sunday Monday Tuesday Wednesday Thursday Friday Saturday")[day]; break;
        case 'b': return $w("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")[month]; break;
        case 'B': return $w("January February March April May June July August September October November December")[month]; break;
        case 'c': return this.toString(); break;
        case 'd': return this.getUTCDate(); break;
        case 'D': return pad(this.getUTCDate()); break;
        case 'H': return pad(hours); break;
        case 'i': return (hours === 12 || hours === 0) ? 12 : (hours + 12) % 12; break;
        case 'I': return pad((hours === 12 || hours === 0) ? 12 : (hours + 12) % 12); break;
        case 'm': return pad(month + 1); break;
        case 'M': return pad(minutes); break;
        case 'p': return hours > 11 ? 'PM' : 'AM'; break;
        case 'S': return pad(this.getUTCSeconds()); break;
        case 'w': return day; break;
        case 'y': return pad(this.getUTCFullYear() % 100); break;
        case 'Y': return this.getUTCFullYear().toString(); break;
      }
    }.bind(this));
  }
});

UPDATE: Bugs fixed. Thanks Andrew and Stephen

Also, some of my old and new code has been posted on GitHub. You might find something useful.

Continue reading article…

Calling Ruby from JavaScript

January 8th, 2008 . 0 comments

Pimp My JavaScript Skillz

January 7th, 2008 . 0 comments

Dustin might not surprise you at your house with a book in hand, but he’ll damn sure send you his innermost fu in the form of a shiny yellow and black book. It’s an excellent read if you’re looking to put more funk in your functions and class in your classes. Check out “Pro JavaScript Design Patterns” by Dustin and Ross Harmes.

—I’m Justin Palmer and I approve this message.

Continue reading article…

Dealing with Asynchronous Queries in Adobe AIR

August 7th, 2007 . 10 comments

Nearly all the methods of Adobe’s SQLConnection class are asynchronous. While this is nice when your running expensive operations (your interface won’t hang up), it can be quiet tough to deal with considering we come from a land where database operations have always been synchronous.

Continue reading article…

Camino's Hidden JavaScript Debugger

July 12th, 2007 . 0 comments

A stray console.log can make Camino go boom. You can see what JavaScript errors are being thrown by opening up Console.app and viewing the logs.

Continue reading article…

Extending Firebug

May 22nd, 2007 . 0 comments

Extending Firebug—Nice article on extending Firebug.

Continue reading article…

JavaScript: Fun with the Left Shift Operator

May 1st, 2007 . 0 comments
  Number.prototype.toHex = function() {
    var hex = "0123456789ABCDEF";
    return hex.substr((this >> 4) & 0x0F, 1) + hex.substr(this & 0x0F,1);
  }
(255).toHex(); //ff

[255, 255, 255].invoke('toColorPart').join(''); //ffffff For the Prototype folk

Continue reading article…

PeepCode: Prototype Video Training

May 1st, 2007 . 0 comments

Avoiding Bloat in Widgets

December 4th, 2006 . 18 comments

Widgets walk a fine line between abstractions and implementations. Implementation, in this case, is a practical solution chosen to perform a given function. The problems with widgets occur when the widget author walks too far in one direction, or worse, walks an outward spiral covering both directions. Both choices lead to script bloat and complexity thats hard to manage. You no longer have a simple solution for a defined problem, you have a complex solution for a variety of problems. The good news is there are ways to avoid both the bloat and complexity.

Continue reading article…

Ajax: Killing Usability One Request at a Time

August 11th, 2006 . 14 comments

My oh my how we’ve wandered down the wrong path. No–it’s not the path where our users praise us for the immensely useful service we provide; Not the path where where we’ve done what’s best for our users; Not the path where we evaluate our choices based on context instead of technology. We have instead taken the proverbial “slip and slide” down the road where Ajax “live” anything is assumed to be better than well justified design decisions.

Continue reading article…

An In-depth Look At The Future of Javascript Debugging With Firebug

May 12th, 2006 . 25 comments

What if you could say goodbye to alert and not-so-useful logger scripts and have a real debugging API to debug Javascript. While it hasn’t made it to the public yet, the next version of Joe Hewitt’s Firebug will finally give us an easy to use, full-featured debugging environment for Javascript. Fortunately, I’ve had the pleasure of being able to test the new version of Firebug and this post will outline some of what you can expect.

Continue reading article…

Graceful Degradation with Prototype, Scriptaculous and Ruby on Rails - Part 2: The Tools Of The Trade

November 11th, 2005 . 22 comments

Graceful Degradation with Prototype, Scriptaculous and Ruby on Rails - Part 1: What's The Beef?

November 11th, 2005 . 4 comments