Skip to content

Instantly share code, notes, and snippets.

View andykent's full-sized avatar

Andy Kent andykent

View GitHub Profile
@andykent
andykent / gist:925458
Created April 18, 2011 14:31
Nginx Upstart
description "nginx http daemon"
start on runlevel [2]
stop on runlevel [016]
console owner
exec /opt/nginx/sbin/nginx -g "daemon off;"
respawn
@andykent
andykent / mongoid.rb
Created January 25, 2011 11:14
Demonstrates a bug in mongoid many-to-many associations with string keys
class User
include Mongoid::Document
field :name
references_and_referenced_in_many :accounts
end
class Account
include Mongoid::Document
field :name
key :name
@andykent
andykent / read.js
Created November 5, 2010 16:34
Test Case that shows a high number of writes getting mangled along with a file to scan over and validate the data.
var fs = require('fs');
var lines = fs.readFileSync('output.json', 'utf8').split("\n");
lines.pop(); // remove the last (empty) new line
for(var n in lines) {
try {
JSON.parse(lines[n]);
} catch (e) {
console.log("Error at line " + (n+1) + " => " + lines[n]);
}
}
reservePort = function(callback) {
var tickCheck = function() {
if(AVAILABLE_PORTS.length > 0) {
callback(AVAILABLE_PORTS.shift())
} else {
process.nextTick(tickCheck)
}
}
tickCheck();
}
@andykent
andykent / forward.coffee
Created July 3, 2010 17:39
Super simple, round robin, TCP port forwarding with node.js
net: require "net"
sys: require "sys"
LISTEN_PORT: 10000
SERVER_ADDRESS: '127.0.0.1'
AVAILABLE_PORTS: [10001, 10002, 10003, 10004, 10005, 10006]
CONNECTION_COUNTER: 0
reservePort: (callback) ->
if AVAILABLE_PORTS.length > 0
# Lightweight Rack middleware to ease configuring cache headers
#
# Sinatra usage example
#
# configure do
# Rack::CacheHeaders.configure do |cache|
# cache.max_age(/^\/$/, 60)
# cache.max_age(/^\/search$/, 3600)
# cache.expires(/^\/about\/.+$/, "00:00")
# cache.private(/^\/account/)