Skip to content

Instantly share code, notes, and snippets.

View arm5077's full-sized avatar
😊

Andrew McGill arm5077

😊
View GitHub Profile
@arm5077
arm5077 / analyze.r
Last active April 24, 2017 17:48
Pulls the top five percent of U.S. medical spenders and calculates proportions of race.
library(Hmisc)
library(survey)
# Import data from SAS transport file
data <- sasxport.get('data/h171.ssp')
# Build survey object using person weights
full_population_survey <- svydesign(ids=~1, data=data, weights=~perwt14f)
# Find cutoff for top 5 percent of spenders
@arm5077
arm5077 / index.js
Created November 22, 2016 13:50
A script for the Raspberry Pi that turns on a Powerswitch when the user says "Lumos!"
const record = require('node-record-lpcm16');
const {Detector, Models} = require('./node_modules/snowboy/');
const Gpio = require('onoff').Gpio;
// Set up control of the pin that toggles the Powerswitch
power = new Gpio(14, 'out');
var on = false;
// Turn the power off by default
power.writeSync(0);
@arm5077
arm5077 / data.csv
Created March 24, 2016 02:34
De-industrialization-based model for Donald Trump in Ohio and Michigan
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 January 15, 2016 16:58
Example of delegate tracker JSON
[
{
"name": "Hillary Clinton",
"party": "D",
"bound": 954,
"unbound": 122,
"states": [
{
"state": "PA",
"bound": 40,
@arm5077
arm5077 / peduto_scraper.php
Last active January 3, 2016 23:28
Segment of PHP script that scrapes Pittsburgh Mayor Bill Peduto's daily schedule.
<?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 January 3, 2016 01:59
Snippet from Tomlin ngram project.
<?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 December 10, 2015 21:30
Candidate tracker
// 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 December 2, 2015 23:11
Color palette for Poseidon
<!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 October 19, 2015 22:56
Finds donors who have contributed to multiple 2016 campaigns.
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 August 29, 2015 14:22
Scrapes Clinton Benghazi emails from the State Department's open records website
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