DoubleClick and Define using Apple Dictionary
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.
A strftime for Prototype
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.
Calling Ruby from JavaScript
Aaron Patterson shows us how to define ruby methods which can be called from JavaScript using RKelly.
Pimp My JavaScript Skillz
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.
Dealing with Asynchronous Queries in Adobe AIR
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.
Camino's Hidden JavaScript Debugger
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.
Extending Firebug
Extending Firebug—Nice article on extending Firebug.
JavaScript: Fun with the Left Shift Operator
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
PeepCode: Prototype Video Training
PeepCode Video: JavaScript With Prototype—In-depth video training for Prototype.
Avoiding Bloat in Widgets
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.
Ajax: Killing Usability One Request at a Time
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.
An In-depth Look At The Future of Javascript Debugging With Firebug
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.

