Skip to content

Instantly share code, notes, and snippets.

@stucchio
stucchio / run-elephant.sh
Created April 4, 2011 18:14
A script to run elephantdb as a daemon
#!/bin/sh
if test -s /var/run/hadoop/elephantdb.pid;
then
OLDPID=`cat /var/run/hadoop/elephantdb.pid`
echo "Killing old elephant process, pid=$OLDPID"
kill $OLDPID
rm /var/run/hadoop/elephantdb.pid
fi;
nohup java elephantdb.main /elephant/global-conf.clj /usr/local/hadoop/conf/elephantdb-local-conf.clj "`date`" > /var/log/hadoop/elephantdb.log &
@stucchio
stucchio / fsm.js
Created August 9, 2011 08:12
Javascript Finite State Machine
function FiniteStateMachine(states, transitions, initialState) {
var state = initialState;
this.getState = function() {
return state;
};
this.transition = function(newState) {
if (_.detect(transitions, function(transition) { return (transition[0] == state) && (transition[1] == newState); })) {
if (('onExit' in states[state]) && (typeof states[state].onExit == 'function')) {
@stucchio
stucchio / gist:1403042
Created November 29, 2011 02:09
Graphs of bodyweight vs time
from pylab import *
E = 1.5 # exercise level
height = 6*12 #Height in inches
a = E * (66 + 12.7*height) / 3500.0
b = E * 6.23 / 3500
g = E * 6.775 / (365*3500.0)
age_range = (28, 40)
t = arange(age_range[0]*365,age_range[1]*365)
@stucchio
stucchio / rc.local
Created December 3, 2011 17:55
Making networking work on cloned Ubuntu VMs
if ! ifconfig eth0 && ! -f /var/log/rewriting-net-rules;
then
echo "Mac address for eth0 is incorrect."
/bin/rm -rf /etc/udev/rules.d/70-persistent-net.rules
touch /var/log/rewriting-net-rules
echo "Rebooting now."
/sbin/reboot
else
/bin/rm /var/log/rewriting-net-rules
fi
@stucchio
stucchio / hexbin_vs_scatter.py
Created March 24, 2012 14:58
Hexbin vs Scatterplot
from numpy import *
from pylab import *
x = rand(N)
y = x + random.normal(0, 0.4, size=(N,))
subplot(211)
axis((0,1,0,1))
scatter(x,y)
subplot(212)
@stucchio
stucchio / nyc_teacher.py
Created May 26, 2012 02:51
Plots used in my "NO SCATTERPLOT" post
# Data from: http://www.ny1.com/content/top_stories/156599/now-available--2007-2010-nyc-teacher-performance-data#doereports
from pylab import *
from pandas import *
import re
def get_data(filename):
d = read_csv(filename, delimiter="\t")
d['teacher'] = d['teacher_name_first_1'] + " " + d['teacher_name_last_1']
return d
@stucchio
stucchio / beta_bandit.py
Last active April 3, 2022 21:17
Beta-distribution Bandit
from numpy import *
from scipy.stats import beta
class BetaBandit(object):
def __init__(self, num_options=2, prior=(1.0,1.0)):
self.trials = zeros(shape=(num_options,), dtype=int)
self.successes = zeros(shape=(num_options,), dtype=int)
self.num_options = num_options
self.prior = prior
@stucchio
stucchio / beta_bandit.py
Created April 14, 2013 15:46
The beta-distribution based bayesian bandit algorith,.
from numpy import *
from scipy.stats import beta
class BetaBandit(object):
def __init__(self, num_options=2, prior=(1.0,1.0)):
self.trials = zeros(shape=(num_options,), dtype=int)
self.successes = zeros(shape=(num_options,), dtype=int)
self.num_options = num_options
self.prior = prior
@stucchio
stucchio / bayes_bandit_empirical_gain_from_incorporating_priors.py
Created April 28, 2013 22:17
Empirical gain from incorporating priors into the Bayesian Bandit
from numpy import *
from scipy.stats import beta
import random
class BetaBandit(object):
def __init__(self, num_options=2, prior=None):
self.trials = zeros(shape=(num_options,), dtype=int)
self.successes = zeros(shape=(num_options,), dtype=int)
self.num_options = num_options
@stucchio
stucchio / basic_income_monte_carlo.py
Last active August 28, 2021 01:42
Monte carlo simulation of basic income/basic job calculations, from blog.
from pylab import *
from scipy.stats import *
num_adults = 227e6
basic_income = 7.25*40*50
labor_force = 154e6
disabled_adults = 21e6
current_wealth_transfers = 3369e9
def jk_rowling(num_non_workers):