Skip to content

Instantly share code, notes, and snippets.

View jseabold's full-sized avatar

Skipper Seabold jseabold

View GitHub Profile
@jseabold
jseabold / download_remote_dir.py
Created September 18, 2012 18:49
walk and download a remote http file server
# if you can, just use wget
# wget -np -r remote_url
import re
import os
import urllib2
import urlparse
import pycurl
from lxml import html
@jseabold
jseabold / ipython_config.py
Last active October 9, 2015 05:07
ipython default profile config with git branch
c = get_config()
# lines of code to run at IPython startup.
c.TerminalIPythonApp.exec_lines = [
'Exit = exit',
'import numpy as np',
'np.set_printoptions(suppress=True)',
'import statsmodels.api as sm',
'import matplotlib.pyplot as plt',
'from scipy import stats, optimize',
@jseabold
jseabold / rmpy.sh
Last active October 6, 2015 11:48
rmpy delete python packages from dist-packages
function rmpy {
if [ -z "$1" ]; then
echo "Aren't you glad I didn't delete everything?";
else
sudo rm -rf /usr/local/lib/python2.7/dist-packages/$1*
fi
}
@jseabold
jseabold / cut.py
Created April 4, 2012 00:55
cut function for numpy
###########################################
# Note: this requires PR # 245 in numpy
# https://github.com/numpy/numpy/pull/245
#
# Author: Skipper Seabold
# License: BSD
import numpy as np
def cut(x, bins, right=True):
@jseabold
jseabold / anova_lm.py
Created March 30, 2012 02:14
ANOVA fitted linear model comparison for statsmodels
from pandas import DataFrame
import numpy as np
from scipy import stats
def anova_lm(*args, **kwargs):
"""
ANOVA table for one or more fitted linear models.
Parmeters
---------
@jseabold
jseabold / bootstrap_numpy.sh
Created March 23, 2012 20:16
bootstrap installations that depend on numpy
#! /bin/bash
# edit this to install whatever you want that depends on numpy after you
# reinstall numpy
# edit these variables or add to them
npsrc="$HOME/src/numpy/"
spsrc="$HOME/src/scipy/"
pdsrc="$HOME/src/pandas/"
smsrc="$HOME/statsmodels/statsmodels/"
@jseabold
jseabold / empirical_likelihood.py
Created March 19, 2012 12:11
Empirical Likelihood with Moment Constraints
from statsmodels.model import LikelihoodModel
import numpy as np
from numpy import asarray
from scipy import optimize
def log_star(z, eps):
"""
Owens' log* function. Provides curvature at eps.
"""
log_idx = z > eps
@jseabold
jseabold / bigmat.ado
Created January 12, 2012 20:35
Put a varlist into a matrix in Stata, even if matrix is bigger than matsize
/*
Put a variable or variable list into a Stata matrix even if it's bigger than
matsize.
Usage:
If you have some variables xb1 and xb2
bigmat xb1 xb2, mat(new_mat)
@jseabold
jseabold / transform.py
Created December 16, 2011 20:24
Use a decorator to transform the params input to a likelihood function.
"""
Use a decorator to transform the params input to a likelihood function.
"""
from functools import wraps
from contextlib import contextmanager
import numpy as np
import inspect
def make_doc(func, wrapper):
argspec = inspect.getargspec(func)
@jseabold
jseabold / translate.py
Created December 13, 2011 18:58
Use Google Translate API from Python
# -*- coding: utf-8 -*-
"""
You need to fill in your API key from google below. Note that querying
supported languages is not implemented.
Language Code
-------- ----
Afrikaans af
Albanian sq
Arabic ar