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
import beamcoder from 'beamcoder'; | |
import { Readable, Writable } from 'stream'; | |
async function * transform(demuxer: beamcoder.Demuxer) { | |
const vdec = beamcoder.decoder({ name: 'h264' }); | |
const adec = beamcoder.decoder({ name: 'aac' }); | |
const venc = beamcoder.encoder({ name: 'h264' }); | |
const aenc = beamcoder.encoder({ name: 'aac' }); |
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
const clauses = new Symbol(); | |
function Multimethod(){ | |
const self = !!new.target ? this : Object.create(Multimethod.prototype); | |
self[clauses] = []; | |
return new Proxy(self,{ | |
apply: function(target, thisArg, args){ | |
let curImpl = () => throw new Error("No Matching Implementation"); | |
let curLen = -1; | |
for(const { thisPredicate, predicates, impl } of self[clauses]){ |
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 TM(tape, alphabet, states, start){ | |
var state, transition, symbol, | |
counter = 0, stateId = start, pos = 0; | |
while(true){ | |
symbol = tape[pos]; | |
if(typeof symbol === 'undefined'){ | |
symbol = alphabet[0]; | |
tape[pos] = symbol; | |
} | |
state = states[stateId]; |
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"] |
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
/** | |
* 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
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
/* | |
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
/* | |
* 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
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])) |
NewerOlder