Skip to content

Instantly share code, notes, and snippets.

View dulichan's full-sized avatar

Dulitha Wijewantha (Chan) dulichan

View GitHub Profile
@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++) {
@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 / 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);
"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 / 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);
@dulichan
dulichan / If.js
Created January 29, 2016 15:32
If— BY RUDYARD KIPLING (in JS)
var you = {};
var others = [];
// If you can keep your head when all about you
// Are losing theirs and blaming it on you,
if (keepYourHead(you)){
looseTheirHead(others);
blame(you);
}
// If you can trust yourself when all men doubt you,
// But make allowance for their doubting too;
@dulichan
dulichan / finance.js
Last active November 10, 2015 12:13
Personal Finance microservice to write CSV data to Google Sheet
module['exports'] = function echoHttp (hook) {
var body = hook.params; // This gives all the JSON body parameters in an object.
//Using a small security measure ;)
if(body.secret != "dgfdg45345jf0248234234"){
hook.res.end("Unauthorized");
return;
}
var https = require('https'),
@dulichan
dulichan / _resource_mismatch_handler_.xml
Created September 16, 2015 11:37
Returning 404 response for WSO2 ESB instead of 202
<!-- Exact sequence name as below should be there. This name is used inside the API implementation in Synapse -->
<sequence xmlns="http://ws.apache.org/ns/synapse" name="_resource_mismatch_handler_">
<log level="full"/>
<property name="HTTP_SC" value="404" scope="axis2"></property>
<respond/>
<drop></drop>
</sequence>
<div class="header">
<h1>Jaggery intro</h1>
<ul ng-repeat="todo in todos">
<li><input type="checkbox" ng-model="todo.status"> <span ng-model="todo.text">{{todo.text}}</span></li>
</ul>
</div>
@dulichan
dulichan / LocalizationManagerUtil.java
Created December 19, 2014 01:28
Proposal idea for a localization manager
/*
The objective of this class is to manage localization options in CDM.
2 types Use cases:-
1) Localize the product based on a configuration
2) Localize components based on user preference.
Use case 2:- Localize the license file
*/