sudo apt-get install debootstrap schroot
CHROOT=/tmp/saucy-i386; mkdir -p $CHROOT; sudo debootstrap --arch=i386 --include=python-pandas,sudo,wget --components=main,universe,multiverse saucy $CHROOT http://debian.lcs.mit.edu/ubuntu
echo -e "[saucy-i386]\ndescription=Ubuntu saucy i386 architecture\ndirectory=$CHROOT\ntype=directory\nusers=$USER\nroot-groups=root\n" | sudo bash -c 'cat - > /etc/schroot/chroot.d/saucy-i386'
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 pandas as pd | |
from boto3 import client | |
client = client(service_name='ec2') | |
prices = client.describe_spot_price_history(InstanceTypes=["m3.medium"], | |
AvailabilityZone="us-east-1a") | |
df = pd.DataFrame(prices['SpotPriceHistory']) | |
df.set_index("Timestamp", inplace=True) | |
df["SpotPrice"] = df.SpotPrice.astype(float) |
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
# you can use something like this if read_html fails to find a table | |
# if you have bs4 >= 4.2.1, you can skip the lxml stuff, the tables | |
# are scraped automatically. 4.2.0 won't work. | |
import pandas as pd | |
from lxml import html | |
url = "http://www.uesp.net/wiki/Skyrim:No_Stone_Unturned" | |
xpath = "//*[@id=\"mw-content-text\"]/table[3]" |
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 pymc import Gamma, Poisson, Normal, MCMC, deterministic | |
import numpy as np | |
dta = dict(T=73, Nsubj=430, eps=0.0, t=[1, 21, 85, 128, 129, 148, 178, 204, | |
206, 210, 211, 212, 225, 238, 241, | |
248, 259, 273, 275, 281, 286, 289, | |
301, 302, 303, 304, 313, 317, 323, | |
344, 345, 349, 350, 351, 355, 356, | |
359, 364, 385, 386, 389, 390, 391, | |
392, 394, 395, 396, 397, 398, 399, |
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 wide_to_long(df, stubnames, i, j): | |
""" | |
User-friendly wide panel to long format. | |
Parameters | |
---------- | |
df : DataFrame | |
The wide-format DataFrame | |
stubnames : list | |
A list of stub names. The wide format variables are assumed to |
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 urllib | |
import docker | |
def get_manifest_auth_token(repo): | |
# https://docs.docker.com/registry/spec/auth/token/ | |
query = urllib.parse.urlencode({ | |
'service': 'registry.docker.io', | |
'scope': 'repository:{repo}:pull'.format(repo=repo) |
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
""" | |
Heavily inspired by the R package bindata. | |
""" | |
import numpy as np | |
from scipy import interpolate | |
from scipy import stats | |
def corr_to_joint(corr, marginals): | |
""" |
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
% stochastic independence | |
\newcommand\independent{\protect\mathpalette{\protect\independenT}{\perp}} | |
\def\independenT#1#2{\mathrel{\rlap{$#1#2$}\mkern2mu{#1#2}}} | |
% conditional probability pipe | |
\mid |
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
library(fpp) | |
data(usmelec) | |
write.csv(as.data.frame(list(date=as.Date(usmelec), usmelec=coredata(usmelec))), "usmelec.csv", row.names=FALSE) |
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
""" | |
Context manager or function to send text messages to your phone when a | |
process is done. | |
Edit the global variables. You might be able to find your phone e-mail | |
address here: http://tinywords.com/about-old/mobile/ | |
Usage: | |
with SendText("long running process"): | |
do_something() |