Skip to content

Instantly share code, notes, and snippets.

Avatar

Jed Schmidt jed

View GitHub Profile
@jed
jed / jquery.cacheOf.js
Created Feb 12, 2009
A lightweight jQuery memoizer for caching the results of expensive DOM operations.
View jquery.cacheOf.js
// 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 Nov 4, 2009
a template module for node.js
View node-tmpl.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 Nov 5, 2009
a class method for aggregating promises
View process.Promise.join.js
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 Nov 19, 2009
a sha1 adaptation for use with node.js
View sha1.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 Nov 19, 2009
a base64 adaptation for use with node.js
View base64.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 )
View 1.txt
gist-in-time can style
your github gists and make them
much less obtrusive.
@jed
jed / cloneFn.js
Created Dec 24, 2009
clones an existing function. scope not included.
View cloneFn.js
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 Jan 5, 2010
a function that dispatches to other functions based on signature
View Dispatcher.js
function Dispatcher() {
var signatures = [], functions = [];
function fn() {
var
args = arguments,
argNo,
arity = args.length,
View gist:276760
captures = this.pathname.match(
new RegExp( "^(.*)(" + captures.join(")(.*)(") + ")(.*)$" )
).slice( 1 );
captures[ pos * 2 + 1 ] = val;
this.pathname = captures.join("");
View foreach-bench.js
#!/usr/bin/env node-bench
var list = [
"foo",
"bar",
"baz",
"quux",
"asdf",
"qwerty",