Skip to content

Instantly share code, notes, and snippets.

View dulichan's full-sized avatar

Dulitha Wijewantha (Chan) dulichan

View GitHub Profile
@dulichan
dulichan / PosPrinter.java
Created December 2, 2012 02:17
COM port printer writing java example
package app.posmachine.machine;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
import javax.comm.SerialPort;
public class PosPrinter {
@dulichan
dulichan / test1.java
Created December 5, 2012 08:59
Code of layout issue - StackOverflow
package org.dchan.context;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@dulichan
dulichan / gist:10661092
Created April 14, 2014 16:01
A Google Script for spreadsheets to covert a selection of cells to mins:secs
function sensible_time() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getActiveRange().getValues();
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < data[i].length; j++) {
if (data[i][j]) {
var range = sheet.getRange(24+i, j+1);
time = data[i][j];
var mins = ~~(time / 60);
var secs = time % 60;
@dulichan
dulichan / deployer.sh
Created January 23, 2014 05:35
Script to configure WSO2 EMM
PRODUCT_HOME="$1"
IOS_CERTS="$2"
IP="$3"
PRODUCT_CONF="$4"
CONFIG_FILE="./openssl_custom.cnf"
TEMP_FOLDER="./temp"
PUSH_CERT="`echo $IOS_CERTS`pushcert.pfx"
PUSH_PASS=""
MDM_CERT="`echo $IOS_CERTS`PlainCert.pfx"
MDM_PASS=""
@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;