Skip to content

Instantly share code, notes, and snippets.

@carlzulauf
carlzulauf / haversine.sql
Created February 2, 2012 16:47
PostgreSQL function for haversine distance calculation, in miles
-- Haversine Formula based geodistance in miles (constant is diameter of Earth in miles)
-- Based on a similar PostgreSQL function found here: https://gist.github.com/831833
-- Updated to use distance formulas found here: http://www.codecodex.com/wiki/Calculate_distance_between_two_points_on_a_globe
CREATE OR REPLACE FUNCTION public.geodistance(alat double precision, alng double precision, blat double precision, blng double precision)
RETURNS double precision AS
$BODY$
SELECT asin(
sqrt(
sin(radians($3-$1)/2)^2 +
sin(radians($4-$2)/2)^2 *
@dmpatierno
dmpatierno / doodleapi.php
Created July 8, 2011 01:26
Creates a new poll with the Doodle API
<?php
$api = new DoodleAPI();
$api->createPoll(array(
'title' => 'Test Poll',
'description' => 'Test Description',
'fromName' => 'David Patierno',
'fromEmail' => '[email protected]',
'dates' => array(
@mmacia
mmacia / test_undefined_offset_exception.php
Created July 5, 2011 10:31
How to catch an invalid array index offset as a native exception in PHP
<?php
/**
* this class shows how to override default PHP handler to catch undefined index errors
* and throw it as native exceptions, much more convenient way to work with object
* oriented programs.
*
* @author Moisés Maciá <[email protected]>
* @see http://codeup.net
*/