This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_date(d) | |
d.strip.gsub(/[^\d\/]/,"") =~ /(^[\d]{1,2}\/[\d]{1,2}\/[\d]{2}$)/ | |
if $1 | |
m, d, y = $1.split("/") | |
if y.to_i <= 13 | |
y = "20#{y}" | |
else | |
y = "19#{y}" | |
end | |
Date.strptime("#{m}/#{d}/#{y}", "%m/%d/%Y") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :transcribable do | |
desc "Harvest documents to transcribe from DocumentCloud" | |
task :harvest_kmiz => :environment do | |
require 'rest-client' | |
klass = Kernel.const_get(Transcribable.table.classify) | |
result = JSON.parse(RestClient.get("http://www.documentcloud.org/api/search?q=contributedto%3Afreethefiles+station%3AKMIZ")) | |
result['documents'].each do |doc| | |
obj = klass.find_or_initialize_by_url("https://www.documentcloud.org/documents/#{doc['id']}") | |
# don't plow over verified docs if rerunning the script | |
obj.verified = false if obj.new_record? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DeepFinder | |
attr_reader :accum | |
def initialize(h, key) | |
@accum = [] | |
@h = h | |
@key = key | |
dig @h | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://rcbth.com/p/getting-an-oauth-token-for-your-twitter-bot | |
require 'rubygems' | |
require 'twitter_oauth' | |
client = TwitterOAuth::Client.new( | |
:consumer_key => 'BUH', | |
:consumer_secret => 'BUH' | |
) | |
request_token = client.request_token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'net/http' | |
require 'base64' | |
require 'openssl' | |
require 'json' | |
class GoogGeocoder | |
PATH = "/maps/api/geocode/json?sensor=false" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var calculateDeath = function(hospital, pickupTime, travelTime) { | |
var survivalChance = 1; | |
// A victim’s chance of survival decreases by 7 to 10 percent / minute | |
// that passes without defibrillation. | |
// http://www.heart.org/idc/groups/heart-public/@wcm/@ecc/documents/downloadable/ucm_438703.pdf | |
survivalChance -= (0.10 * pickupTime); | |
// Time in transit to ER (.58% / minute, via the Google Directions API) | |
// http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2464671/table/tbl1/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'sanitize' | |
TO_REMOVE = ["", " ", " "] | |
get '/' do | |
<<-HTML | |
<form method="post" action="sanitize"> | |
<textarea name="dirty" style="width:100%;height:800px;"></textarea> | |
<input type="submit" value="Submit"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lookup = { | |
"2001_v1" : 188914, | |
"2001_v2" : 193305 | |
} | |
$(function() { | |
$("#censo, #vars").change(function() { | |
var year = $("#censo option:selected").val(); | |
var version = $("#vars option:selected").val(); | |
var map_id = lookup[year + "_" + version]; | |
console.log(map_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.8.1.min.js"></script> | |
<script> | |
$(document).ready(function() { | |
$("#submit").click(function() { | |
var username = $("#username").val(); |