Instantly share code, notes, and snippets.

View utilization_and_cycle_time.py
import numpy
import random
from matplotlib import pyplot
percentiles = [50, 75, 90, 95, 99]
latencies = [[] for p in percentiles]
loads = []
n = 100000
for k in numpy.linspace(0.01, 1.0, 100):
View american_community_survey_example.py
# Uses American Community Survey data to estimate property taxes
# https://www.census.gov/programs-surveys/acs/
# The data is a f-ing PITA to parse, but here's an attempt
import bs4
import csv
import io
import os
import requests
import sys
View plot_word_length_in_letters.py
from num2words import num2words
from matplotlib import pyplot
lang = 'de'
words = [num2words(i, lang=lang) for i in range(1000000)]
fig = pyplot.figure()
ax = fig.add_subplot(111)
ax.semilogx([len(word) for word in words], color='green')
View beta.py
import matplotlib.pyplot, numpy, scipy.stats, seaborn
for i in range(50):
p, = scipy.stats.uniform.rvs(size=1)
a, b = scipy.stats.geom.rvs(p, size=2)
if a == b == 1:
continue
print(a, b)
x = numpy.linspace(0, 1, 1000)
y = scipy.stats.beta.pdf(x, a, b)
View ll_to_3d.py
def ll_to_3d(lat, lon):
lat *= math.pi / 180
lon *= math.pi / 180
x = math.cos(lat) * math.cos(lon)
z = math.cos(lat) * math.sin(lon)
y = math.sin(lat)
return numpy.array([x, y, z])
View kaplan_meier.py
n, k = len(te), 0
ts, ys = [], []
p = 1.0
for t, e in te:
if e: # whether the event was "observed" (converted) or not observed (may convert in the future)
p *= (n-1) / n
n -= 1
ts.append(t)
ys.append(100. * (1-p))
pyplot.plot(ts, ys, 'b')
View get_n_results.py
def get_n_results_dumb(q):
r = requests.get('http://www.google.com/search',
params={'q': q,
"tbs": "li:1"})
r.raise_for_status()
soup = bs4.BeautifulSoup(r.text)
s = soup.find('div', {'id': 'resultStats'}).text
if not s:
return 0
m = re.search(r'([0-9,]+)', s)
View group-rotation.js
/*
This code is meant to be used with a rotating responsibility for incoming bugs and stuff.
To make this work, you need to:
1. Set up the key in the Google IAM manager
2. Add domain delegation for the user
3. Download the key and add the following fields: "admin_email" and "domain"
*/
var key = require('./google-people-api-creds.json');
var scope = ['https://www.googleapis.com/auth/admin.directory.group',
View simulate_time_waitingt_train_problems.py
import numpy
from matplotlib import pyplot
import seaborn
p = numpy.logspace(-6, 0, 50)
pyplot.figure(figsize=(10, 5))
for k in [1, 3, 10, 30, 100, 300, 1000]:
Z = (p * k**2 + (1 - p)) / (p * k + (1 - p))
View simulate_time_waiting_n_2.py
import numpy
from matplotlib import pyplot
import seaborn
delta = 0.1
x = numpy.arange(0.0, 10.0, delta)
y = numpy.arange(0.0, 10.0, delta)
X, Y = numpy.meshgrid(x, y)
p = 0.5