Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am conorsg on github.
  • I am conorsg (https://keybase.io/conorsg) on keybase.
  • I have a public key ASDz1RwKfxO36GRiJBb_QV0_uPU3Uh6Nlk1oP3gOpQbUKQo

To claim this, I am signing this object:

@conorsg
conorsg / ebrso.py
Last active November 14, 2019 13:04
EBRSO warrant list scraper
# Pulls EBRSO warrant list from https://www.ebrso.org/PUBLICTOOLS/WarrantListModule.aspx
# Written by Conor Gaffney (conorsg) in 2019
#
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import csv
import requests
import pandas as pd
@conorsg
conorsg / pocket-shame.py
Last active August 29, 2015 14:18
counts how many unread articles you have in your pocket queue each day. see: http://conorgaffney.com/2015/04/12/pocket-shame/
#!/usr/bin/python
import json
import urllib3
import certifi
from datetime import datetime, date, timedelta
from time import strftime
simple_data = []
record = []
@conorsg
conorsg / sheriff-sales.py
Last active August 29, 2015 14:18
scrapes all the sheriff's sale data. this takes a looooong time to run
#!/usr/bin/python
# gets sheriff's sale data from http://www.civilsheriff.com/RealEstateSales.asp
#
# example of URL that returns sales:
# http://www.civilsheriff.com/RealEstate/RealEstateBody.asp?MYSaleDate=11/6/2014
#
#
# the good people at http://www.notrs.com/ who made the sheriff's website could use a lesson or two in web development
from bs4 import BeautifulSoup
buildChart <- function(p) {
gt <- ggplot_gtable(ggplot_build(p))
t <- gtable_filter(gt, "title")[[1]]
l <- gtable_filter(gt, "guide-box")[[1]]
p <- p + theme(legend.position = "none", plot.title = element_blank())
@conorsg
conorsg / deduper.R
Created February 4, 2015 16:23
dedups entries in kentico form
#dedup
require(dplyr)
require(lubridate)
d <- read.csv("FILE")
names(d)[1] <- "id"
names(d)[2] <- "date"
names(d)[5] <- "first"
names(d)[7] <- "last"
names(d)[8] <- "social"
@conorsg
conorsg / geobaser.R
Last active August 29, 2015 14:14
gets the geographies for the baseline recruit group
#!usr/bin/Rscript
require(lubridate)
require(dplyr)
require(jsonlite)
require(RCurl)
require(stringr)
require(xtermStyle)
#fns
@conorsg
conorsg / opa-interview.R
Created October 19, 2014 18:18
calculates empirical probabilities of outcomes of 911 calls and fits regression to some of them
#!/usr/bin/Rscript
library(lubridate)
#utility functions
action <- c("RTF", "NAT", "NAT71", "NATC", "NATM", "NATT", "RTFC", "RTFM", "RTFT")
noaction <- c("UNF", "VOI", "GOA") #remaining dispositions, like TEST and UKN are disregarded
catAct <- function(disp) {
if(disp %in% action) {
@conorsg
conorsg / heatmaker.R
Created October 3, 2014 04:25
transforms some date data and uses calendarHeat.R to make calendar heat maps
source('calendarHeat.R')
PropTypes <- c("67P", "55", "67F", "67A", "67", "56", "62", "67S", "62C", "62R", "67B", "56D", "62B", "65", "67E", "67C", "65P", "65J")
ViolTypes <- c("35D", "35", "34", "34S", "37", "34D", "34C", "37D", "60", "38D")
HomicideTypes <- c("30", "30S", "30C", "30D")
RapeTypes <- c("42", "43")
GunTypes <- c("64G", "94", "95", "95G")
df <- read.csv('FILE', sep=',', header=T)
df.violent <- df[df$Type_ %in% ViolTypes, ]
@conorsg
conorsg / geocode-a-csv.py
Created October 1, 2014 21:30
makes calls to Google's geocode API down a column of addresses in a csv, writes the lat long on back
#!/usr/bin/env python
import json
import urllib2
import csv
api_key = 'YOUR_API_KEY'
with open('FILE.csv', 'rU') as f:
reader = csv.reader(f)