Skip to content

Instantly share code, notes, and snippets.

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")
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?
class DeepFinder
attr_reader :accum
def initialize(h, key)
@accum = []
@h = h
@key = key
dig @h
end
# 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
require 'uri'
require 'net/http'
require 'base64'
require 'openssl'
require 'json'
class GoogGeocoder
PATH = "/maps/api/geocode/json?sensor=false"
@ashaw
ashaw / calculateDeath.js
Last active December 16, 2015 13:08
How we're calculating death in our HeartSaver experimental news game.
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/
require 'sinatra'
require 'sanitize'
TO_REMOVE = ["", " ", "&nbsp;"]
get '/' do
<<-HTML
<form method="post" action="sanitize">
<textarea name="dirty" style="width:100%;height:800px;"></textarea>
<input type="submit" value="Submit">
propublica.views.stickyNav = propublica.View.extend({
cssClass : "sticky_nav",
render : function() {
_.bindAll(this, "stick");
this.jWindow = $(window);
this.jFooter = $("footer");
this.offsetTop = this.el.offset().top;
this.elHeight = this.el.height();
this.jWindow.scroll(this.stick);
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);
<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();