Skip to content

Instantly share code, notes, and snippets.

@zacharydenton
zacharydenton / models.py
Created February 18, 2011 02:27
Geodesic Distance Between Points in GeoDjango
from itertools import tee, izip
from django.contrib.gis.db import models
from django.contrib.gis.measure import Distance
from geopy.distance import distance as geopy_distance
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
@paulgb
paulgb / binom_interval.py
Created September 19, 2013 17:58
Compute two-sided binomial confidence interval in Python. Based on R's binom.test.
from scipy.stats import beta
def binom_interval(success, total, confint=0.95):
quantile = (1 - confint) / 2.
lower = beta.ppf(quantile, success, total - success + 1)
upper = beta.ppf(1 - quantile, success + 1, total - success)
return (lower, upper)