Skip to content

Instantly share code, notes, and snippets.

// 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 ){
#!/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',
// 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 = $({}),
@ehynds
ehynds / blah.js
Created March 1, 2011 14:45 — forked from benpickles/blah.js
////////////////
// IN CONSOLE //
////////////////
Blah = Model("blah", {
persistence: Model.localStorage(),
find_by_uid: function(uid) {
return this.detect(function() {
return this.uid == uid
@ehynds
ehynds / gist:779771
Created January 14, 2011 15:51
calling a fn immediately and later
var foo = (function f(){
return f;
})(); // do this immediately
// then later:
foo();
// 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:
// our "Widget" object constructor
var Widget = function( options, element ){
this.options = options;
this.element = element;
this._init();
};
Widget.prototype = {
@ehynds
ehynds / screening.js
Created September 14, 2010 17:12 — forked from rmurphey/screening.js
// 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 );
// 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
// normalize XMLSerializer object
if( !window.XMLSerializer ){
window.XMLSerializer = function(){};
window.XMLSerializer.prototype.serializeToString = function( XMLObject ){
return XMLObject.xml || '';
};
}