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
if (!FileReader.prototype.readAsArrayBuffer) { | |
FileReader.prototype.readAsArrayBuffer = function readAsArrayBuffer () { | |
this.readAsBinaryString.apply(this, arguments); | |
this.__defineGetter__('resultString', this.__lookupGetter__('result')); | |
Object.defineProperty(this, 'result', { | |
get : function () { | |
var string = this.resultString, | |
result = new Uint8Array(string.length); | |
for (var i = 0; i < string.length; i++) { | |
result[i] = string.charCodeAt(i); |
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 DataView = (function(){ | |
var littleEndian = ( | |
(new Uint16Array((new Uint8Array([0x12, 0x34])).buffer)[0] === 0x3412) | |
?true:false); //Determine native endianness | |
function dv(buffer){ | |
this.buffer = buffer; | |
this.bytes = new Uint8Array(buffer); | |
} |
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
Matrix = (function(){ | |
function id(){return this;} | |
function _set(idx,src){this[idx]=src;} | |
function _get(idx){return this[idx];} | |
Array.prototype.subarray = function(start,end){ | |
var j,row = {}; | |
for(j=0;start<end;j++,start++){ | |
Object.defineProperty(row,j,{ | |
set:_set.bind(this,start), |
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 emit_string(obj,data,encoding){ | |
obj.emit('data',(data instanceof Buffer | |
?data.toString(encoding) | |
:data[0]) | |
); | |
} | |
function emit_buffer(obj,data){ | |
obj.emit('data',(data instanceof Buffer | |
?data:new Buffer(data[0],data[1])) |
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
/* | |
* No sentinel results in reading the entire stream until it ends, a | |
* numeric sentinel reads fixed length chunks, and a string sentinel | |
* reads chunks bounded by the sentinel string | |
*/ | |
exports.accumulate = function(stream,opts,callback){ | |
stream.pause(); | |
if(!callback){ | |
callback = opts; | |
opts = {encoding:'utf8'}; |
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
/* | |
http://www.whatwg.org/specs/web-apps/current-work/webvtt.html | |
*/ | |
function parseWebVTT(input){ | |
"use strict"; | |
var line,l,p,cue_list=[], | |
cue,cue_text,id,fields, | |
time_pat = /\s*(\d*:?[0-5]\d:[0-5]\d\.\d\d\d)\s*-->\s*(\d*:?[0-5]\d:[0-5]\d\.\d\d\d)\s*(.*)/; | |
//If the first character is a BYTE ORDER MARK (BOM) character, advance position to the next character in input. |
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
Audio = (function(){ | |
return { | |
sampleRate:44100, | |
channelCount:1, | |
WriteAudio:function(soundData){ | |
new Audio( 'data:audio/wav;base64,'+btoa( | |
audioLib.PCMData.encode({ | |
data: soundData, | |
sampleRate: this.sampleRate, | |
channelCount: this.channelCount, |
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
/** | |
* precise version of Date.now() - | |
* It provide submillisecond precision based on window.performance.now() when | |
* available, fall back on Date.now() | |
* see http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision | |
*/ | |
var nowSubms = (function(){ | |
var p = window.performance || {}; | |
if( p.now ) return function(){ return p.timing.navigationStart + p.now(); }; | |
else if( p.mozNow ) return function(){ return p.timing.navigationStart + p.mozNow(); }; |
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
/* Looping version */ | |
function fib(n){ | |
var fk = 0, fkp = 1, | |
f2k, f2kp, b; | |
for(b = Math.floor(Math.log(n)/Math.LN2); b > 0; b--){ | |
f2k = fk*(2*fkp-fk); | |
f2kp = fkp*fkp+fk*fk; | |
if(n&(1<<b)){ | |
fk = f2kp; |
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 Earley = (function(){ | |
function Grammar(rules) { | |
this.symbols = {}; | |
rules.forEach(function(rule) { | |
// "A -> B C | D" -> ["A ", " B C | D"] | |
var parts = rule.split('->'); | |
var lhs = parts[0].trim(); | |
var rhss = parts[1].trim(); | |
// "B C | D" -> ["B C", "D"] |
OlderNewer