Skip to content

Instantly share code, notes, and snippets.

View dkincaid's full-sized avatar

Dave Kincaid dkincaid

View GitHub Profile
@dkincaid
dkincaid / gist:3277518
Created August 6, 2012 18:52
Mutable state test
@Test
public void changeNameTest() {
MutableClass original_name = new MutableClass("my name");
MutableClass expected_name = original_name;
NameFilter filter = new NameFilter();
MutableClass new_name = filter.changeName(original_name,
"new name");
assertEquals(new_name, expected_name);
@dkincaid
dkincaid / queries.clj
Created July 13, 2012 01:13
Cascalog sales transaction summary
(ns transaction.queries
(:use [cascalog.api])
(:require [cascalog.ops :as c]
[cascalog.tap :as tap]
[cascalog.workflow :as w])
(:import [com.google.common.hash Hashing]
[org.joda.time.format DateTimeFormat]
[cascading.scheme.hadoop TextDelimited])
(:gen-class))
(defn standard-tokenizer [text]
"Uses the Lucene StandardTokenizer to tokenize the given text. Returns a vector containing
the tokens."
(let [analyzer (StandardAnalyzer. Version/LUCENE_31)
tokenstream (.tokenStream analyzer "field" (StringReader. text))
termatt (.addAttribute tokenstream TermAttribute)
terms []]
(while (.incrementToken tokenstream)
(print (.term termatt)))))
@dkincaid
dkincaid / getcode.R
Created November 14, 2011 21:17
Geocode function for R using Infochimps
geocode = function(location) {
library(RJSONIO)
api.uri = "http://api.infochimps.com/"
geocode.uri = "geo/utils/geolocate?"
api.key = "apikey=xxxxxxxxxxxx"
print(location)
uri = paste(api.uri, geocode.uri, api.key, "&f.address_text=", location, sep="")
raw.data = readLines(uri, warn="F")
results = fromJSON(raw.data)
@dkincaid
dkincaid / infochimps_geo.R
Created September 10, 2011 15:30
Pulling ACS data from Infochimps Geo API in R
library(RJSONIO)
library(ggplot2)
api.uri <- "http://api.infochimps.com/"
acs.topline <- "social/demographics/us_census/topline/search?"
api.key <- "apikey=xxxxxxxxxx" # replace the x's with your Infochimps API key
radius <- 10000 # in meters
lat <- 44.768202
long <- -91.491603