This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2, csv | |
import matplotlib.pyplot as plt | |
import datetime | |
import seaborn | |
import numpy, scipy.stats, math | |
f = urllib2.urlopen('https://raw.githubusercontent.com/datasets/s-and-p-500/master/data/data.csv') | |
csv = csv.reader(f) | |
csv.next() # headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
import OpenSSL.crypto | |
import os | |
import requests | |
import ssl | |
import tempfile | |
@contextlib.contextmanager | |
def pfx_to_pem(pfx_path, pfx_password): | |
''' Decrypts the .pfx file to be used with requests. ''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |