Skip to content

Instantly share code, notes, and snippets.

View jseabold's full-sized avatar

Skipper Seabold jseabold

View GitHub Profile
@jseabold
jseabold / ungoogle.py
Last active October 13, 2015 07:08
ungooogle
import urllib
import re
def ungoogle(url, type="pdf"):
try:
return urllib.unquote(re.search("(?<=url=).+"+type, url).group())
except:
return urllib.parse.unquote(re.search("(?<=url=).+"type, url).group())
@jseabold
jseabold / smb_share.sh
Created December 7, 2012 14:50
Mount a samba share for streaming music
# Provided you have set up the remote machine to share the folder you want
# You can do this
# get the IP address for the machine
nmblookup -I skipper-desktop
# cd to mount point
cd /media
# make a directory, if you need to
/* hack to clear screen in stata */
program define cls
di _newline(`=c(pagesize)')
end
@jseabold
jseabold / spirals.py
Created January 30, 2013 00:51
draw a spiral in matplotlib
import numpy as np
import matplotlib.pyplot as plt
#As a path collection
from matplotlib.collections import LineCollection
fig, ax = plt.subplots()
r = np.arange(0, .075, 0.00001)
nverts = len(r)
@jseabold
jseabold / wiki_scrape_papal.py
Last active December 14, 2015 10:39
Tutorial-style replication of Scraping portion of Papal Conclave forecasting by dmasad
{
"metadata": {
"name": "wiki_scrape"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@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
@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 / 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 / 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 / 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__)"`
}