Skip to content

Instantly share code, notes, and snippets.

@mscdex
mscdex / node_debian_init.sh
Created August 6, 2011 09:33 — forked from peterhost/node_debian_init.sh
Daemon init script for node.js based app/server (DEBIAN/UBUNTU)
#! /bin/sh
# ------------------------------------------------------------------------------
# SOME INFOS : fairly standard (debian) init script.
# Note that node doesn't create a PID file (hence --make-pidfile)
# has to be run in the background (hence --background)
# and NOT as root (hence --chuid)
#
# MORE INFOS : INIT SCRIPT http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit
# INIT-INFO RULES http://wiki.debian.org/LSBInitScripts
# INSTALL/REMOVE http://www.debian-administration.org/articles/28
@mscdex
mscdex / bench.js
Created April 12, 2012 17:23 — forked from xk/bench.js
When threads_a_gogo beats node 2 to 1.... or does it?
/*
$ node bench.js
Threads_a_gogo JS thread -> 3039 (ms) 298607040
Node's main JS thread -> 4677 (ms) 298607040
Ratio: 1.54 times faster than main JS thread
New, separate VM -> 3065 (ms) 298607040
Ratio: 1.01 times faster than new VM
*/
@mscdex
mscdex / foo.js
Last active August 29, 2015 13:59 — forked from OliverJAsh/foo.js
var request = require('request');
var zlib = require('zlib');
var websiteRequest = request('http://oliverjash.me/', {
headers: {
'Accept-Encoding': 'gzip,deflate'
}
});
// Request, `http.ClientRequest` – writable stream, emits a `response` event
// loc_parser: functions to parse the textual part of a LOC record
// stored in our DNS. The key function here is parseLOCString which
// should be passed a dns.LOC and a string containing the latitude,
// longitude etc.
//
// This is an implementation of RFC 1876. Read it for background as
// the format in a dns.LOC is slightly unusual.
//
// Copyright (c) 2014 CloudFlare, Inc.
@mscdex
mscdex / update_to_nan_v2.0.x.sh
Created August 30, 2015 05:55 — forked from thlorenz/update_to_nan_v2.0.x.sh
Script to update Node.js addons to work with nan 2.0.x and thus with iojs v3.x (gets you 90% there)
#!/bin/bash
replacements=(
"NanAsyncWorker/Nan::AsyncWorker"
"NanAsyncQueueWorker/Nan::AsyncQueueWorker"
"NanCallback/Nan::Callback"
"NanSetInternalFieldPointer/Nan::SetInternalFieldPointer"
"NanGetInternalFieldPointer/Nan::GetInternalFieldPointer"
"NanNewBufferHandle\\(([^;]+);/Nan::NewBuffer(\\1.ToLocalChecked();"
"(NanNew(<(v8::)?String>)?\\(\"[^\"]*\"\\))/\\1.ToLocalChecked()"