This file contains 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
Array.prototype.binarySearch = function binarySearch(find, comparator, insert) { | |
if (!comparator) { | |
comparator = function(a,b) { | |
return ((a == b) ? 0 : ((a < b) ? -1 : 1)); }; | |
} | |
var low = 0; | |
var high = this.length - 1; | |
var i, comparison; | |
while (low <= high) { | |
i = parseInt((low + high) / 2, 10); |
This file contains 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
(function() { | |
var s = "prefix arg1\narg2", | |
expected_capture = "arg1\narg2", | |
regexps = [ | |
/prefix\s+(.*)$/, // base | |
/prefix\s+(.*)$/m, /prefix\s+(.*)$/g, /prefix\s+(.*)$/mg, | |
/prefix\s([\s\S]*)$/, // base | |
/prefix\s([\s\S]*)$/m, /prefix\s([\s\S]*)$/g, /prefix\s([\s\S]*)$/mg | |
]; |
This file contains 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
Prototype.CrossFrame = function() { | |
// Common functionality | |
var url_src_matcher = /^(https?:\/\/.+)\??.*/, | |
url_name_matcher = /\W/g, | |
urlForLocation = function(l) { return l.match(url_src_matcher)[1]; }, | |
nameForUrl = function(url) { return url.replace(url_name_matcher, '-'); }; | |
// Parent-specific closure locals | |
var url_map = {}, sentinel_created = false, | |
createSentinel = function(url) { |
This file contains 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
var EventDispatcher = (function() { | |
var api = { | |
addEventListener: function(event, callback) { | |
initialize(this); | |
if (!this.eventListeners[event]) | |
this.eventListeners[event] = []; | |
this.eventListeners[event].push(callback); | |
}, | |
dispatchEvent: function(event) { | |
initialize(this); |
This file contains 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
# Usage | |
# projection = MapProjection::WinkelTripel.new(w, h) | |
# projections.project( latitude, longitude) | |
# => [ x, y ] # cartesian coordinates | |
# Where x and y will be between 0, 0 (upper-left) and w, h (lower-right) | |
# suitable for compositing images on a bitmap | |
module Math | |
DEG2RAD = PI / 180 | |
This file contains 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
#!/usr/bin/ruby | |
require 'stringio' | |
class HangMarkus | |
attr_reader :solutions | |
FILL_IN_CHARACTERS = (32..176).map { |k| k.chr } - [ '_' ] | |
def sub_puzzles p | |
0 == p.count('_') ? | |
p : FILL_IN_CHARACTERS.map { |c| sub_puzzles(p.sub('_', c)) } |
This file contains 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
var spectrum = []; | |
var signal = []; | |
var peak = []; | |
var bufferSize = 2048; | |
var calculateDFT = function(buffer, sampleRate) { | |
var complexValues = []; | |
for ( var k = 0; k < buffer.length/2; k ++ ) { |
This file contains 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
function hex2rgb(hex) { | |
var c, o = [], k = 0, m = hex.match( | |
/^#(([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})|([0-9a-f])([0-9a-f])([0-9a-f]))$/i); | |
if (!m) return {r:0,g:0,b:0}; | |
for (var i = 2, s = m.length; i < s; i++) { | |
if (undefined === m[i]) continue; | |
c = parseInt(m[i], 16); | |
o[k++] = c + (i > 4 ? c * 16 : 0); | |
} |
This file contains 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
Compare = function(fn1, fn2, i) { | |
var time = function(fn) { | |
var now = new Date(); | |
fn(); | |
return new Date() - now; | |
}, | |
spinOn = function(fn, i) { | |
return function() { for (var ii = i;ii;ii--) fn(); } | |
}, | |
fn1_time = time(spinOn(fn1, i)), |