This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pattern for organizing DOM ready & non-DOM-ready dependent | |
// code within an initialization method. i guess this could be | |
// useful if initialization must take place inside the <head> tag, | |
// or you absolutely need to kick off some processes ASAP. | |
(function(){ | |
var app = app || {}; | |
function domReady( callback, context ){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
// Copyright 2011, Tim Branyen @tbranyen <[email protected]> | |
// Dual licensed under the MIT and GPL licenses. | |
// Script to detect cursewords in commit messages and provide the | |
// offending commit sha's. | |
var git = require('nodegit'); | |
var curses = ['fuck', 'shit', 'bitch', 'ass', ], | |
path = './.git', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// inspired by http://www.dustindiaz.com/async-method-queues/ | |
// (don't actually use this gist; there are better ways) | |
(function($) { | |
$.fetch = function(url) { | |
if (!(this instanceof $.fetch)) { | |
return new $.fetch(url); | |
} | |
var q = this.q = $({}), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////// | |
// IN CONSOLE // | |
//////////////// | |
Blah = Model("blah", { | |
persistence: Model.localStorage(), | |
find_by_uid: function(uid) { | |
return this.detect(function() { | |
return this.uid == uid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foo = (function f(){ | |
return f; | |
})(); // do this immediately | |
// then later: | |
foo(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// connect the widget obj to jQuery's API under the "foo" namespace | |
$.widget.bridge("foo", Widget); | |
// now you can do... | |
var instance = $("#elem").foo({ | |
baz: true | |
}); | |
/* | |
which just did three things: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// our "Widget" object constructor | |
var Widget = function( options, element ){ | |
this.options = options; | |
this.element = element; | |
this._init(); | |
}; | |
Widget.prototype = { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1: how could you rewrite the following to make it shorter? | |
if (foo) { | |
bar.doSomething(el); | |
} else { | |
bar.doSomethingElse(el); | |
} | |
bar[ foo ? 'doSomething' : 'doSomethingElse' ]( el ); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from the docs: | |
jQuery.isXMLDoc( document ) // false | |
jQuery.isXMLDoc( document.body ) // false | |
// where XMLObject equals our wu_tang root node | |
// from the previous examples: | |
jQuery.isXMLDoc( XMLObject ) // true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// normalize XMLSerializer object | |
if( !window.XMLSerializer ){ | |
window.XMLSerializer = function(){}; | |
window.XMLSerializer.prototype.serializeToString = function( XMLObject ){ | |
return XMLObject.xml || ''; | |
}; | |
} |