Skip to content

Instantly share code, notes, and snippets.

@mlconnor
mlconnor / node.js proxy
Last active October 27, 2015 14:44
A node.js proxy in 13 lines
express = require('express')
request = require('request')
cors = require('cors')
apiServerHost = 'https://TARGET_SERVER'
app = express()
app.use(cors())
app.use('/', (req, res)->
url = apiServerHost + req.url
@mlconnor
mlconnor / s3cors.txt
Last active November 15, 2016 03:31
CORS policy on S3/CloudFront
Here is how you can test
Create bucket, add this policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": {
@mlconnor
mlconnor / cookieless_sessions.js
Created May 29, 2015 23:08
middleware for cookieless sessions in express.js
function buildHandler(originalMethod, res) {
return function(name,value,options) {
console.log('name=[' + name + '] val=' + value + ' args=' + _.toArray(arguments));
var args = _.clone(_.toArray(arguments));
if ( name == 'set-cookie' ) {
console.log('set-cookie');
if ( _.isString(value) ) {
console.log('str');
var match = value.match(/\s*connect\.sid\s*=\s*([^;$]+)/);
if ( match ) {
@mlconnor
mlconnor / mapobject.coffee
Last active August 29, 2015 14:20
function that maps one object to another using deep get and set
###
this is a function that makes it easy to map one object to another
using underscore/lodash.
###
_ = require('lodash') #3.10.1
mapper = (obj,mapping,initial)->
newObj = if initial then initial else {}
_.each(mapping, (from, to)->
@mlconnor
mlconnor / flattner.js
Last active August 29, 2015 14:16
JavaScript flattner for dotted notation.
function smoosher(object) {
var nodesToVisit = [ { path:[], d: object }];
var result = [];
var visitedObjects = [];
while ( nodesToVisit.length > 0 ) {
var currentNode = nodesToVisit.shift();
var nodeType = typeof currentNode.d === 'undefined' ? 'undefined' :
(typeof currentNode.d === 'object' && ! currentNode.d) ? 'null' :
({}).toString.call(currentNode.d).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
@mlconnor
mlconnor / 0_reuse_code.js
Last active August 29, 2015 14:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console

What

Roll your own iPython Notebook server with Amazon Web Services (EC2) using their Free Tier.

What are we using? What do you need?

  • An active AWS account. First time sign-ups are eligible for the free tier for a year
  • One Micro Tier EC2 Instance
  • With AWS we will use the stock Ubuntu Server AMI and customize it.
  • Anaconda for Python.
  • Coffee/Beer/Time
@mlconnor
mlconnor / bootstrap_index.html
Last active April 3, 2020 00:44
Bootstrap 3 CDN Template
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 3 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap core CSS -->
<link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" media="screen">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
@mlconnor
mlconnor / frontmatter.js
Created January 23, 2015 20:29
A simple front matter (YAML) with Handlebars template. Pass the name of the file into the program.
yaml = require('js-yaml');
fs = require('fs');
Handlebars = require('hbs');
Handlebars.registerHelper("sep", function(options){
if(options.data.last) {
return options.inverse();
} else {
return options.fn();
}
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Updated: 2010/12/05
// License: MIT
//
// Copyright (c) 2010-2013 Diego Perini (http://www.iport.it)
//
// Permission is hereby granted, free of charge, to any person