Skip to content

Instantly share code, notes, and snippets.

@cdipaolo
cdipaolo / HaversinFormula.go
Created April 15, 2015 01:31
Golang functions to calculate the distance in meters between long,lat points on Earth.
// haversin(θ) function
func hsin(theta float64) float64 {
return math.Pow(math.Sin(theta/2), 2)
}
// Distance function returns the distance (in meters) between two points of
// a given longitude and latitude relatively accurately (using a spherical
// approximation of the Earth) through the Haversin Distance Formula for
// great arc distance on a sphere with accuracy for small distances
//
@knowtheory
knowtheory / prettyprint.js
Created April 11, 2011 05:44
A pretty printer for Javascript objects that looks like Ruby's pp formatter. In use on Rhino, untested elsewhere.
function pp(object, depth, embedded) {
typeof(depth) == "number" || (depth = 0)
typeof(embedded) == "boolean" || (embedded = false)
var newline = false
var spacer = function(depth) { var spaces = ""; for (var i=0;i<depth;i++) { spaces += " "}; return spaces }
var pretty = ""
if ( typeof(object) == "undefined" ) { pretty += "undefined" }
else if ( typeof(object) == "boolean" ||
typeof(object) == "number" ) { pretty += object.toString() }
else if ( typeof(object) == "string" ) { pretty += "\"" + object + "\"" }