Skip to content

Instantly share code, notes, and snippets.

@soodoku
soodoku / fun.md
Last active October 30, 2017 18:01
Fun Math

Fun Math

Fun Fact 1

  • 1 - 1 + 1 - 1 + 1 - 1 + .... = 1/2
  • Proof (1) by Luigi Grandi:

S = 1 - 1 + 1 - 1 + 1 - 1 + ...
1 - S = 1 - (1 - 1 + 1 - 1 + 1 - 1 + ...)
= 1 - 1 + 1 - 1 + 1 - 1 + ...

@soodoku
soodoku / approval.csv
Created October 28, 2017 21:42
Approval Data on Few Politicians
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 38 columns, instead of 4. in line 5.
Last,First,N,Mode,Date Start,Date End,TotApp,TotDis,TotDK,DemApp,DemDis,DemDK,RepApp,RepDis,RepDK,IndApp,IndDis,IndDK,LibApp,LibDis,LibDK,ModApp,ModDis,ModDK,ConApp,ConDis,ConDK,Source,Link,,,,,,,,,
Bachmann,Michelle,928,Phone,07/15/11,07/17/11,29,45,26,16,58,26,45,27,28,28,47,24,15,64,21,17,53,30,50,24,26,PPP,http://www.publicpolicypolling.com/pdf/2011/PPP_Release_National_720925.pdf,,,,,,,,,
Bachmann,Michelle,700,Phone,10/07/11,10/10/11,27,56,17,15,68,17,43,36,21,23,64,13,11,77,12,14,62,23,49,34,17,PPP,http://www.publicpolicypolling.com/pdf/2011/PPP_Release_US_1011513.pdf,,,,,,,,,
Bachmann,Michelle,700,Phone,12/16/11,12/18/11,30,54,16,22,65,13,41,39,19,26,59,16,21,71,8,20,67,12,42,34,23,PPP,http://www.publicpolicypolling.com/pdf/2011/PPP_Release_National_1220925.pdf,,,,,,,,,
Bloomberg,Michael,707,Phone,11/19/10,11/21/10,19,38,44,24,30,46,12,48,40,19,37,44,28,29,43,24,28,48,9,53,39,PPP,http://publicpolicypolling.blogspot.com/2010/11/americans-not-impressed-with-bloomberg.html,,,,,,,,,
Bloomberg,Michael,700,P
devtools::install_github("abresler/gdeltr2")
devtools::install_github("hafen/trelliscopejs")
library(gdeltr2)
library(dplyr)
asb_ocr <- "Brooklyn Nets"
gkg_codes <-
get_codes_gkg_themes()
imageweb_codes <- get_gdelt_codebook_ft_api(code_book = "imageweb")
@soodoku
soodoku / rent control
Last active October 18, 2016 01:46
Rent Control
# Read the data
sf <- read.csv("sf_tenants.csv")
# Recode
sf$market_rates <- gsub("%", "", sapply(strsplit(sf$market_rate, " / "), "[", 2)) # market_rate
sf$rent_control_rates <- gsub("%", "", sapply(strsplit(sf$rent_control, " / "), "[", 2)) # market_rate
# Ratio of rent_control vs. rent_control
sf$ratio <- as.numeric(sf$rent_control_rates)/as.numeric(sf$market_rates)
@soodoku
soodoku / Liberal Regex Pattern for All URLs
Created July 11, 2016 02:21 — forked from gruber/Liberal Regex Pattern for All URLs
Liberal, Accurate Regex Pattern for Matching All URLs
The regex patterns in this gist are intended to match any URLs,
including "mailto:foo@example.com", "x-whatever://foo", etc. For a
pattern that attempts only to match web URLs (http, https), see:
https://gist.github.com/gruber/8891611
# Single-line version of pattern:
(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
@soodoku
soodoku / missing.R
Last active April 22, 2016 11:53
plotting missing
# Load libs
library(ggplot2)
# Simulate correlated data
R = matrix(cbind(1,.80, .80,1), nrow=2)
U = t(chol(R))
@soodoku
soodoku / state_various.csv
Last active April 12, 2016 22:31
US State name, 2 letter code, Alphabetical number, Census Region, ICPSR, ICPSR 2
state code num census icpsr icpsr2
Alabama AL 1 South 41 41 AL ALABAMA
Alaska AK 2 West 81 81 AK ALASKA
Arizona AZ 3 West 61 61 AZ ARIZONA
Arkansas AR 4 South 42 42 AR ARKANSAS
California CA 5 West 71 71 CA CALIFORNIA
Colorado CO 6 West 62 62 CO COLORADO
Connecticut CT 7 Northeast 1 01 CT CONNECTICUT
Delaware DE 8 South 11 11 DE DELAWARE
District of Columbia DC 9 Northeast 55 55 DC DISTRICT OF COLUMBIA
@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
@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
@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