Skip to content

Instantly share code, notes, and snippets.

// Helper method for Prototype to loop over a collection of elements
// and run a method on existing elements within the dom
Object.extend(Array.prototype, {
each_element_invoke: function(method) {
var args = $A(arguments).slice(1);
return this.map(function(element) {
return element && element[method].apply(element, args);
});
}
});
alias battery='ioreg -w0 -l | grep Capacity | cut -d " " -f 17-50'
alias svnaddall='svn status | grep "^\?" | awk "{print \$2}" | xargs svn add'
alias flushdns="dscacheutil -flushcache"
# environment variables
export PATH=/usr/local/bin:$PATH
export PATH="$HOME/bin:$PATH"
export PATH=/usr/local/git/bin:$PATH
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
export MANPATH=/usr/local/git/man:$MANPATH
export EDITOR="mate -w"
export SVN_EDITOR="mate -w"
# aliases
$(document).ajaxSend(function(event, request, settings) {
// pass authenticity token with requests
// requires global AUTH_TOKEN var to be set by Rails:
// <%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %>
settings.data = (settings.data ? settings.data + "&" : "") + "authenticity_token=" + encodeURIComponent( AUTH_TOKEN );
// make respond_to jump to the js block
if ( settings.dataType == 'html' ) request.setRequestHeader("Accept", "text/javascript");
});
Element.Methods.update_old = Element.Methods.update;
Element.Methods.update = function() {
Element.Methods.update_old.apply(this, arguments);
$.livequery.run();
};
Ajax.Responders.register({
onComplete: function() { $.livequery.run(); }
});
// requires nightly version of jQuery b/c it uses the add special event hook
// more about special event hooks: http://brandonaaron.net/blog/2009/06/4/jquery-edge-new-special-event-hooks
(function( $ ) {
$.event.special.hashchange = {
setup: function( data, namespaces ) {
if ( 'onhashchange' in window ) {
// sweet, native support... short-circuit
return false;
}
// onhashchange is not natively supported ... work around it :(
/*
* Sugar for type detection working across frames and browsers ;)
*
* Detected types
*
* 'arguments', 'array', 'boolean', 'date', 'document', 'element', 'error', 'fragment',
* 'function', 'nodelist', 'null', 'number', 'object', 'regexp', 'string', 'textnode',
* 'undefined', 'window'
*
* Copyright (c) 2009 Daniel Steigerwald (http://daniel.steigerwald.cz), Mit Style License
/*
* Sugar for type detection working across frames and browsers ;)
*
* Detected types
*
* 'arguments', 'array', 'boolean', 'date', 'document', 'element', 'error', 'fragment',
* 'function', 'nodelist', 'null', 'number', 'object', 'regexp', 'string', 'textnode',
* 'undefined', 'window'
*
* Copyright (c) 2009 Daniel Steigerwald (http://daniel.steigerwald.cz), Mit Style License