Skip to content

Instantly share code, notes, and snippets.

View thejefflarson's full-sized avatar
👨‍👩‍👧‍👦
being a dad

Jeff Larson thejefflarson

👨‍👩‍👧‍👦
being a dad
View GitHub Profile
class TweetClassifier
GOOD = %w[superior quality excellent superb outstanding magnificent
great exceptional marvelous wonderful awesome]
BAD = %w[inferior shoddy careless miserable horrible
incompetent awful atrocious terrible pathetic crappy]
FACETS = %w[article story piece column]
SEARCH = "http://search.twitter.com/search.json"
// First things first, add our special CSRF token to every jQuery Ajax
// request.
$(document).ajaxSend(function(e, xhr, options) {
var token = $("meta[name='csrf-token']").attr("content");
xhr.setRequestHeader("X-CSRF-Token", token);
});
@brianboyer
brianboyer / import_usat
Created February 16, 2011 16:50
PostgreSQL importer for the pre-processed census files provided to IRE members by Paul Overberg and Anthony DeBarros from USA Today.
#! /bin/sh
#
# usat_import
# Created by Ryan Nagle, Chris Groskopf and Brian Boyer
#
# PostgreSQL importer for the pre-processed census files provided to IRE
# members by Paul Overberg and Anthony DeBarros from USA Today.
#
# To get the source files, join IRE (it's cheap!):
# http://www.ire.org/getcensus/
require 'rubygems'
require 'pp'
unless self.class.const_defined? "IRB_RC_HAS_LOADED"
# Log to STDOUT if in Rails
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')
require 'logger'
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
end
def import(stat, &blk)
puts "trying #{stat}"
begin
block_given? ? blk.call : Object.const_get(stat).import(@date)
rescue GatticaError => exception
puts "*** got a GA error: #{exception} ***"
sleep 10
retry
end
end
.infinite_frowns {
color: #660000;
background: #FFEEEE;
}
.infinite_smiles {
color: #000;
background: #CCFFCC;
}
@sstephenson
sstephenson / back_forward.js
Created December 13, 2010 21:55
How to detect whether a hash change came from the Back or Forward button
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
module ProPublica
class GoogleComparer
BASE_URL = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="
WEB_TITLE_DELIMITERS = /(-|\|).*$/
def initialize(facility_name)
@facility_name = facility_name
url_encoded_facility_name = CGI.escape(@facility_name)
@results = JSON.parse(RestClient.get(BASE_URL + url_encoded_facility_name))['responseData']['results']
end
ALNUM = /[a-z0-9]/i
PUNCT = /[^a-z0-9\s]/i
REPEAT = /(.)\1{2,}/
UPPER = /[A-Z]/
LOWER = /[a-z]/
ACRONYM = /^[A-Z]+('?s|[.,])?$/
ALL_ALPHA = /^[a-z]+$/i
CONSONANT = /[bcdfghjklmnpqrstvwxz]/i
VOWEL = /[aeiouy]/i
CONSONANT_5 = /[bcdfghjklmnpqrstvwxz]{5}/i
var ArrayProto = Array.prototype
, ObjProto = Object.prototype
;
// Array Tests
["forEach", "map", "reduce", "reduceRight", "filter", "every", "some",
"indexOf", "lastIndexOf"].forEach(function(key){
var d = document.createElement("div");
d.textContent = key + ": " + ArrayProto[key];
document.body.appendChild(d);
});