Skip to content

Instantly share code, notes, and snippets.

@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
@mscdex
mscdex / gist:de646d2bf676c23014ce
Last active August 29, 2015 14:00
Monkey patches Express's res.render() to support a layout
/*
Usage:
Set a global/default layout with:
app.set('view layout', 'foo');
Set a layout per-render (overrides global layout) with:
res.render('foo', { layout: 'bar' });
Or disable a layout if a global layout is set with:
res.render('foo', { layout: false });
If no layout is provided using either of the above methods,
then the view will be rendered as-is like normal.
@mscdex
mscdex / isoagent.js
Created November 10, 2014 06:03
Http.Agent instance for response headers with latin1 characters
// First: `npm install agent-base streamsearch iconv-lite`
var http = require('http'),
net = require('net'),
EventEmitter = require('events').EventEmitter,
HTTPParser = process.binding('http_parser').HTTPParser,
parsers = http.parsers;
var agentBase = require('agent-base'),
StreamSearch = require('streamsearch'),
// 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()"
# Doxyfile 1.5.5
# This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project
#
# All text after a hash (#) is considered a comment and will be ignored
# The format is:
# TAG = value [value, ...]
# For lists items can also be appended using:
# TAG += value [value, ...]
var Class = require('./class').Class; // tested with v0.3.0-3-e1e4628 @ http://github.com/visionmedia/class.js
var LeafNode = new Class({
constructor: function(order){
this.order = order;
this.isLeafNode = true;
this.isInternalNode = false;
this.parentNode = null;
@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 / gcc-5.2.0-musl.diff
Created October 13, 2015 20:16
Fixed MIPS patch for gcc 5.2.0 with musl
# HG changeset patch
# Parent 9b5795e98965ab4820a65ceeae0de644d0c5a9bb
Use the generic implementation of libstdc++ primitives when we're on musl, not the glibc one.
diff -r 9b5795e98965 libstdc++-v3/configure.host
--- a/libstdc++-v3/configure.host Sun Jul 26 15:42:47 2015 -0400
+++ b/libstdc++-v3/configure.host Sun Jul 26 15:46:09 2015 -0400
@@ -274,6 +274,13 @@
os_include_dir="os/bsd/freebsd"
;;