Skip to content

Instantly share code, notes, and snippets.

View dulichan's full-sized avatar

Dulitha (Duli) dulichan

View GitHub Profile
@dulichan
dulichan / Life.js
Last active January 29, 2016 16:04
Walk.js
var man = {
"attributes": ["Sadness", "Anger", "Happiness", "Loneliness"]
};
var walk = function(person){
while(true){
console.print("Walk of Life");
}
}
walk(man);
"use strict"
var UniversalTruth = require("./UniversalTruth.js").UniversalTruth;
class EnergyMatter extends UniversalTruth{
constructor(hypothesis){
super(hypothesis)
this.energy = 100; //finite energy
this.matter = 0; //finite mass
this.inverseFlag = true;
}
execution() {
@dulichan
dulichan / recorder.js
Created October 19, 2016 15:13
Recording in the Browser
var audioContext = new (window.AudioContext || window.webkitAudioContext)();
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
// Using arrow functions from ES 6
navigator.getUserMedia({ audio: true }, (stream) => {
// API works in a pipe mechanism
const gain = audioContext.createGain();
const audioSource = audioContext.createMediaStreamSource(stream);
// we connect the gain pipe to the audio source pipe.
var gainNode = audioSource.connect(gain);
@dulichan
dulichan / recorder.js
Last active October 19, 2016 15:22
Recording in the Browser
var audioContext = new (window.AudioContext || window.webkitAudioContext)();
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
// Using arrow functions from ES 6
navigator.getUserMedia({ audio: true }, (stream) => {
// API works in a pipe mechanism
const gain = audioContext.createGain();
const audioSource = audioContext.createMediaStreamSource(stream);
// we connect the gain pipe to the audio source pipe.
var gainNode = audioSource.connect(gain);
@dulichan
dulichan / wav-encoder.js
Created October 19, 2016 15:24
Wav encoding on the browser
function writeUTFBytes(dataview, offset, string) {
for(let i = 0; i < string.length; i++) {
dataview.setUint8(offset + i, string.charCodeAt(i));
}
}
function mergeBuffers(buffer, length) {
const result = new Float32Array(length);
let offset = 0;
for(let i = 0; i < buffer.length; i++) {