Skip to content

Instantly share code, notes, and snippets.

View dshaw's full-sized avatar
🦄
Always bet on Node.js ✨

Dan Shaw dshaw

🦄
Always bet on Node.js ✨
View GitHub Profile
/*
* TableSorter 2.0 Parsers
* Version 1.0.0
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
/**
@dshaw
dshaw / history.js
Created March 25, 2010 15:44
JavaScript History implementation in Harmony by Dima Romakhin
// JavaScript History implementation by Dima Romakhin
// http://romakhin.ru/harmony/draw/src/history.js
var history_max_len = 30;
function History( o )
{
this.init( o );
}
setInterval((function () {
console.log(new Date()); // run some arbitrary code
return arguments.callee; // here be the magic
})(), 1000);
// ^---- and that runs the function, and the return val is assign to the interval
@dshaw
dshaw / Array.prototype.forEach()
Created April 11, 2010 17:14
Array.prototype.forEach implementation from @Rem
// from @rem's dashboard.js: http://rem.im/chirp/dashboard.js
if (![].forEach) {
Array.prototype.forEach = function(fn) {
var len = this.length || 0,
i = 0;
context = arguments[1];
if (typeof fn == 'function') {
for (; i < len; i++) {
fn.call(context, this[i], i, this);
// From @codepo8
// http://www.smashingmagazine.com/2010/04/20/seven-javascript-things-i-wish-i-knew-much-earlier-in-my-career/
// Take the list of class attributes on an element and add new class.
function addclass(elm,newclass){
var classes = elm.className.split(' ');
classes.push(newclass);
elm.className = classes.join(' ');
}
var scrollTop = Math.max(doc.documentElement.scrollTop, doc.body.scrollTop);
@dshaw
dshaw / JavaScript implementation of isDate()
Created April 23, 2010 19:04
JavaScript isDate() implementation
function isDate(str) {
return (Object.prototype.toString.call(new Date(str)) === "[object Date]");
}
@dshaw
dshaw / Array.prototype.remove(elem)
Created April 23, 2010 19:07
Array.prototype.remove( element )
// Check to make sure indexOf is implemented (!!IE6).
if (!Array.indexOf) {
Array.prototype.indexOf = function(elem) {
var i=0,
length=this.length;
for (; i < length; i++) {
if (this[i] === elem ) {
return i;
}
}
@dshaw
dshaw / gist:378192
Created April 25, 2010 05:56 — forked from paulirish/gist:315916
(function(window,document,undefined){ ... })(this,this.document);
// everyone's new favorite closure pattern:
(function(window,document,undefined){ ... })(this,this.document);
// when minified:
(function(w,d,u){ ... })(this,this.document);
// which means all uses of window/document/undefined inside the closure
// will be single-lettered, so big gains in minification.
// it also will speed up scope chain traversal a tiny tiny little bit.
@dshaw
dshaw / jQuery-like each implementation
Created April 29, 2010 17:11
jQuery-like each implementation
var each = [].forEach || function (fn) {
var len = this.length || 0, that = arguments[1];
if (typeof fn == 'function') {
for (var i = 0; i < len; i++) {
fn.call(that, this[i], i, this);
}
}
};