Skip to content

Instantly share code, notes, and snippets.

@mlconnor
mlconnor / depth_breadth.txt
Created August 14, 2014 20:24
depth first search vs breadth first search
list nodes_to_visit = {root};
while( nodes_to_visit isn't empty ) {
currentnode = nodes_to_visit.first();
nodes_to_visit.prepend( currentnode.children );
//do something
}
BFS:
list nodes_to_visit = {root};
@mlconnor
mlconnor / arr2csv.js
Created August 19, 2014 17:52
converts and array of objects into a csv string
function arr2csv(arr) {
var cols = [];
/* get a list of unique columns */
_.each(arr, function(item) {
cols = _.union(_.keys(item), cols);
});
var csvRows = [cols.join("\t")];
for ( var i = 0; i < arr.length; i++ ) {
var row = arr[i];
@mlconnor
mlconnor / py.txt
Last active August 29, 2015 14:05
Python notes
Good basic intro on types
https://docs.python.org/2/tutorial/introduction.html
https://docs.python.org/2/tutorial/controlflow.html
blocks use : and indent
while a < b:
print a
if x < 0:
@mlconnor
mlconnor / app.js
Last active August 29, 2015 14:09
Performance test with node.js
var request = require('request');
var async = require('async');
var url = "...";
var payload = "...";
var calls = [];
var clients = 100;
var callsPerClient = 20;
var thinkTime = 0;
//
// 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

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 / 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
@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 / 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 / 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 ) {