Skip to content

Instantly share code, notes, and snippets.

@keeganwatkins
keeganwatkins / test.coffee
Created May 19, 2015 15:43
Coffeescript semantics
window.localStorage is not null # window.localStorage === !null
window.localStorage isnt null # window.localStorage !== null
@keeganwatkins
keeganwatkins / class-def.js
Created October 4, 2013 16:44
Defining a constructor and it's prototype methods all in a single call.
// This is a fairly common pattern. First, define a constructor...
var Person = function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
};
// ...then define some methods by mixing into the prototype
$.extend(Person.prototype, {
sayHello: function() {
console.log('Hello, I\'m ' + this.getFullName());
@keeganwatkins
keeganwatkins / array-shuffle.js
Created November 17, 2010 21:15
Simple mechanism for randomizing the contents of an Array
var shuffle = function(source) {
var ret = Array.prototype.slice.call(source),
len = source.length,
i = len,
rand, temp;
while (i--) {
rand = parseInt( Math.random() * len, 10 );
temp = ret[ i ];
ret[ i ] = ret[ rand ];
// jQuery UI sugar: an easy way to limit a plugin generated by the widget
// factory down to the first element. This is useful for widgets like dialog
// and mediaplayer that should be instantiated/configured individually.
$.widget.singularize = function(widgetName) {
// Keep a reference to the auto-generated plugin, so that we can use it later
var widget = $.fn[ widgetName ],
slice = Array.prototype.slice;
// Abort is widget doesn't exist to avoid creating random properties on $.fn
if (!widget || !($.isFunction(widget))) {
@keeganwatkins
keeganwatkins / iDevice.js
Created September 9, 2010 15:49
Simple detection for iPod/iPad/iPhone
var isIDevice = navigator.platform.toLowerCase() in {
"ipod": true,
"ipad": true,
"iphone": true
};