Skip to content

Instantly share code, notes, and snippets.

View dcj's full-sized avatar

Don Jackson dcj

View GitHub Profile
@fxn
fxn / post.md
Created May 23, 2011 21:08
GeoPlanet data with ancestor chain cache imported in 10 minutes

GeoPlanet data with ancestor chain cache imported in 10 minutes

Yahoo! provides its GeoPlanet data as three separate TSV files, available for download here.

That's a database with some 17 million records:

  • 5.7 million records: locations (aka places).
  • 2.2 million records: alternative names for each place (aka aliases).
  • 9.6 million records: matrix of neighbourhoods per place (aka adjacencies).
@ordnungswidrig
ordnungswidrig / reify_generic.clj
Created June 8, 2011 14:06
Reify a protocol by giving a generic implementation function that will be called for all protocol methods. Like a proxy.
(ns reify-generic
"reify a protocol such that every method is delegated to a specified method")
(defmacro reify-generic
"Reify the given protocols. Every method of any protocol is implemented such
that f is called as (apply f protocol-method args)
Example:
(defprotocol Calculator
@rowan-m
rowan-m / gist:1026918
Created June 15, 2011 11:34 — forked from jedi4ever/gist:898114
update jenkins Updatecenter from CLI
$ java -jar jenkins-cli.jar -s http://localhost:9000 install-plugin findbugs
findbugs is neither a valid file, URL, nor a plugin artifact name in the update center
No update center data is retrieved yet from: http://updates.jenkins-ci.org/update-center.json
findbugs looks like a short plugin name. Did you mean 'null'?
# Specifying a full URL works!
$ java -jar jenkins-cli.jar -s http://localhost:9020 install-plugin http://updates.jenkins-ci.org/download/plugins/AdaptivePlugin/0.1/AdaptivePlugin.hpi
# Get the update center ourself
@sivajag
sivajag / gist:1046688
Created June 25, 2011 17:30
core.clj
(defproject address_book "1.0.0-SNAPSHOT"
:description "Address Book"
:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/clojure-contrib "1.2.0"]
[compojure "0.6.2"]
[ring/ring-core "0.3.7"]
[ring/ring-jetty-adapter "0.2.3"]]
:dev-dependencies [[swank-clojure "1.2.1"]]
:main address-book.core)
@twbell
twbell / factual_local_mappings.json
Created June 29, 2011 21:56
Provides a machine-readable mapping between Factual's Global Local Schema and country-specific attributes, denotes which attributes are supported within a specific country, and provides a country-to-table lookup
{
"countries": {
"ar": {
"country": "Argentina",
"table": "PfldJg",
"attributes": {
"factual_id": {
"supported": true,
"mapping": "Factual ID"
},
anonymous
anonymous / simplegeo-context-neighborhoods-by-city.py
Created July 5, 2011 22:54
Find all neighborhoods in a given city, by address
>>> import simplegeo
>>> from itertools import ifilter
>>> client = simplegeo.context.Client('your-key','your-secret')
>>> location = client.get_context_by_address("41 Decatur St, San Francisco, CA")
# Find the bounding box of your current city
>>> sf = next(ifilter(lambda feature: feature['classifiers'][0]['category'] == 'Administrative', location['features']), None)
>>> hoods = client.get_features_from_bbox(sf['bounds'], features__category='Neighborhood')
@pamelafox
pamelafox / usermodel.py
Created July 6, 2011 21:08
SimpleGeo Timezone Calculation on Python App Engine
class User(db.Model):
location = db.StringProperty()
timezone = db.StringProperty(default='America/Los_Angeles')
# Do this once per user
def calculate_timezone(self):
from simplegeo import Client
client = Client('oauth key', 'oauth secret SHH')
response = client.context.get_context_by_address(self.location)
for feature in response['features']:
@twbell
twbell / factual_local_maketables.sql
Created July 11, 2011 15:55
Unofficial (read: quick, dirty, and largely unverified) Create Table SQL for Factual local tables
CREATE TABLE `ar` (
`factual_id` VARCHAR(36) NOT NULL COMMENT 'Factual ID',
`name` VARCHAR(255) DEFAULT NULL COMMENT 'Name',
`address` VARCHAR(255) DEFAULT NULL COMMENT 'Address',
`locality` VARCHAR(255) DEFAULT NULL COMMENT 'City',
`region` VARCHAR(255) DEFAULT NULL COMMENT 'Province',
`postcode` VARCHAR(255) DEFAULT NULL COMMENT 'Postcode',
`tel` VARCHAR(255) DEFAULT NULL COMMENT 'Telephone',
`fax` VARCHAR(255) DEFAULT NULL COMMENT 'Fax',
`category` VARCHAR(255) DEFAULT NULL COMMENT 'Category',
@ryancrum
ryancrum / jquerytest.cljs
Created July 21, 2011 02:24
How to use jQuery from ClojureScript
(ns jquerytest.core)
(def jquery (js* "$"))
(jquery
(fn []
(-> (jquery "div.meat")
(.html "This is a test.")
(.append "<div>Look here!</div>"))))
@adeel
adeel / push-notifications.clj
Created July 26, 2011 01:03
Example of sending Apple push notifications with Clojure.
; Depends on [com.notnoop.apns/apns "0.1.6"].
(:import ('com.notnoop.apns APNS))
(defn send-push-notification [device-token message]
(let [service (.build (.withSandboxDestination
(.withCert (APNS/newService) "resources/apns-dev-cert.p12" "password")))
payload (.build (.alertBody (APNS/newPayload) message))]
(.push service device-token payload)))