Skip to content

Instantly share code, notes, and snippets.

@chesles
chesles / rmdir.js
Created September 18, 2012 19:38
Recursively removing a directory in node.js
var fs = require('fs')
, path = require('path')
function rmdir(dir, callback) {
fs.readdir(dir, function rmfiles(err, files) {
if (err && err.code == 'ENOTDIR') {
return fs.unlink(dir, callback);
}
else if (err) {
return callback(err);
@chesles
chesles / index.js
Created October 25, 2012 03:05 — forked from max-mapper/index.js
fetch images and store in pouchdb
var path = require('path')
var Pouch = require('pouchdb')
var async = require('async')
var request = require('request')
var queue = async.queue(queueWorker, 5) // 5 requests at a time
var imageURLs = [
"http://substack.net/images/ben.png",
"http://substack.net/images/bed.png"
]
var pouch = require('pouchdb');
var pouches = {
http1: 'http://localhost:5984/http1',
http2: 'http://localhost:5984/http2',
ldb1: 'ldb://testdb1',
ldb2: 'ldb://testdb2',
}
Object.keys(pouches).forEach(function(key) {
@chesles
chesles / RBIF.js
Created November 5, 2012 05:36
Really Bad Image Format
/* Challenge #1
*
* Color: represents an RGB color. Pass a hexadecimal string (RRGGBB format,
* like CSS) to this constructor and get a Color object with integer r, g, and b
* components
*/
function Color(rgb) {
if (!(this instanceof Color)) return new Color(rgb);
var parts = rgb.match(/([0-9a-f]{2})/gi);
@chesles
chesles / d3.linechart.js
Created May 31, 2013 18:40
Reusable line chart using d3.chart
function getter(attr, scale) {
return function(d) {
return scale ? scale(d[attr]) : d[attr]
}
}
var defaults = {
width: 560,
height: 250,
x: 'x',
@chesles
chesles / borg.rb
Created May 31, 2013 19:17 — forked from xunker/borg.rb
voices = %w[Agnes Alex Bruce Bubbles Fred Junior Kathy Princess Ralph Vicki Victoria]
phrases = [
"We are the Borg.",
"Lower your shields and surrender your ships.",
"We will add your biological and technological distinctiveness to our own.",
"Your culture will adapt to service us.",
"Resistance is futile."
]
@chesles
chesles / gist:7143817
Last active December 26, 2015 11:29 — forked from paladiy/gist:5591997
{"keys": [], "values": ["123"]}