Skip to content

Instantly share code, notes, and snippets.

View ericf's full-sized avatar

Eric Ferraiuolo ericf

View GitHub Profile
ericf@Fino:deepclone (master)$ node -v
v0.10.16
ericf@Fino:deepclone (master)$ node deep-copy.js
Recursive Deep Copy x 11,638 ops/sec ±2.46% (88 runs sampled)
JSON Deep Copy x 11,146 ops/sec ±2.61% (88 runs sampled)
Fastest is Recursive Deep Copy
ericf@Fino:deepclone (master)$ nvm use v0.11.6
Now using node v0.11.6
ericf@Fino:deepclone (master)$ node -v
v0.11.6
diff --git a/src/app/js/router.js b/src/app/js/router.js
index 3b91967..8b8cc6f 100644
--- a/src/app/js/router.js
+++ b/src/app/js/router.js
@@ -9,6 +9,7 @@ Provides URL-based routing using HTML5 `pushState()` or the location hash.
var HistoryHash = Y.HistoryHash,
QS = Y.QueryString,
YArray = Y.Array,
+ YObject = Y.Object,
@ericf
ericf / gist:6153024
Last active December 20, 2015 15:19
#!/usr/bin/env node
var async = require('async'),
email = require('../lib/email'),
invs = require('../lib/invitations');
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdout.write('Are you sure you want to BLAST OFF EMAILS? (yes/NO): ');
@ericf
ericf / gist:6151890
Last active December 20, 2015 15:09
var async = require('async'),
exphbs = require('express3-handlebars'),
path = require('path'),
request = require('request'),
config = require('../config'),
helpers = require('../lib/helpers'),
invs = require('../lib/invitations'),
templates = config.dirs.emails,
@ericf
ericf / gist:6133744
Last active December 20, 2015 12:49

Proposal for Extending Express Apps

Creating npm packages which extend the functionality of Express apps has become a major thing we've been doing. There are several approaches we can take, from messing with the Express object prototypes, to creating a function in which an express app is passed in. After trying the former, I'm now a fan of the latter.

The Issues with Extending Express

Extending the Express object prototypes has issues. The running Node.js process may have multiple versions of express, and in order to extend the prototypes you need to require('express'). This means that you might get a different express module instance than the one the main app is created from.

Both approaches suffer from extending something more than once. Similar to how there may be multiple version of express in the running Node.js process, there can also be multiple copies of the extension modules. If the app developer needs to rely on a different version of an Express ext

@ericf
ericf / rsvp.js
Created May 14, 2013 17:46
A snippet from rsvp.js from my wedding site.
Y.Model.prototype.promiseSave = function (options) {
var model = this;
return new Y.Promise(function (resolve, reject) {
model.save(options, function (err, res) {
return err ? reject(err) : resolve(res);
});
});
};
@ericf
ericf / guests.js
Last active December 17, 2015 01:19
This is how I've been using node-postgres to create parameterized queries to PostgreSQL which may contain one or more updates to a row. Stay safe, but flexible :) https://github.com/brianc/node-postgres
var pg = require('pg'),
config = require('../config'),
GUEST_BY_ID = 'SELECT * FROM guests WHERE id=$1 LIMIT 1',
UPDATE_GUEST = 'UPDATE guests SET $UPDATES WHERE id=$1',
UPDATE_SCHEMA = {
title : true,
name : true,
Y.Guest = Y.Base.create('guest', Y.Model, [Y.ModelSync.REST], {
root: '/guests/'
});
Y.Guests = Y.Base.create('guests', Y.ModelList, [Y.ModelSync.REST], {
model: Y.Guest
});
Y.Invitation = Y.Base.create('invitation', Y.Model, [Y.ModelSync.REST], {
root: '/invitations/',
<!doctype html>
<html>
<head>
<meta charset="utf8">
<title>JSON</title>
</head>
<body>
<h1>JSON Test Page</h1>
#!/usr/bin/env node
var fs = require('fs'),
path = require('path'),
yui_module = process.argv[2] ? path.join(process.cwd(), process.argv[2]) : 'yui',
output = process.argv[3],
EXCLUDE_FILTERS = [
/^cookie/,