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 / node-require.js-diff_match_patch.js
Created May 25, 2011 17:22 — forked from tmpvar/node-require.js-diff_match_patch.js
use diff match patch in node and in the browser via require.js
/**
* Diff Match and Patch
*
* Copyright 2006 Google Inc.
* http://code.google.com/p/google-diff-match-patch/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@dshaw
dshaw / storify-unpublish.js
Created February 18, 2011 00:31
Unpublish your Storify story from the story view page.
$.post(location.href+'/unpublish/', function(response) { console.dir(response) });
@dshaw
dshaw / storify-unpublish.js
Created February 18, 2011 00:23
Unpublish a story from the console while logged in at Storify.com
$.post('http://storify.com/dshaw/packing-for-sf/unpublish/', function(response) { console.dir(response) });
@dshaw
dshaw / tweet_media_generic.html
Created November 4, 2010 21:21
tweet generic media attachment icon
<div class="stream-item-content tweet stream-tweet " data-tweet-id="292671788679169" data-item-id="292671788679169" data-screen-name="gruber" data-user-id="33423" data-classic-retweet-action="true" data-storify-permalink="http://twitter.com/gruber/status/292671788679169">
<div class="tweet-dogear "></div>
<div class="tweet-image">
<img height="48" width="48" src="http://a3.twimg.com/profile_images/546338003/gruber-sxsw-final_normal.png" alt="John Gruber" class="user-profile-link" data-user-id="33423">
</div>
<div class="tweet-content">
<div class="tweet-row">
<span class="tweet-user-name">
<a class="tweet-screen-name user-profile-link" data-user-id="33423" href="/#!/gruber" title="John Gruber">gruber</a>
@dshaw
dshaw / tweet-media_dailybooth.html
Created November 4, 2010 20:06
#newtwitter tweet-media embeds.
<div class="component">
<div class="tweet-media">
<div class="dailybooth">
<a class="inline-media-image" data-inline-type="DailyBooth" href="http://dailybooth.com/pamelafox/9884843" target="_blank"><img src="http://cdn2.dailybooth.com/5/pictures/large/cd75a8852f0d648d2de6a28e9317a2e3_9884843.jpg"></a>
</div>
<div class="media-attribution">
<span>via</span><img width="16px" height="16px" src="http://dailybooth.com/favicon.ico"><a target="_blank" data-media-type="DailyBooth" class="media-attribution-link" href="http://dailybooth.com">DailyBooth</a>
</div>
</div>
<hr class="component-spacer">
@dshaw
dshaw / min_jquery_version.js
Created October 29, 2010 03:42
Determine if a page has the minimum jQuery version you need to do what you're doing.
function minVersion(version) {
var $vrs = window.jQuery.fn.jquery.split('.'),
min = version.split('.');
for (var i=0, len=$vrs.length; i<len; i++) {
console.log($vrs[i], min[i]);
if (min[i] && $vrs[i] < min[i]) {
return false;
}
}
return true;
@dshaw
dshaw / dreadnode-gamecast.js
Created October 6, 2010 19:41
dreadnode game.gamecast()
// Optimize gamecast with ( http://github.com/LearnBoost/Socket.IO-node/blob/master/lib/socket.io/listener.js#L83-90 ):
Listener.prototype.broadcast = function(message, except){
for (var i = 0, k = Object.keys(this.clients), l = k.length; i < l; i++){
if (this.clients[k[i]] && (!except || [].concat(except).indexOf(this.clients[k[i]].sessionId) == -1)){
this.clients[k[i]].send(message);
}
}
return this;
};
function doHash(str, seed) {
var m = 0x5bd1e995;
var r = 24;
var h = seed ^ str.length;
var length = str.length;
var currentIndex = 0;
while (length >= 4) {
var k = UInt32(str, currentIndex);
@dshaw
dshaw / cl-snips
Created September 22, 2010 00:53
Command Line Snippets
# set temporary environment variable
export PORT=8888
# Expresso test with code coverage
expresso -I lib-cov test/*
// From jQuery source
// Calculate pageX/Y if missing and clientX/Y available
if ( event.pageX == null && event.clientX != null ) {
var doc = document.documentElement, body = document.body;
event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
}