Skip to content

Instantly share code, notes, and snippets.

View tblobaum's full-sized avatar
😆

Thomas J Blobaum tblobaum

😆
  • Creston, Iowa
View GitHub Profile
global
log 0.0.0.0 local2 info
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
daemon
defaults
option http-server-close
option http-pretend-keepalive
timeout connect 4s
var Redis = require('redis-stream')
, client = new Redis(6379, 'localhost')
, es = require('event-stream')
// stream monitor to all http requests
// curl http://localhost:3000/
function server (request, response) {
var redis = client.stream()
redis.pipe(es.join('\r\n')).pipe(response)
//
// example
var Redis = require('redis-stream')
, redis = new Redis(6379, 'localhost')
//
// reimplementation of rpoplpush with streams
var rpoplpush = redis.stream('rpop')
rpoplpush.pipe(redis.stream('lpush', 'list-two'))
rpoplpush.write('list-one')
var Drone = require('worker-drone')
, queue = [ { val : 1 }, { val : 2 }, { val : 0 }, { val : 2 }, { val : 4 } ]
, results = [ ]
var worker = new Drone({
work: function (data, callback) {
data.val += 5
callback(null, data)
}
, poll: 1000
@tblobaum
tblobaum / server.js
Created April 21, 2012 06:49
a little server to get vimeo thumbnails (why dont they do this already?)
process.setgid('nobody')
process.setuid('nobody')
require('rconsole')
.set({ facility: 'local0' })
require('http')
.createServer(require(__dirname + '/vimeo'))
.listen(80)
// returns the first defined argument, which is useful for cleanly
// setting values with multiple potential defaults
function defined () {
for (var i=0; i<arguments.length; i++)
if (typeof arguments[i] !== 'undefined')
return arguments[i]
}
var baz = false
$ fleet ps --hub=localhost:3002 --secret=beepboop
drone#308d6b03
└─┬ pid#ba7063
├── status: running
├── commit: fleet-inception/d6fb3002df40e8f0ab20e26b9cb212bb34a64713
└── command: fleet hub --port=3000 --secret=beepboop
$ fleet ps
drone#20ca93c3
└─┬ pid#e6eaa

node-host-components

run components of a large project on separate machines

Example

Place your existing node application in a sub directory, and create a server.js file so it is relative to the other files like this. Let's assume we started with two node modules or servers that work together (api and application) We handled deployment and version control of these applications separately because, well, we had to, but it's about to get a lot easier.

├─┬ api
function getArgs (fn, callback) {
var str = fn.toString()
, ret = str.match(/\(([^\)]*)\)/)[1].split(', ')
callback && callback(ret)
return ret
}
function throttle(fn, delay) {
var timer = 0
, last = new Date().getTime()
return function () {
var context = this
, args = arguments
, should = last + delay
, ind = should - new Date().getTime()
if ( ind < 0 ) {