Skip to content

Instantly share code, notes, and snippets.

@MatthaeusHarris
MatthaeusHarris / gist:1337815
Created November 3, 2011 21:22
Multiple sites on multiple ports on one machine
{
"webhosts": {
"example.com": {
"aliases": ["www.example.com"],
"docroot": "/var/www/example.com",
"ports": [80,443]
},
"foo.example.com": {
"aliases": ["www.foo.example.com"],
"docroot": "/var/www/foo.example.com",
#!/bin/bash
for f in $(find jpm/cloud0/ -type f)
do
if [ -e `echo $f | sed 's/^jpm\/cloud0/jpm\/cloud1/'` ]
then
#echo "Testing $f" >&2
diff $f `echo $f | sed 's/^jpm\/cloud0/jpm\/cloud1/'`
fi
done
@MatthaeusHarris
MatthaeusHarris / gist:3984608
Created October 31, 2012 03:24
JSON TCP buffer implementation
var util = require('util');
var events = require('events');
function JSONBuffer(sock) {
if (false === this instanceof JSONBuffer) {
return new JSONBuffer();
}
events.EventEmitter.call(this);
this.sock = sock;
@MatthaeusHarris
MatthaeusHarris / gist:3984672
Created October 31, 2012 03:42
Environment variable-based logger
function logger() {
if (false === (this instanceof logger)) {
return new logger();
} else {
var logString = process.env.FQDEBUG || "";
logLevels = logString.split(',');
for (var l in logLevels) {
this.logLevel[logLevels[l]] = true;
}
console.log(this.logLevel);
app.get("/gamevil/privacy", function(req, res) {
if (cache.privacy && cache.privacy.timestamp > moment().unix() - 3600) {
res.end(cache.privacy.data);
} else {
cache.privacy = {"timestamp": moment().unix()};
http.get("http://us.gamevil.com/news.php?m=policy", function(r) {
var page = "";
r.on('data', function(chunk) {
page += chunk;
});
var a = [1, 2, 3, 4, 5];
var b = function() {
if (null) {
var a = [1, 2, 3];
}
console.log(a);
}
console.log(a);
b();
@MatthaeusHarris
MatthaeusHarris / gist:48e03d71e06b1b4ac1b5
Created May 29, 2014 19:59
HTTP service uptime nagios plugin
#!/usr/bin/env ruby
# Tweakable knobs
# Which statuses constitute a success?
acceptable_statuses = ["200", "404", "403"]
# How much past history do we consider for each run, in seconds?
history = 60
Assuming a log file of entries like:
============================================================
user_id = SIEZYTIEROGHEC4BCXYU9A
request_id = 5c119b8a-73f5-4e98-86ce-f6755c60d256
operation = GET
request_timestamp = 1402072887926
key = path/to/my/object
response = 200
bytes = 34591
var eventAccumulator = function(event, eventsList, queue, callback) {
// logger.log("arena","eventAccumulator(%s,%s,%s,callback)",event, JSON.stringify(eventsList), JSON.stringify(queue));
logger.log("arena","eventAccumulator queue: " + queue + " event: " + event);
if (typeof eventAccumulator[queue] === 'undefined' || typeof eventAccumulator[queue].eventList === 'undefined') {
eventAccumulator[queue] = {};
eventAccumulator[queue].eventList = [];
for (var i in eventsList) {
eventAccumulator[queue].eventList.push(eventsList[i])
}
}
// Set up the event accumulator to fire when all users have been saved.
var arenaStartEvents = [];
for (var p in this.players) {
arenaStartEvents.push(this.players[p].userID);
this.players[p].on('leaveArena', (function(arena, player) {
return (function() {
arena.playerLeftArenaInProgress(player);
});
})(this, this.players[p]));
}