Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / jquery.ba-isjquery.js
Created January 20, 2010 18:53
Determine if a reference is a jQuery object
// Moved to:
// http://github.com/cowboy/jquery-misc/blob/master/jquery.ba-isjquery.js
// http://github.com/cowboy/jquery-misc/blob/master/jquery.ba-isjquery.min.js
@cowboy
cowboy / git_stuff.sh
Created January 23, 2010 22:40
Some git-related bash stuff
## also see http://github.com/cowboy/bash-misc/blob/master/bash_prompt.sh
# ssh
ps aux | grep ssh-agent | grep -v grep > /dev/null 2>&1 || eval $(ssh-agent)
alias ssh_key='ssh-add -l | grep id_rsa > /dev/null 2>&1 || ssh-add'
# git
alias gst='git status'
alias gl='ssh_key && git pull'
(function ($) {
$.event.special.load = {
add: function( handler, data, namespaces ) {
if ( /^img$/i.test( this.tagName ) && ( this.complete || this.readyState === 4 ) ) {
// If element is IMG and has been cached by IE, trigger the event explicitly.
var event = jQuery.Event( 'load' );
event.data = data;
handler.call( this, event );
@cowboy
cowboy / throttle_debounce.js
Created February 2, 2010 13:47
Throttle + Debounce
/*!
* Throttle + Debounce - v0.2 - 2/5/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// Returns a function that will, when called repeatedly, execute `callback` no
@cowboy
cowboy / jquery.ba-viewportoffset.js
Created February 3, 2010 13:28
Calculate element offset from the top-left of the viewport.
// This has moved to:
// http://github.com/cowboy/jquery-misc/blob/master/jquery.ba-viewportoffset.js
// http://github.com/cowboy/jquery-misc/blob/master/jquery.ba-viewportoffset.min.js
// This has moved to:
// http://github.com/cowboy/jquery-misc/blob/master/jquery.ba-scrollbarwidth.js
// http://github.com/cowboy/jquery-misc/blob/master/jquery.ba-scrollbarwidth.min.js
@cowboy
cowboy / jquery.event.special.foo.add.js
Created February 8, 2010 19:52
1.4/1.4.1 and 1.4.2+ compatible event special .add method
// 1.4.2 (new plugins, use this)
$.event.special.foo = {
add: function( handleObj ) {
// Do something when event is bound here!
var old_handler = handleObj.handler;
handleObj.handler = function(event) {
// handleObj.type (string, 'foo' in this case)
// handleObj.data (anything)
@cowboy
cowboy / qunit-async-test.js
Created February 9, 2010 15:03
Run asynchronous qunit test serially
test( 'async tests', function() {
// My custom async function
function ajax(data, successCallback) {
$.ajax({
url: 'server.php',
data: data,
success: successCallback,
error: function( xhr, textStatus ){
ok( false, textStatus );
@cowboy
cowboy / gist:303386
Created February 13, 2010 11:12 — forked from padolsey/gist:303362
var a = 1;
(function(){
var a = 2;
(function(parent){
var global = this;
################################################################
name: jQuery plugin closure
tab trigger: jqp
scope selector: source.js
code:
(function(\$${2:,window}${3:,undefined}){
'$:nomunge'; // Used by YUI compressor.
${0:// OMG LETS MAKE A PLUGIN!!}