Skip to content

Instantly share code, notes, and snippets.

View tylerpearson's full-sized avatar

Tyler Pearson tylerpearson

View GitHub Profile
@tylerpearson
tylerpearson / twitter_bio_word_analyzer.rb
Last active August 29, 2015 14:12
A Ruby script to find the most commonly used words in the bios of accounts a user follows on Twitter
require 'twitter'
# change this to your own info to get the script to work
# get it from https://apps.twitter.com/
client = Twitter::REST::Client.new do |config|
config.consumer_key = "XXX"
config.consumer_secret = "XXX"
config.access_token = "XXX"
config.access_token_secret = "XXX"
@tylerpearson
tylerpearson / nyt.txt
Last active August 29, 2015 14:12
most common words in the Twitter bios of New York Times staff (downcased, with most punctuation stripped and stop words removed)
new: 514
times: 497
york: 483
editor: 264
reporter: 138
@nytimes: 101
author: 83
correspondent: 71
bureau: 60
nyt: 60
@tylerpearson
tylerpearson / pass_with_subjects.rb
Last active August 29, 2015 14:20
Calculate the percentage of sponsored bills passed (as primary and cosponsor) for each delegate with a breakdown of bill subjects. These results are for WV House during the 2011 session, but the script should be able to be modified to be used with any JSON dump from the Sunlight Foundation Open States API.
require 'httparty'
require 'json'
require 'pp'
require 'uri'
require 'hashie'
def load_json(filename)
Hashie::Mash.new(JSON.parse(IO.read(filename)))
end
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
console.log("Starting scraping");
var allResults = [];
for (var chapter=1; chapter <= 168; chapter++) {
@tylerpearson
tylerpearson / unicorn.rb
Created June 1, 2015 23:14
Unicorn + Octopus on Heroku
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 4)
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
@tylerpearson
tylerpearson / parse_dump_downloader.rb
Last active August 29, 2015 14:22
Ruby Capybara script to trigger a dump of Parse data. For example, this could be used nightly to get a backup.
require 'cgi'
require 'timeout'
require 'capybara'
class ParseDownloader
include Capybara::DSL
def initialize(email, password, app_name)
Capybara.default_driver = :selenium
@email = email
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1='\[\033[34;40m\]\W \[\033[0;33m\]$(parse_git_branch)\[\e[0m\] $ '
@tylerpearson
tylerpearson / results.json
Created July 27, 2015 22:14
Calculate the percentage of sponsored bills passed (as primary and cosponsor) for each delegate with a breakdown of bill subjects. These results are for WV House during the 2011 session, but the script should be able to be modified to be used with any JSON dump from the Sunlight Foundation Open States API.
{
"Morgan":{
"total":{
"count":117,
"passed":19,
"subjects":{
"Boards and Commissions":17,
"Licenses":9,
"Health (And Related Subheadings)":6,
"Governmental Agencies":6,
@tylerpearson
tylerpearson / import_maxmind_csv.sql
Created August 11, 2015 23:18
SQL import MaxMind GeoIP CSV into MySQL
USE users_info;
CREATE TABLE IF NOT EXISTS `geoips` (
`id` INT(1) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT,
`ipstart` VARCHAR(50) COLLATE UTF8_GENERAL_CI NOT NULL,
`ipend` VARCHAR(50) COLLATE UTF8_GENERAL_CI NOT NULL,
`locid_start` INT(1) UNSIGNED ZEROFILL NOT NULL,
`locid_end` INT(1) UNSIGNED ZEROFILL NOT NULL,
`country_code` VARCHAR(4) COLLATE UTF8_GENERAL_CI NOT NULL,
`country` VARCHAR(100) COLLATE UTF8_GENERAL_CI NOT NULL,
require 'csv'
yc_companies_names = []
def simple_name(name)
name.downcase
end
# mattermark export
CSV.foreach("mattermark.csv") { |row| yc_companies_names << simple_name(row[0]) }