Skip to content

Instantly share code, notes, and snippets.

View jbn's full-sized avatar

John B Nelson jbn

View GitHub Profile
@jbn
jbn / D3_IPython_Freeze_Framing.ipynb
Created September 1, 2015 21:26
A Little Demo of a Fun Technique for D3.js Development
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jbn
jbn / always_on_jupyter.sh
Created September 10, 2015 14:12
Always On Jupyter
# Installation:
# - Put this in your .bash_profile
# - Replace my directory with your exobrain directory on line 10
#
# What you get:
# A Jupyter notebook open on a well-defined port that is always
# on for exobrain-ing your ideas...
exec 6<>/dev/tcp/localhost/10000 || (
source activate py27 &&
@jbn
jbn / rewrite_oauth_serialize_url_parameters.jl
Created September 18, 2015 22:48
My justification for rewriting OAuth.jl's oauth_serialize_url_parameters
function method_a(options)
parameterstring = ""
keyssorted = sort!(collect(keys(options)))
for key in keyssorted
parameterstring *= "$key=$(options["$key"])&"
end
chop(parameterstring)
end
function method_b(options)
@jbn
jbn / nan_to_na.py
Last active October 16, 2015 20:52
import os
import numpy as np
import pandas as pd
import rpy2
from rpy2 import robjects
from rpy2.robjects.packages import importr
AMELIA = importr("Amelia")
@jbn
jbn / ulp_speed.scala
Created November 11, 2015 22:15
A script to test the time-expense of scala.math.ulp
import scala.math.ulp
/**
* ThirdWay calls `ulp` occasionally. This script tries to assess costs.
*/
def timeIt[R](f: => R): Long = {
val start = System.currentTimeMillis
f
System.currentTimeMillis - start
@jbn
jbn / epsilon_and_scheduling.scala
Created November 11, 2015 22:47
Double's epsilon and scheduling artifacts
/*
Consider two activities, A and B, both scheduled at the same time. When
activated, they schedule themselves for reactivation in a time delta of 0.1
and 0.2. If this is less than the ulp at a given time, both activities end
up being scheduled at the same time.
*/
import scala.math.ulp
val MaxTime = 9.007199254740991E15
@jbn
jbn / spark_json_reader.scala
Created December 10, 2015 18:19
JSON + bz2 + Spark = WINNING
// Load a DataFrame of users. Each line in the file is a JSON
// document, representing one row.
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
val people = sqlContext.read.json("users.json.bz2")
$ nslookup donaldjdrumpf.com
54.192.37.{240, 220, 36, 204, 108, 84, 38, 123}
$ nslookup optrump2016.com
104.18.47.68
104.18.46.68
$ nslookup donaldtrump.com
104.16.72.120
104.16.75.120
@jbn
jbn / Makefile
Created March 30, 2016 18:51
Fetch and Save First, Makefile
# Makefile
FETCH = data/raw/FETCHED
PROCESS = data/clean/CLEANED
all: $(FETCH) $(PROCESS)
$(FETCH): scripts/fetch.py
@mkdir -p data/raw
python scripts/fetch.py
@touch $(FETCH)