Skip to content

Instantly share code, notes, and snippets.

View mcavage's full-sized avatar

Mark Cavage mcavage

View GitHub Profile
@mcavage
mcavage / gist:1056404
Created June 30, 2011 14:57
Serving static content with restify
// Docs/etc.
server.get(null, '/', function(request, response, next) {
response.send(302, null, {
Location: config.siteName + '/docs'
});
return next();
}, log.w3c);
server.get(null, '/docs', function(req, res, next) {
@mcavage
mcavage / seattlejs.js
Created October 9, 2011 22:20
Example of running ldapjs over the GitHub API
var fs = require('fs');
var ldap = require('ldapjs');
var log4js = require('log4js');
var GitHubApi = require("github").GitHubApi;
///--- Globals
var bunyan = require('bunyan');
var restify = require('restify');
var server = restify.createServer({
log: bunyan.createLogger({
name: 'restify',
stream: process.stdout,
level: process.env.LOG_LEVEL || 'info',
serializers: restify.bunyan.serializers
})
@mcavage
mcavage / gist:3309350
Created August 10, 2012 00:08
telling me where to look further at what my restify app is doing...
putobject-ensureParent
value ------------- Distribution ------------- count
-1 | 0
0 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 153
1 | 1
2 | 1
4 | 1
8 | 0
putobject-ensureContentLength
@mcavage
mcavage / gist:1856186
Created February 17, 2012 23:31
stopmachine.sh
#!/bin/bash
# Globals
#export SDC_CLI_URL=https://us-west-1.api.joyentcloud.com
#export SDC_CLI_ACCOUNT=mark.cavage
#export SDC_CLI_KEY_ID=id_rsa
var restify = require('restify');
///--- Globals
var NotAuthorizedError = restify.NotAuthorizedError;
/**
* Figure out how long it takes for a method to execute.
*
* @param {func} method to test
* @param {int} iterations number of executions.
* @param {Array} args to pass in.
* @param {T} context the context to call the method in.
* @return {int} the time it took, in milliseconds to execute.
*/
var bench = function (method, iterations, args, context) {
@mcavage
mcavage / gist:1712462
Created January 31, 2012 19:38
Argument checking simplification
if (!String.prototype.capitalize) {
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
}
function assertArg(name, type) {
if (typeof(name) !== type)
throw new TypeError(name + '(' + type.capitalize() + ') required');
@mcavage
mcavage / gist:1563151
Created January 5, 2012 01:06
npmfreeze
#!/usr/bin/env node
// -*- mode: js -*-
var fs = require('fs');
var semver = require('semver');
var spawn = require('child_process').spawn;
///--- Globals
var deps = {};
[root@headnode (bh1-kvm1:0) ~]# plockstat -A -e 6 -p 40679
0
Mutex hold
Count nsec Lock Caller
-------------------------------------------------------------------------------
8421 1751 0xaa5408 beam.smp`erts_smp_mtx_unlock+0x9
2629 1749 0x61dee0 beam.smp`erts_deliver_time+0x4b
3257 1395 0xed46e8 beam.smp`erts_alcu_alloc_thr_pref+0xd6
208 21752 0xfffffd7fe97d9a70 beam.smp`do_port_command+0x34c