Skip to content

Instantly share code, notes, and snippets.

@nycdavid
nycdavid / gist:cd6723a483f458b50fa4
Created August 10, 2015 16:52
Example jwt auth middleware
require "pry"
class JwtAuthentication
def initialize(app)
@app = app
end
def call(env)
req = Rack::Request.new(env)
secret = ";Xsc2}M48w33xUvL7N>SG-V}OnU??BG&O&|!az,)yHpLgm/|g,kj^iVNwr<SFqy"
@nycdavid
nycdavid / gist:ea8a653e054d6b696e0a
Created June 6, 2014 14:12
Salud: Import script for JSON foods
var fs = require('fs'),
mongoClient = require('mongodb').MongoClient,
foodsJson = JSON.parse(fs.readFileSync('./foods-2011-10-03.json'));
mongoClient.connect('mongodb://127.0.0.1:27017/salud', function(err, db) {
if (err) throw err;
var collection = db.collection('foods-orig');
foodsJson.forEach(function(el, i) {
var fs = require('fs'),
path = '/path/to/sql/file'; // This represents a 4-5 gb file, way too large for a buffer in memory
// Without Streams
fs.readFile(path, 'utf8', function(err, data) { // This will fail because the size is too large for BUffer creation
if (err) throw err;
console.log(data);
});
// With Streams
@nycdavid
nycdavid / gist:0424f674b928f48dd406
Created May 31, 2014 02:24
Mastering Node.js: Chap.1 Events and Emitters
var EventEmitter = require('events').EventEmitter;
// Create the initial Counter class, that emits the named event
var Counter = function(init) {
this.increment = function() {
init++;
this.emit('incrementer', init);
}
};