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
@dshaw
dshaw / bury console.log
Created April 29, 2010 17:56
bury console.log from TWTR widget.js
// from http://twitter.com/javascripts/widgets/widget.js
if(!"console" in window){window.console={log:function(){}}}
@dshaw
dshaw / Array.prototype.forEach implementation in TWTR widget.js
Created April 29, 2010 19:28
Array.prototype.forEach implementation in TWTR widget.js
// from http://twitter.com/javascripts/widgets/widget.js
if(!Array.forEach){Array.prototype.forEach=function(D,E){var C=E||window;for(var B=0,A=this.length;B<A;++B){D.call(C,this[B],B,this)}};
@dshaw
dshaw / The .bind method from Prototype.js
Created May 1, 2010 05:04
The .bind method from Prototype.js
// From @jeresig
// http://ejohn.org/apps/learn/#2
// The .bind method from Prototype.js
Function.prototype.bind = function(){
var fn = this, args = Array.prototype.slice.call(arguments), object = args.shift();
return function(){
return fn.apply(object,
args.concat(Array.prototype.slice.call(arguments)));
};
};
@dshaw
dshaw / arguments.callee
Created May 1, 2010 05:41
Replacing named function reference with arguments.callee
// From @jeresig
// http://ejohn.org/apps/learn/#15
var ninja = {
yell: function(n){
return n > 0 ? arguments.callee(n-1) + "a" : "hiy";
}
};
assert( ninja.yell(4) == "hiyaaaa", "arguments.callee is the function itself." );
@dshaw
dshaw / uuid.js
Created May 7, 2010 17:05
uuid.js
// From: http://github.com/wuher/oauth2/blob/master/lib/oauth2.js
/*
* implementation copied from narwhal/lib/uuid.js
* this is because narwhal/engines/rhino/lib/uuid.js overrides this
*/
var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
var generate_verifier = function (length, radix) {
var chars = CHARS, uuid = [], rnd = Math.random;
length = length || 8;
var performance = (function () {
var my = {};
// Wrap a function body in this to return a copy that instruments itself
// If you want this to be useful, you should give your profiled function a name,
// otherwise it will be identified as "", which is less than useful.
my.profile = function (func) {
return function () {
var start = new Date().getTime(),
time,
@dshaw
dshaw / parseUri 1.2.2
Created May 17, 2010 20:34
parseUri 1.2.2
// FROM: http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
function parseUri (str) {
var o = parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
@dshaw
dshaw / Array.prototype.map.js
Created May 24, 2010 21:26
Array.prototype.map
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/map
if (!Array.prototype.map)
{
Array.prototype.map = function(fun /*, thisp*/)
{
var len = this.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
@dshaw
dshaw / Array.prototype.forEach.js
Created May 24, 2010 21:28
Array.prototype.forEach
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/forEach
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun /*, thisp*/)
{
var len = this.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
@dshaw
dshaw / gist:420563
Created June 1, 2010 04:32
Non-templated JS/JSON Code Sample
function render(tweet) {
var html = '<li><div class="tweet">';
html += '<div class="vcard"><a href="http://twitter.com/' + tweet.user.screen_name + '" class="url"><img style="height: 48px; width: 48px;" alt="' + tweet.user.name + '" class="photo fn" height="48" src="' + tweet.user.profile_image_url + '" width="48" /></a></div>';
html += '<div class="hentry"><strong><a href="http://twitter.com/';
html += tweet.user.screen_name + '" ';
html += 'title="' + tweet.user.name + '">' + tweet.user.screen_name + '</a></strong> ';
html += '<span class="entry-content">';
html += container[twitterlib].ify.clean(tweet.text);
html += '</span> <span class="meta entry-meta"><a href="http://twitter.com/' + tweet.user.screen_name;
html += '/status/' + tweet.id + '" class="entry-date" rel="bookmark"><span class="published" title="';