Skip to content

Instantly share code, notes, and snippets.

@roberttod
roberttod / index-1.js
Last active May 18, 2017 20:50
Tutorial: Node.js authentication
const express = require('express')
const bodyParser = require('body-parser')
const store = require('./store')
const app = express()
app.use(express.static('public'))
app.use(bodyParser.json())
app.post('/createUser', (req, res) => {
store
@roberttod
roberttod / chars.js
Created May 5, 2015 15:30
None base64 chars allowed in cookie
// http://tools.ietf.org/html/rfc6265#section-4.1.1
var allowedChars = [0x21, [0x23, 0x2B], [0x2D, 0x3A], [0x3C, 0x5B], [0x5D, 0x7E]]
var chars = []
allowedChars.forEach(function (range) {
if (!range.length) {
chars.push(String.fromCharCode(range))
return
}
for (var code = range[0]; code < range[1]; code++) {
chars.push(String.fromCharCode(code))
@roberttod
roberttod / index.js
Created April 25, 2014 15:00
requirebin sketch
var $ = require("jquery");
var Router = require("cherrytree");
var Route = require("cherrytree/route");
var HistoryLocation = require("cherrytree/location/history_location");
// for router to keep the app's state in sync with the url
// we need to use a custom location, the default `none` location
// doesn't touch the URL. This allows you implementing your own
// URL manager say if you want to save some space, or you already
// use a framework that can manage URLs like Backbone.
@roberttod
roberttod / cookie-blocking-test.js
Created October 10, 2013 10:29
Test if the cookie is locked during synchronous execution.
@roberttod
roberttod / revert-require-context.js
Last active December 16, 2015 19:09
Change the context of require and then change back again
// Change require to new context
var newRequire = require.config({
context: "new"
});
// Define and then require module under context "new"
define("someModule", [], function () {return "newContext"; });
newRequire(["someModule"], function (something) {console.log(something); });
// Revert back to global context