Skip to content

Instantly share code, notes, and snippets.

View jseabold's full-sized avatar

Skipper Seabold jseabold

View GitHub Profile
@jseabold
jseabold / pysal_auto.ipynb
Created September 9, 2013 16:58
Try to replicate some spatial autocorrelation statistics.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jseabold
jseabold / hepatitis.csv
Created September 9, 2013 16:54
For this example we will consider the distribution of hepatitis rates for the counties of California. The data are taken from the Department of Health Services of the State of California (1999). Obtained from: http://www.nku.edu/~longa/geomed/ppa/doc/globals/Globals.htm
County X Y Rate
Alameda 195 500 14.4
Alpine 318 560 0.0
Amador 265 550 12.1
Butte 220 630 52.9
Calaveras 280 530 22.6
Colusa 195 598 23.8
Contra Costa 192 515 12.5
Del Norte 100 790 301.5
El Dorado 260 580 32.0
@jseabold
jseabold / schedule_sleep.sh
Last active December 19, 2015 20:58
Use rtcwake to sleep immediately and wake up in 23 hours (to do some stuff for an hour). Intended to be called from cron.
#!/bin/bash
DATE=`date -d "now + 23 hour + 0 min + 0 sec" +%s`
rtcwake -lv -m disk -t $DATE
exit
@jseabold
jseabold / alias.sh
Created July 2, 2013 18:36
Handy aliases.
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../../;'
alias c='clear'
alias ping='ping -c 5'
alias ports='netstat -tulanp'
alias apt-get="sudo apt-get"
## pass options to free ##
alias meminfo='free -m -l -t'
@jseabold
jseabold / prompt.sh
Created July 2, 2013 18:29
Prompt that includes the github branch name.
# place in .bashrc
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "("${ref#refs/heads/}")"
}
PS1="[\w] \$(parse_git_branch)\n|\# \$ "
PS2="\[\033[1;33m...\[\033[0m\]"
@jseabold
jseabold / pushdp.sh
Created July 2, 2013 18:28
Change to directory in which a Python program is installed.
function pushdp {
pushd `python -c "import os; import $1; print os.path.dirname($1.__file__)"`
}
@jseabold
jseabold / skyrim_table.py
Last active June 14, 2018 03:02
Read an HTML table using pandas
# 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]"
@jseabold
jseabold / orth_poly.py
Created June 25, 2013 14:56
Christoffel-Darboux recurrence relation for orthogonal polynomials using numpy
# this is a translation of orthpoly.ado from Stata 11. Their license likely applies.
def orthpoly(X, deg, weights=None):
"""
Christoffel-Darboux recurrence relation for orthogonal polynomials.
"""
nobs = len(X)
orth_poly = np.ones((nobs, deg+1))
for i in range(1, deg+1):
t = X*orth_poly[:,i-1]**2
@jseabold
jseabold / standardized_regressors.py
Created May 3, 2013 14:10
standardize each variable in a statsmodels regression
import statsmodels.api as sm
from statsmodels.formula.api import ols
# load some data
dta = sm.datasets.longley.load_pandas()
# make a standardized RHS formula
stand = "standardize(%s)"
std_rhs = ' + '.join([stand]*len(dta.exog_name)) % tuple(dta.exog_name)
print std_rhs
@jseabold
jseabold / ipcluster_launcher.py
Created March 29, 2013 20:17
Start an IPython cluster with subprocess
"""
Creates a task interface.
Change to
view = rc[:]
for a direct interface.
"""
from IPython.parallel import Client