This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def euclidean_distance(p, q): | |
""" Calculate distance between 2 points in n-dimensional space | |
>>> euclidean_distance((3, 0), (0, 4)) | |
5.0 | |
""" | |
n = len(p) # dimensions | |
return sum([(p[i] - q[i]) ** 2 for i in xrange(n)]) ** 0.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {list} data List of integers sorted ascending | |
* @param {int} find Integer to search for | |
* @param {int} start Min array index | |
* @param {int} end Max array index | |
* @return {int} Index of 'find' or -1 if not found | |
*/ | |
var binarySearch = function (data, find, start, end) { | |
var mid = start + (end - start) / 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create a google map and populate it with markers and infoboxes | |
* | |
* @requires underscore.js @link http://documentcloud.github.com/underscore/ | |
* @param options {object} Override default settings | |
* @return {object} this | |
*/ | |
var MapPopulator = function (options) { | |
var defaults = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Requires jQuery Rotate Plugin - http://wilq32.googlepages.com/wilq32.rollimage222 | |
$(function() | |
{ | |
var angle; | |
function begin_rotation(override_angle) | |
{ | |
// Generate random number between 15 and 35 for rotation distance | |
amount = Math.floor(Math.random()*36); | |
while(amount < 15) | |
{ |