Skip to content

Instantly share code, notes, and snippets.

View bjornarneson's full-sized avatar

Bjorn Arneson bjornarneson

View GitHub Profile
@bjornarneson
bjornarneson / scrape_fiscal_notes_v2.py
Created November 20, 2014 20:47
Scrape fiscal notes from Minnesota Management and Budget website to local directory
# modules we're using
# (be sure that lxml is in your python installation)
import lxml.html, urllib2, urlparse, os, shutil
# construct a namespace dictionary to pass to the xpath() call
# this lets us use regular expressions in the xpath
ns = {'re': 'http://exslt.org/regular-expressions'}
# build dictionary of fiscal note search pages
d = {
@bjornarneson
bjornarneson / gist:14bad31988bcc4d277b2
Created October 17, 2014 19:47
Label output for R charts
#cutlabels=FALSE gives nicer legend output
print(classIntervals(jenks71$jenks71, n=5, style="kmeans"), cutlabels=FALSE)
@bjornarneson
bjornarneson / sd1213mn.geojson
Created August 16, 2013 19:42
2012-2013 Minnesota school district boundaries
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bjornarneson
bjornarneson / sas_round.py
Created June 21, 2013 13:48
Python/Pandas/Numpy rounds 'halfway' numbers (e.g. 2.5, 4.5, -0.5) to the nearest even integer. SAS rounds these numbers *up* to the next integer. While the Numpy method is generally preferable, this helper function can be used to replicate output from SAS (or SPSS) in Python.
def round2(x):
"""Numpy rounds x.5 to nearest even integer. To emulate SAS/SPSS,
which both round x.5 *up* to nearest integer, use this function.
"""
y = x - np.floor(x)
if (0 < y < 0.5):
return np.floor(x)
else:
return np.ceil(x)
@bjornarneson
bjornarneson / asc2csv.c
Created June 12, 2012 02:51
Convert 2011-2012 Area Resource File (ARF) into a .CSV format readable by R
/* 1. Download the 2011-2012 ARF data files from http://arf.hrsa.gov/ */
/* 2. Download this gist into the same directory as the ARF file named arf2011.asc */
/* 3. Issue these commands in your terminal application: */
/* gcc -o asc2csv asc2csv.c */
/* ./asc2csv arf2011.asc > arf2011.csv */
/* 4. Open the resultant .csv data file with your R app of choice */
#include <stdio.h>
#include <stdlib.h>