Skip to content

Instantly share code, notes, and snippets.

View danrpts's full-sized avatar
🤠
Howdy

Daniel Peterson danrpts

🤠
Howdy
View GitHub Profile
@danrpts
danrpts / followAsync.js
Last active August 29, 2015 14:16
An asynchronous directory walk for targeting files.
var fs = require("fs");
var path = require("path");
function asyncForEach (array, fun) {
array.forEach(function (element) {
process.nextTick(function () {
fun(element);
});
});
}
@danrpts
danrpts / followSync.js
Last active August 29, 2015 14:15
A synchronous directory walk for targeting files.
var fs = require('fs');
var path = require('path');
function followSync (start, fun) {
var found = [];
var isfun = (typeof fun === "function");
(function sync (trail) {
fs.readdirSync(trail).forEach(function (breadcrumb) {
var next = path.join(trail, breadcrumb);
fs.statSync(next).isDirectory() ?
@danrpts
danrpts / fibonacci.rb
Created November 11, 2014 05:32
A space-saving, bottom-up algorithm to calculate the nth Fibonacci number in linear time.
def fibonacci(n)
arr = [0, 1]
for k in 2..n do
arr[1] = arr[1] + arr.shift
end
return arr[1]
end
@danrpts
danrpts / boot
Last active April 4, 2017 22:53 — forked from jdx/boot.js
#!/usr/bin/env node
// This script will boot bin/www with the number of workers
// specified in WORKER_COUNT.
//
// The master will respond to SIGHUP, which will trigger
// restarting all the workers and reloading the app.
var cluster = require('cluster');
var workerCount = process.env.WORKER_COUNT || 2;