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
@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: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: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;
@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
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:7810003
Last active Dec 30, 2015
"foo" task for creating a new Foo instance
View gist:7810003
task('foo', {async: true}, function () {
var f = geddy.model.Foo.create({title: 'zerb', description: 'frang'});
f.save(function (err, data) {
if (err) { throw err; }
geddy.model.Foo.all({id: f.id}, function (err, data) {
if (err) { throw err; }
console.log('Found foo', data[0].id);
geddy.model.Foo.first({id: f.id}, function (err, data) {
if (err) { throw err; }
console.log('Found foo again', data.id);
View model-hasMany-error.js
var
// $ npm install model@0.2.10
model = require( 'model'),
Adapter = require('./node_modules/model/lib/adapters/memory/').Adapter,
adapter = new Adapter({});
var User = function () {
this.adapter = adapter;
this.property('login', 'string', {required: true});
this.property('password', 'string', {required: true});
View gist:6237190
// Determine if `content` is a collection of models
else if(content instanceof Array) {
if(!type) {
throw new Error(
'Cannot determine model type from empty array, specify one in opts');
}
@mde
mde / gist:6223332
Created Aug 13, 2013
Two overlapping experiments
View gist:6223332
<%
var msg = '';
if (testA) {
msg += '<div>group</div>';
}
if (testB || testA) {
msg += '<div>conversation</div>';
}
%>
<%= msg; %>
View gist:6100679
var User = function () {
this.hasMany('Messages');
this.hasMany('ConversationMemberships');
this.hasMany('Conversations', {through: 'ConversationMembership'});
};
var Conversation = function () {
this.hasMany('Messages');
this.hasMany('ConversationMemberships');
this.hasMany('Users', {through: 'ConversationMembership'});
You can’t perform that action at this time.