Skip to content

Instantly share code, notes, and snippets.

View jed's full-sized avatar

Jed Schmidt jed

View GitHub Profile
@jed
jed / jquery.cacheOf.js
Created February 12, 2009 04:29
A lightweight jQuery memoizer for caching the results of expensive DOM operations.
// jQuery.fn.cacheOf - By Jed Schmidt (MIT Licensed)
// A lightweight jQuery memoizer for caching the results of expensive DOM operations.
// Example usage:
// Say you have a processing-intensive call
// that occurs often in your code.
$().find( "*:not(:contains(abc))" );
@jed
jed / node-tmpl.js
Created November 4, 2009 08:50
a template module for node.js
// tmpl-node.js: a template module for node.js
// Jed Schmidt - http://jedschmidt.com/
//
// inspired by John Resig's micro templates
// http://ejohn.org/blog/javascript-micro-templating/
var posix = require( "posix" ),
concat = Array.prototype.concat;
process.mixin( exports, {
@jed
jed / process.Promise.join.js
Created November 5, 2009 01:00
a class method for aggregating promises
process.Promise.prototype.combine = function() {
var args = Array.prototype.slice.call( arguments ),
count = args.length,
results = new Array( count ),
index = 0,
self = this;
if ( count == 1 && args[0] instanceof Array )
return arguments.callee.apply( self, args[0] );
@jed
jed / sha1.js
Created November 19, 2009 23:26
a sha1 adaptation for use with node.js
/* adapted by Jed Schmidt for use as a node.js module.
* the following node.js adapter code is MIT-licensed.
*
* Example usage:
*
* var sha1 = require("sha1.js"), hash;
*
* my_sha1 = sha1.hex( data );
* my_hmac_sha1 = sha1.hex( key, data );
*
@jed
jed / base64.js
Created November 19, 2009 23:26
a base64 adaptation for use with node.js
/* adapted by Jed Schmidt for use as a node.js module */
this.encode = base64encode;
this.decode = base64decode;
this.chars = function( string ) {
base64EncodeChars = string || "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
base64DecodeChars = [];
for ( var i = 128; i--; ) {
if ( base64DecodeChars[ i ] === undefined )
@jed
jed / 1.txt
Created December 5, 2009 21:17
gist-in-time can style
your github gists and make them
much less obtrusive.
@jed
jed / cloneFn.js
Created December 24, 2009 18:34
clones an existing function. scope not included.
function cloneFn( fn ) {
var
str = fn.toString(),
args = str.match( /\((.*)\)/ )[1].split(/\W+/),
body = str.match( /{((?:.|\n)+)}/ )[1];
return Function.apply( this, args.concat( body ) );
};
@jed
jed / Dispatcher.js
Created January 5, 2010 17:07
a function that dispatches to other functions based on signature
function Dispatcher() {
var signatures = [], functions = [];
function fn() {
var
args = arguments,
argNo,
arity = args.length,
captures = this.pathname.match(
new RegExp( "^(.*)(" + captures.join(")(.*)(") + ")(.*)$" )
).slice( 1 );
captures[ pos * 2 + 1 ] = val;
this.pathname = captures.join("");
#!/usr/bin/env node-bench
var list = [
"foo",
"bar",
"baz",
"quux",
"asdf",
"qwerty",