Skip to content

Instantly share code, notes, and snippets.

View pschmied's full-sized avatar

Peter Schmiedeskamp pschmied

View GitHub Profile
@pschmied
pschmied / devifyosx
Created December 19, 2014 17:57
OS X config fixes
#!/usr/bin/env bash
# With apologies to:
# ~/.osx — https://mths.be/osx
# Ask for the administrator password upfront
sudo -v
# Keep-alive: update existing `sudo` time stamp until `.osx` has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
@pschmied
pschmied / devify-osx.sh
Created December 25, 2014 19:55
Make modern OSX make me not want to stab my own eyes out.
#!/usr/bin/env bash
# With apologies to:
# ~/.osx — https://mths.be/osx
# Ask for the administrator password upfront
sudo -v
# Keep-alive: update existing `sudo` time stamp until `.osx` has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
@pschmied
pschmied / zone-to-zone-travel
Created July 1, 2013 18:39
I whipped this up to validate zone-to-zone travel times and distances from our travel model. This takes a shapefile of zone centroids and queries Google for a random sampling of origin and destination pairs.
# You may need to install a couple libraries before loading them:
# install.packages(c("ggmap", "plyr", "rgdal"))
library(ggmap)
library(plyr)
library(rgdal)
# Here we read in a shapefile containing the centroids of our TAZs
zonecentroids <- readOGR(dsn="/path/containing/shapefile/no/final/slash",
layer="shapefile-containing-points")
@pschmied
pschmied / big-clip.R
Last active December 20, 2015 15:19
Clip a big number of parcels to the University District. All data downloaded from wagda.lib.washington.edu (must have netid to download)
# install.packages(c("rgdal", "rgeos", "ggmap", "maptools"))
library(rgdal)
library(rgeos)
library(ggmap)
library(maptools)
# Read the shapefile with OGR. Punctuation matters: No trailing slash
# on the dsn, and no .shp on the layer
udist <- readOGR(dsn="/Users/peter/Downloads/clip",
layer="unidstuc")
@pschmied
pschmied / filegdb.rb
Last active December 23, 2015 06:59
Homebrew formula to install ESRI FileGDB support. This package can be installed via this gist's URL. GDAL can then be installed with FGDB support either by modifying the GDAL formula, or by specifying the `--enable-unsupported` option to the GDAL build.
require 'formula'
# ESRI FileGDB support. This recipe can download the file from ESRI,
# however, you must sign into the ESRI support site and agree to their
# licensing terms from a webbrowser.
class Filegdb < Formula
homepage 'http://www.esri.com/software/arcgis/geodatabase/interoperability'
url 'http://downloads2.esri.com/Software/FileGDB_API_1_3-64.zip'
sha1 '95ba7e3da555508c8be10b8dbb6ad88a71b03f49'
@pschmied
pschmied / obesity-by-state.R
Created November 5, 2013 19:51
Plot of state obesity rates in descending order
# Statewide obesity data
# from http://massey.limfinity.com/data/
library(gdata)
library(ggplot2)
# stringsAsFactors=FALSE is important more often than not.
obesity <- read.xls("http://massey.limfinity.com/data/obesity.xls",
sheet=1, stringsAsFactors=FALSE)
@pschmied
pschmied / poisson-gamma-postpred.ipynb
Last active July 4, 2016 13:57
Sampling from a posterior predictive distribution in IJulia. See http://nbviewer.ipython.org/gist/pschmied/b443e5e2d876b5ce9627 for rendered version.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pschmied
pschmied / voting-power.png
Last active November 20, 2016 09:25
Relative voting power by state
voting-power.png
@pschmied
pschmied / knitr-example.Rnw
Last active March 31, 2017 00:53
An example of an xtable and some graphics in knitr w/LaTeX
% I use the memoir class for everything. `texdoc memoir` from your command
% prompt (on Mac & Linux anyway) has all the details. It's better.
\documentclass[11pt,letterpaper,article]{memoir} % for a short document
\usepackage{lipsum}
\usepackage{amsmath}
\usepackage{latexsym}
% Useful for Knitr. Otherwise, I use memoir class's 'ctabular' env.
\usepackage{longtable}
\newsubfloat{figure}% Allow subfloats in figure environment
@pschmied
pschmied / dsmpapi.org
Last active June 21, 2017 20:48
Using DSMP API from R

Publishing a dataset using DSMP API from R

These are some notes I made to reason through / illustrate usage of the new DSMP API. Usage here is presented as a linear set of steps for pedagogical purposes rather than attempting to create a reusable set of functions or a library.

Creating a new R client library based around the DSMP API is a task for the hopefully-not-too-distant future.