Skip to content

Instantly share code, notes, and snippets.

View davidwood's full-sized avatar

David Wood davidwood

View GitHub Profile
@davidwood
davidwood / gist:3767666
Created September 22, 2012 20:13
Hash password
var crypto = require('crypto'),
saltLength = 10,
algorithm = 'sha1';
function hash(password) {
var salt = crypto.randomBytes(10).toString('binary'),
hash = crypto.createHmac(algorithm, salt).update(password).digest();
return { hash: hash, salt: salt };
}
@davidwood
davidwood / gist:2579713
Created May 2, 2012 19:47
Upstart script for node app
description "My awesome application daemon"
start on filesystem or runlevel [2345]
stop on shutdown
respawn
respawn limit 5 60 # Limit respawns to 5 failures in 60 seconds
env NODE_ENV=production
exec /usr/local/bin/node /path/to/application/app.js >> /path/to/application/logs/node.log 2>&1
@davidwood
davidwood / app.js
Created April 30, 2012 14:46
Basic node 0.6.x cluster skeleton
var http = require('http');
var app = module.exports = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end();
});
@davidwood
davidwood / clone-rackspace-container.js
Created February 20, 2012 16:42 — forked from bromanko/clone-rackspace-container.js
Cloudfiles Copy Container
var cloudfiles = require('cloudfiles'),
request = require('request'); // Install request with `npm install request`
// CloudFiles client configuration
var configCloudFiles = {
auth: {
username: '',
apiKey: '',
host: 'auth.api.rackspacecloud.com'
}
@davidwood
davidwood / gist:1657675
Created January 22, 2012 17:00
Diaper wipe "solution"

Diaper wipe "solution"

We use this "solution" with cloth wipes instead of disposable diaper wipes.

Recipe

@davidwood
davidwood / FUCK-YA.md
Created December 9, 2011 19:59
List content type of files in Cloudfiles container

How to list the content type of all files in a Cloudfiles container.

  1. Install node and npm
  2. Install the awesome Cloudfiles package from Nodejitsu
  3. Create a folder and save the dw-is-my-hero.js to that folder
  4. Edit dw-is-my-hero.js and change USERNAME and API_KEY to your username and API key
  5. Run node dw-is-my-hero.js CONTAINER_NAME
  6. Smile (and tell people how rad node.js is)
@davidwood
davidwood / gist:1213888
Created September 13, 2011 14:13
Find an object in an array by id property
var myId = 10;
var index;
var item = _.detect(this._list, function(val, indx) {
if (val.id == myId) {
index = indx;
return true;
}
}, this);
@davidwood
davidwood / gist:989019
Created May 24, 2011 16:10
Single line access to array value
<?php
function returnArray() {
return array('item1', 'item2', 'item3');
}
function array_value(&$arr, $index) {
return $arr[$index];
}
@davidwood
davidwood / gist:954363
Created May 3, 2011 22:05
Serve current directory over HTTP using Python
python -m SimpleHTTPServer
By default, SimpleHTTPServer serves on port 8000. To specify a port, use (where 9090 is the port you want):
python -m SimpleHTTPServer 9090
And to run it in the background, use:
python -m SimpleHTTPServer &
function generateBackground($obj)
{
return $obj.css('background-color') + ' ' + $obj.css('background-image') + ' ' + $obj.css('background-repeat') + ' ' + $obj.css('background-attachment') + ' ' + $obj.css('background-position');
}