Skip to content

Instantly share code, notes, and snippets.

@joskid
joskid / simplegeo-plancast.py
Created July 29, 2011 23:27 — forked from mager/simplegeo-plancast.py
Parse plancast firehose and import to SimpleGeo Storage
import json, requests, simplegeo
from simplegeo.models import Record
client = simplegeo.Client('your-key', 'your-secret')
firehose = 'http://api.plancast.com/02/plans/firehose.json?extensions=place'
resp = requests.get(url=firehose)
data = json.load(resp)
plans = data['plans']
@joskid
joskid / gist:1121795
Created August 3, 2011 02:44 — forked from jacobian/gist:336445
Installing GeoDjango deps on Ubuntu 9.10
### Install some packages. Ignore the errors.
aptitude install binutils libgdal1-1.5.0 postgresql-8.3-postgis postgresql-server-dev-8.3 python-psycopg2 python-setuptools
### Make connecting to postgres easier
echo "local all all trust" > /etc/postgresql/8.3/main/pg_hba.conf
invoke-rc.d postgresql-8.3 reload
### Become the Postgres user to create a spatial template database:
"""ajaxgoogle.py - Simple bindings to the AJAX Google Search API
(Just the JSON-over-HTTP bit of it, nothing to do with AJAX per se)
http://code.google.com/apis/ajaxsearch/documentation/reference.html#_intro_fonje
brendan o'connor - gist.github.com/28405 - anyall.org"""
try:
import json
except ImportError:
import simplejson as json
import urllib, urllib2
@joskid
joskid / example.hmm
Created November 2, 2011 06:00 — forked from djsutherland/example.hmm
Code for a Hidden Markov Model, along with some sample data / parameters for testing.
4 # number of states
START
COLD
HOT
END
3 # size of vocab
1
2
3
@joskid
joskid / gist:1625131
Created January 17, 2012 06:19 — forked from jamescasbon/template.py
Pure python templates using with statement
"""
A really stupid python template language inspired by coffeekup, markaby.
Do not use this code, it will ruin your day. A byproduct of insomnia.
TL;DR
-----
This module defines a template language that allows us to do:
d = Doc()
@joskid
joskid / gist:1658620
Created January 22, 2012 20:15 — forked from greeness/gist:1420935
tutorial ml codes
@joskid
joskid / perceptron.py
Created January 22, 2012 21:21 — forked from mblondel/perceptron.py
Kernel Perceptron
# Mathieu Blondel, October 2010
import numpy as np
from numpy import linalg
def linear_kernel(x1, x2):
return np.dot(x1, x2)
def polynomial_kernel(x, y, p=3):
return (1 + np.dot(x, y)) ** p
@joskid
joskid / benchmark.m
Created February 13, 2012 17:10 — forked from brusic/benchmark.m
Benchmark code
// define inside file timetest.m
function blank = timetest(x, y, MAX_ITR)
m = length(y);
x = [ones(m, 1) x];
theta = zeros(size(x(1,:)))'; % initialize fitting parameters
alpha = 0.07;
for num_iterations = 1:MAX_ITR
grad = (1/m).* x' * ((x * theta) - y);
theta = theta - alpha .* grad;
@joskid
joskid / jquery.ba-tinypubsub.js
Created February 18, 2012 00:30 — forked from cowboy/HEY-YOU.md
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);
@joskid
joskid / lda_gibbs.py
Created February 29, 2012 15:58 — forked from mblondel/lda_gibbs.py
Latent Dirichlet Allocation with Gibbs sampler
"""
(C) Mathieu Blondel - 2010
Implementation of the collapsed Gibbs sampler for
Latent Dirichlet Allocation, as described in
Finding scientifc topics (Griffiths and Steyvers)
"""
import numpy as np