Skip to content

Instantly share code, notes, and snippets.

from __future__ import absolute_import
"""
This will configure and run the nosetests for graph against remove ec2 servers.
Running this makes a few assumptions.
1) You must have access to graph on github. This will checkout the repo to run the tests
2) You must have an account on EC2 and be able to create instances.
In order to configure, you need to create a file in your home called ~/.boto that looks like:
@turnersr
turnersr / submit.py
Created August 1, 2013 21:39
Code used to submit jobs to Cuckoobox via the REST API
import pycurl
import cStringIO
import json
import urllib
from collections import defaultdict
from time import sleep
import glob as g
base_api_url = "http://localhost:8090/"
@turnersr
turnersr / sort_check.ml
Created August 26, 2013 17:01
A simple sort result checker used to test the correctness of sorting function in a black box setting. This is taken from http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.112.3042&rep=rep1&type=pdf .
let x = [1;3;4;5;1;2;10;7];;
let y = List.sort compare x;;
let convert_pos list n =
let rec aux i r = function
| [] -> r
| e::t -> aux (i+1) (r @ [e*n+i]) t
in aux 0 [] list;;
@turnersr
turnersr / dart.html
Last active December 31, 2015 23:49
Day 1, using Dart to paint circles.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>My First Canvas Example</title>
</head>
<body style="margin:0px">
<Canvas id="my_canvas"> </Canvas>
<script type="application/dart" src="dots.dart"></script>
@turnersr
turnersr / palau_flag.dart
Created December 23, 2013 01:50
Day 2, use of the the cascade operator.
import 'dart:html';
import 'dart:math';
void main() {
init_palau_flag();
}
void init_palau_flag() {
palau_flag();
}
Uniregistry, Corp. 9 ['COUNTRY', 'CHRISTMAS', 'PICS', 'PHOTO', 'GIFT', 'LINK', 'GUITARS', 'SEXY', 'TATTOO']
Afilias Limited 8 ['BLACK', 'MEET', '\xe7\xa7\xbb\xe5\x8a\xa8 (xn--6frz82g) \xe2\x80\x93 Chinese for "mobile"', 'BLUE', 'KIM', 'PINK', 'RED', 'SHIKSHA']
United TLD Holdco Ltd. 7 ['DEMOCRAT', 'SOCIAL', 'MODA', 'DANCE', 'IMMOBILIEN', 'KAUFEN', 'NINJA']
United TLD Holdco, Ltd. 7 ['ROCKS', 'CONSULTING', 'HAUS', 'PUB', 'ACTOR', 'REVIEWS', 'FUTBOL']
Top Level Domain Holdings Limited 6 ['VODKA', 'COOKING', 'RODEO', 'HORSE', 'FISHING', 'MIAMI']
@turnersr
turnersr / dirichlet_pdf.py
Last active August 29, 2015 14:00
Dirichlet pdf in python
import math
import numpy as np
# Another example at http://stackoverflow.com/questions/10658866/calculating-pdf-of-dirichlet-distribution-in-python
def gamma(x):
return math.gamma(x)
@turnersr
turnersr / rs.py
Created April 29, 2014 04:17
Single-pass, parallel statistics algorithms for mean, variance, and standard deviation
class RunningStat(object):
"""
Based on ideas presented in
1. Numerically Stable, Single-Pass, Parallel Statistics Algorithms - http://www.janinebennett.org/index_files/ParallelStatisticsAlgorithms.pdf
2. Accurately computing running variance - http://www.johndcook.com/standard_deviation.html
"""
def __init__(self):
self.m_n = 0
self.m_oldM = 0
@turnersr
turnersr / sample_dirichlet.py
Last active August 29, 2015 14:00
Sampling from a Dirichlet distribution by sampling from a n-sphere and then projecting onto a n-simplex.
import numpy as np
def projection_on_to_simplex(sphere_point):
# References
# Same implmentation as the one used here at https://gist.github.com/daien/1272551
# Efficient Projections onto the .1-Ball for Learning in High Dimensions - http://machinelearning.org/archive/icml2008/papers/361.pdf
mu = np.sort(sphere_point)[::-1]
mu_sums = np.cumsum(mu)
rho = np.nonzero(mu * np.arange(1, sphere_point.shape[0] + 1) > (mu_sums - 1))[0][-1]