Skip to content

Instantly share code, notes, and snippets.

@soodoku
soodoku / state_abbrev_fips.txt
Created April 12, 2016 21:03
US State Abbreviations to FIPS crosswalk
1 AL
2 AK
4 AZ
5 AR
6 CA
8 CO
9 CT
10 DE
11 DC
12 FL
@fredbenenson
fredbenenson / kickstarter_sql_style_guide.md
Last active April 2, 2024 15:19
Kickstarter SQL Style Guide
layout title description tags
default
SQL Style Guide
A guide to writing clean, clear, and consistent SQL.
data
process

Purpose

@carlislerainey
carlislerainey / mass-shootings.R
Last active December 4, 2015 12:51
Downloads and plots data on mass shootings from Mother Jones (http://www.motherjones.com/politics/2012/12/mass-shootings-mother-jones-full-data)
# load packages
library(magrittr)
library(googlesheets)
library(lubridate)
library(dplyr)
library(stringr)
library(tidyr)
library(ggplot2)
library(maps)
@soodoku
soodoku / cong.csv
Last active November 22, 2015 20:29
Educational Qualifications of Members of the 111th Congress
Name District Education Science Law
Jeff Sessions (R) AL-Senate B.A., Huntingdon College; J.D. University of Alabama School of Law 1
Richard Shelby (R) AL-Senate B.A., University of Alabama; J.D. University of Alabama School of Law 1
Jo Bonner (R) AL-1 B.A. Journalism, University of Alabama 0
Bobby Bright (D) AL-2 B.A. Political Science, Auburn University; M.S. Criminal Justice, Troy State University; J.D. Thomas Goode Jones School of Law 1
Mike Rogers (R) AL-3 B.A., Political Science; M.P.A., Jackson State University; J.D. Birmingham School of Law 1
Robert Aderholt (R) AL-4 B.A., Political Science/History, Birmingham Southern College; J.D., Samford University 1
Partker Griffith (D) AL-5 B.S.; M.D., Louisiana State University 0
Spencer Bachus (R) AL-6 B.A., Auburn University; J.D., University of Alabama 1
Artur Davis (D) AL-7 B.A., Government, Harvard University; J.D., Harvard University School of Law 1
@bearloga
bearloga / classify.R
Created September 10, 2015 19:27
A function which launches a Shiny app for hand coding (manually classifying) data.
#' Manual classification of observations
#'
#' \code{classify} launches a Shiny app to manually classify a subset of observations.
#'
#' @param x A character vector.
#' @param btn_labels A character vector of length 2 corresponding to 0 and 1.
#' @return A vector of 0/1 for each element in \code{x}.
#' @export
#' @examples \dontrun{
#' foo <- sprintf('%s (%.2f miles per gallon)', rownames(mtcars), mtcars$mpg)
@tslumley
tslumley / redpeak.R
Last active September 9, 2015 14:02
redpeak=function(s,w){
x=c(0,0,1,NA, 1,2,2,NA,0.5,1,1.5)
y=c(0,1,1,NA,1,1,0,NA,0,0.5,0)
polygon(x*w+s[1],y*w+s[2],col=c("black","navyblue","#98332f"))
}
@soodoku
soodoku / server_installs
Last active August 30, 2015 23:40
Basic R related installs for Initializing Scrapers on Digital Ocean Ubuntu
apt-get upgrade
apt-get update
sudo aptitude install emacs24
sudo aptitude install r-base
sudo aptitude install libcurl4-openssl-dev
sudo aptitude install libxml2-dev
apt-get install openjdk-7-*
R CMD javareconf -e
@soodoku
soodoku / prop_weights.R
Created May 31, 2015 22:52
Weighting datasets by propensity scores (~YouGov Method for Sampling)
"
Weighting by Propensity Scores
Last Edited: 5/31/2015
Task Outline:
1. Two datasets:
dataset 1: large pop. representative sample
dataset 2: convenient sample
2. Create weights for dataset 2 so that its marginals are close to dataset 1 on some vars.
@soodoku
soodoku / text_classifier.R
Last active December 15, 2016 17:44
Basic Text Classifier
"
Basic Text Classifier
- Takes a csv with a text column, and column of labels
- Splits into train and test
- Preprocesses text using tm/bag-of-words, 1/2-order Markov
- Uses SVM and Lasso
@author: Gaurav Sood
"
@soodoku
soodoku / salvage_csv.py
Last active August 29, 2015 14:20
Salvage Corrupted CSV
'''
What does it do?
Goes through a corrupted csv sequentially and outputs rows that are clean.
Also outputs, total n, total corrupted n
@author: Gaurav Sood
Run: python salvage_csv.py input_csv output_csv
'''