Skip to content

Instantly share code, notes, and snippets.

Matthew Eernisse mde

Block or report user

Report or block mde

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Jake async complete
task('foo', {async: true}, function () {
console.log('entered foo');
setTimeout(complete, 10);
console.log('after foo timeout');
});
task('default', {async: true}, function () {
var t = jake.Task.foo;
t.on('complete', function () {
console.log('foo completed');
@mde
mde / gist:8965696
Created Feb 12, 2014
Thrown error in Mongo callback not caught by domain
View gist:8965696
var http = require('http')
, domain = require('domain')
, mongo = require('mongodb')
, config = {
username: null
, dbname: null
, prefix: null
, password: null
, host: 'localhost'
, port: 27017
@mde
mde / gist:9216297
Last active Aug 29, 2015
Simple Node HTTP proxy
View gist:9216297
var http = require('http')
, server = http.createServer();
server.on('request', function (serverReq,
serverResp) {
var host = 'www.example.com'
, opts
, clientRequest
, handle;
View gist:c07995770e5b8e960802
upstream foo_site {
server 127.0.0.1:4000;
}
server {
listen 80;
server_name www.foo.com foo.com;
access_log /var/log/nginx/foo_site.access.log;
location / {
proxy_pass http://foo_site;
}
@mde
mde / gist:2c4fe6906db45d652b88
Created Jun 9, 2014
Escape any escape sequences in a string
View gist:2c4fe6906db45d652b88
var escapeEscapeSequences = function (str) {
return str
.replace(/[\\]/g, '\\\\') // Slash has to go first
.replace(/[\b]/g, '\\b')
.replace(/[\f]/g, '\\f')
.replace(/[\n]/g, '\\n')
.replace(/[\r]/g, '\\r')
.replace(/[\t]/g, '\\t');
};
View gist:6df28c379d544e02c13d
bash-3.2$ npm install
npm http GET https://registry.npmjs.org/filelist
npm http GET https://registry.npmjs.org/minimatch/0.2.3
npm http 200 https://registry.npmjs.org/filelist
npm http GET https://registry.npmjs.org/filelist/-/filelist-0.0.2.tgz
npm http 200 https://registry.npmjs.org/minimatch/0.2.3
npm http GET https://registry.npmjs.org/minimatch/-/minimatch-0.2.3.tgz
npm http 200 https://registry.npmjs.org/filelist/-/filelist-0.0.2.tgz
npm WARN package.json filelist@0.0.2 No README.md file found!
npm http 200 https://registry.npmjs.org/minimatch/-/minimatch-0.2.3.tgz
View riakpbc domains
var http = require('http')
, domain = require('domain')
, riakpbc = require('./index')
, riak = riakpbc.createClient({host: 'localhost', port: 8087});
http.createServer(function (req, res) {
var dmn = domain.create();
dmn.on('error', function (err) {
console.dir(arguments);
View gist:82a934b6a3fa1da604be
> var foo = function (a) { return function (b) { return a * b; }; };
undefined
> var bar = foo(2);
undefined
> bar(5);
10
> var foo = function () { console.log(arguments.length); };
undefined
> foo();
0
@mde
mde / gist:81b131ff6810ed7c4e0e
Last active Aug 29, 2015
Simple left-to-right mixin
View gist:81b131ff6810ed7c4e0e
var mixin = function () {
var args = Array.prototype.slice.call(arguments);
var target = args.shift();
var source = args.shift();
// We don't need no hasOwnProperty checks!
for (var prop in source) {
target[prop] = source[prop];
}
if (args.length) {
args.unshift(target);
View gist:3825a3732effbe76ee62
var foo = {
a: function () {
console.log(this);
}
};
foo.a(); // Logs the foo obj
foo['a'](); // Same, logs the foo obj
You can’t perform that action at this time.