Skip to content

Instantly share code, notes, and snippets.

View dirtyvagabond's full-sized avatar

Aaron Crow dirtyvagabond

  • Los Angeles, CA
View GitHub Profile
@dirtyvagabond
dirtyvagabond / gist:1143156
Created August 12, 2011 22:42
An OK Clojure simple API example
;
; Required dependencies:
; [org.clojure/clojure-contrib "1.2.0"]
; [com.google.api.client/google-api-client "1.4.1-beta"]
; [com.google.guava/guava "r09"]
;
(ns funnyplaces.core
(:import (com.google.api.client.auth.oauth OAuthHmacSigner OAuthParameters))
(:import (com.google.api.client.http GenericUrl HttpRequest HttpRequestFactory HttpResponse HttpTransport))
(:import (com.google.api.client.http.javanet NetHttpTransport))
(fetch :places :q “coloft”)
[{:name "Coloft",
:address "920 Santa Monica Blvd"
:latitude 34.020433,
:longitude -118.490092,
:postcode "90401",
:factual_id "f8458ec1-3b63-48aa-82a1-6a06970d1235",
:locality "Santa Monica",
:region "CA",
(crosswalk :factual_id "f8458ec1-3b63-48aa-82a1-6a06970d1235")
[{:factual_id "f8458ec1-3b63-48aa-82a1-6a06970d1235",
:namespace "facebook",
:namespace_id "218169018973",
:url "http://www.facebook.com/theCoLoft"}
{:factual_id "f8458ec1-3b63-48aa-82a1-6a06970d1235",
:namespace "foursquare",
:namespace_id "1283109",
:url "https://foursquare.com/venue/1283109"}
{
"version":"3.0",
"response":
{
"included_rows":2,
"total_row_count":2,
"data":[
{
"factual_id":"39599c9b-8943-4c15-999d-c03f6c587881",
"last_name":"John",
{
"version":"3.0",
"response":
{
"included_rows":2,
"total_row_count":2,
"data":[
{
"factual_id":"39599c9b-8943-4c15-999d-c03f6c587881",
"last_name":"John",
(ns datastore-api-server.conf
"Configuration utility."
(:use [clojure.tools.logging :only (info debug error)])
(:use [fs.core :only (exists?)]))
(def DEFAULT-CONF-FILES ["server-conf.clj" "resources/server-conf.clj"])
(defn load-when
"If path exists, returns the data structure represented in the
file at path. Otherwise returns nil."
@dirtyvagabond
dirtyvagabond / gist:1772763
Created February 8, 2012 19:45
conf_ex.clj
When app starts up:
...
(conf/add-file! some-conf-file))
...
Some other ns in app, needs some conf:
...
(defn redis-host []
((conf/conf) :redis-host))
(defn slurp-cp [f]
(let [loader (java.net.URLClassLoader. (into-array [(jio/as-url (fs/file f))]))]
(slurp (jio/resource f loader))))
@dirtyvagabond
dirtyvagabond / tabwc.clj
Created July 12, 2012 00:55
Quick and dirty tabwc per Clojure Class assignment
;;
;; project.clj
;;
(defproject tabwc "0.0.0-SNAPSHOT"
:description "A Clojure Class Assignment! CLI util to validate a TAB file, or do a wc."
:main tabwc.core
:dependencies [[org.clojure/clojure "1.4.0"]])
;; Example 1: a step that uses Crosswalk to add Fatual IDs
crosswalked.tab <- uncrossed.tab [c4]
;; For all lines where there's no factual_id,
;; pull out values from the columns named "foursquare" and "yelp"
(:>! factual_id [foursquare yelp]
;; Put into the factual_id column (creating if necessary)...
(+= "factual_id"
;; The result from Crosswalking foursquare, if there's a hit...
(or (:factual_id (first (select crosswalk
(where