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
###
# An implementation of the msgpack serialization format - http://msgpack.org/
# By Devon Govett
# MIT LICENCE
###
class MsgPack
idx = 0
@pack: (data, byteArray = false) ->
@dshaw
dshaw / rehash.js
Created July 27, 2011 20:52
Restore a flattened structure to a hash
// I use this to reconstitute the values returned by HGETALL ( http://redis.io/commands/hgetall ).
function rehash (values) {
var hash = {}
, isKey = true
, key;
if (!Array.isArray(values)) return hash;
values.forEach(function(value) {
if (isKey) {
key = value;
@dshaw
dshaw / array.goodies.js
Created July 21, 2011 21:09 — forked from rwaldron/array.extensions.md
Array goodies from twitter rap with David Herman, see wrap up here: http://twitter.com/#!/littlecalculist/status/89855977838485504
// http://twitter.com/#!/littlecalculist/status/89848378682392576
// http://twitter.com/#!/littlecalculist/status/89855977838485504
// Unary Array.from()
Array.from = function( arrayish ) {
return [].slice.call( arrayish );
};
@dshaw
dshaw / console.log.js
Created July 12, 2011 07:29 — forked from tmpvar/.gitignore
A console.log implementation that plays "nice" with large amounts of data. Keeps node alive until the output has flushed to screen.
/*
A console.log that won't leave you hanging when node exits
*/
console.log = function(d) {
var res = process.stdout.write(d + '\n');
// this is the first time stdout got backed up
if (!res && !process.stdout.pendingWrite) {
process.stdout.pendingWrite = true;
@dshaw
dshaw / gist:1072946
Created July 8, 2011 22:08 — forked from technoweenie/gist:1072829
.netrc file so you can push/pull to https git repos without entering your creds all the time
machine github.com
login technoweenie
password SECRET
machine api.github.com
login technoweenie
password SECRET
// we're all so 1337 by @gregarious
$('.avatar_laptop img').attr('src','https://s3.amazonaws.com/static.turntable.fm/roommanager_assets/props/laptop_linux.png');
@dshaw
dshaw / module.js
Created June 22, 2011 05:01 — forked from creationix/module.js
A super simple module system for browsers. Assumes all source files are concatenated and in browser.
function define(name, fn) {
if (!defs) { defs = {}; }
defs[name] = fn;
}
function require(name) {
console.log("Loading " + name);
if (modules && modules.hasOwnProperty(name)) return modules[name];
if (defs && defs.hasOwnProperty(name)) {
if (!modules) { modules = {}; }
var fn = defs[name];
@dshaw
dshaw / gist:1038645
Created June 21, 2011 19:22 — forked from bluewhalelabs/gist:1033554
Turntable Growler
// ==UserScript==
// @name Turntable Growler
// @namespace http://fluidapp.com
// @description Creates growl notifications for chat in turntable
// @include *
// @author Gregarious Narain
// ==/UserScript==
(function () {
if (window.fluid) {
@dshaw
dshaw / application.js
Created June 8, 2011 17:43 — forked from fabware/application.js
socket.io application and haproxy configuration
var express = require('express');
var redis = require('redis');
const serverType = process.argv[2];
const serverHost = process.argv[3];
const serverPort = parseInt(process.argv[4]);
const redisPort = 6379;
const redisHost = '127.0.0.1';
@dshaw
dshaw / node-and-npm-in-30-seconds.sh
Created May 26, 2011 03:50 — forked from isaacs/node-and-npm-in-30-seconds.sh
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh