Skip to content

Instantly share code, notes, and snippets.

Avatar
😊

Andrew McGill arm5077

😊
View GitHub Profile
@arm5077
arm5077 / data.csv
Created Mar 24, 2016
De-industrialization-based model for Donald Trump in Ohio and Michigan
View data.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 52 columns, instead of 31. in line 1.
area_fips,state,name,clinton_raw,sanders_raw,clinton_percent,sanders_percent,bush_raw,carson_raw,christie_raw,cruz_raw,fiorina_raw,huckabee_raw,kasich_raw,rubio_raw,santorum_raw,trump_raw,bush_percentage,carson_percentage,christie_percentage,cruz_percentage,fiorina_percentage,huckabee_percentage,kasich_percentage,rubio_percentage,santorum_percentage,trump_percentage,1975_raw_manufacturing,1975_percent_manufacturing,1975_raw_total,1993_raw_manufacturing,1993_percent_manufacturing,1993_raw_total,2007_raw_manufacturing,2007_percent_manufacturing,2007_raw_total,2014_raw_manufacturing,2014_percent_manufacturing,2014_raw_total,1975_to_1993_manufacturing,1975_to_1993_total,1993_to_2007_manufacturing,1993_to_2007_total,2007_to_2014_manufacturing,2007_to_2014_total,1975_to_2014_manufacturing,1975_to_2014_total,gini,gini_adjusted,college_or_higher,poverty_level,percent_white_alone
26001,Michigan,ALCONA,463,455,48.74,47.89,13,27,5,460,4,2,340,138,4,1111,0.61,1.26,0.23,21.47,0.19,0.09,15.87,6.44,0.19,51.84,94,17.06,551,2
@arm5077
arm5077 / candidate_example.json
Created Jan 15, 2016
Example of delegate tracker JSON
View candidate_example.json
[
{
"name": "Hillary Clinton",
"party": "D",
"bound": 954,
"unbound": 122,
"states": [
{
"state": "PA",
"bound": 40,
@arm5077
arm5077 / peduto_scraper.php
Last active Jan 3, 2016
Segment of PHP script that scrapes Pittsburgh Mayor Bill Peduto's daily schedule.
View peduto_scraper.php
<?PHP
$scheduleArray = explode( "<p><strong>", $schedule );
for( $j = 0; $j < count( $scheduleArray ); $j++ ) {
$scheduleArray[$j] = strip_tags( $scheduleArray[$j] );
$scheduleArray[$j] = trim( str_replace( "&nbsp;", "", $scheduleArray[$j] ) );
//parse split press release into export array
$start = 0;
if( $scheduleArray[$j] != "" ) {
$tempArray = "";
@arm5077
arm5077 / ngram.php
Last active Jan 3, 2016
Snippet from Tomlin ngram project.
View ngram.php
<?PHP
// For this example, $ngram = 1, meaning we're only looking at one word at a time and not phrases
$textArray = explode( " ", $formatted ); // $formatted is the text sample with most punctuation removed
for ( $i = 0; $i < count( $textArray ) - $ngram; $i++ ) {
$chunk = "";
for ( $j = 0; $j < $ngram; $j++ ) {
@arm5077
arm5077 / app.js
Last active Dec 10, 2015
Candidate tracker
View app.js
// thenBy.js, sorting library
/*** Copyright 2013 Teun Duynstee Licensed under the Apache License, Version 2.0 ***/
var firstBy=function(){function n(n,t){if("function"!=typeof n){var r=n;n=function(n){return n[r]}}if(1===n.length){var u=n;n=function(n,t){return u(n)<u(t)?-1:u(n)>u(t)?1:0}}return-1===t?function(t,r){return-n(t,r)}:n}function t(t,u){return t=n(t,u),t.thenBy=r,t}function r(r,u){var f=this;return r=n(r,u),t(function(n,t){return f(n,t)||r(n,t)})}return t}();
var limit = 3; // Number of places to display
// Get data from endpoint
d3.json("http://traveltracker.nationaljournal.com/api/widget", function(err, data){
// Sort by date and number of trips
@arm5077
arm5077 / index.html
Last active Dec 2, 2015
Color palette for Poseidon
View index.html
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
<script src="swatches.json"></script>
<script type="text/javascript">
angular.module("swatchApp", [])
.controller('swatchController', ['$scope', function($scope){
$scope.colors = swatches;
$scope.height = window.innerHeight / swatches.length;
@arm5077
arm5077 / compare_candidates.sql
Last active Oct 19, 2015
Finds donors who have contributed to multiple 2016 campaigns.
View compare_candidates.sql
ALTER TABLE contributions_individual ADD COLUMN contbr_nm_short varchar(200);
UPDATE contributions_individual set contbr_nm_short = SUBSTRING_INDEX(contributions_individual.contbr_nm, ' ', 2);
SELECT contributions_individual.cand_nm,
contributions_individual.contbr_nm_short,
contributions_individual.contbr_zip,
SUM(contributions_individual.contb_receipt_amt) as total,
b.cand_nm,
b.contbr_nm_short,
@arm5077
arm5077 / index.js
Last active Aug 29, 2015
Scrapes Clinton Benghazi emails from the State Department's open records website
View index.js
var fs = require("fs");
var http = require('http');
fs.readFile("data.json", 'utf8', function(err, data){
data = JSON.parse(data);
data.Results.forEach(function(email, i){
console.log("http://foia.state.gov/searchapp/"+email.pdfLink);
// use a timeout so State's server doesn't get mad
@arm5077
arm5077 / scripts.js
Last active Aug 29, 2015
nstein js changes
View scripts.js
$(window).load(function(){
$(".magWYSIWYG h1").css("font-size", "20pt");
});
@arm5077
arm5077 / index.html
Created Feb 23, 2015
Converts a copy-and-pasted table of emails into readable text.
View index.html
<!doctype html>
<html ng-app="formatApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"></script>
<style type="text/css">
body {
font-family: Helvetica, sans-serif;