Skip to content

Instantly share code, notes, and snippets.

Ilmari Heikkinen kig

Block or report user

Report or block kig

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kig
kig / mic.js
Created Oct 6, 2018
Microphone input to MP3
View mic.js
// Uses getUserMedia to record audio from microphone, compresses it to mp3, and throws it away.
// You should change the last step to e.g. pushing the audio to a server over a WebSocket.
// This script uses lame.js for mp3 encoding
// https://github.com/zhuker/lamejs
var audioDataCallback = function(encodedData, originalData) {
console.log("Encoded " + encodedData.byteLength + " bytes. Original: " + originalData.byteLength);
};
View deltaPack.js
var pngCompress = function(buffer) {
var canvas = document.createElement('canvas');
canvas.width = Math.min(Math.ceil((buffer.byteLength+6) / 3), 16384);
canvas.height = Math.ceil((buffer.byteLength+6) / (3*canvas.width));
var ctx = canvas.getContext('2d');
var id = ctx.getImageData(0, 0, canvas.width, canvas.height);
var u32 = new Uint32Array(1);
var u8 = new Uint8Array(u32.buffer);
u32[0] = buffer.byteLength;
var src = new Uint8Array(buffer);
@kig
kig / jsdecode.html
Created Nov 6, 2015
Buggy feature-free JavaScript QR decoder
View jsdecode.html
<html>
<body>
<script>
var QRDecoder = function(imageData) {
this.imageData = imageData;
this.imageBits = new Int8Array(QRDecoder.MAX_SIZE * QRDecoder.MAX_SIZE);
this.decodedBits = new Uint8Array( (QRDecoder.MAX_SIZE * QRDecoder.MAX_SIZE) >> 3 );
this.size = -1;
this.ecc = -1;
@kig
kig / sky.frag
Created Dec 28, 2013
sky shader
View sky.frag
vec3 lightPos_ = vec3(
-cos(iGlobalTime*0.1)*-8.5,
3.5+sin(iGlobalTime*0.05)*3.0,
-(sin(iGlobalTime*0.1)*4.0-5.4)
);
vec3 bgLight = normalize(lightPos_);
vec3 lightPos = bgLight * 9999.0;
vec3 sun = vec3(5.0, 3.5, 2.0)*4.0;
@kig
kig / scplayer.css
Last active Jan 1, 2016
Small SoundCloud player widget
View scplayer.css
#music {
opacity: 0;
transition: 1s;
position: absolute;
left: 10px;
bottom: 10px;
color: white;
height: 46px;
width: 300px;
}
@kig
kig / print.styl
Created Oct 1, 2013
Stylus print stylesheet for Message presos (https://message.fhtr.net)
View print.styl
/*
Released under the MIT License.
*/
@media print
@page
margin 0
padding 0
body
@kig
kig / index.html
Last active Dec 22, 2015
Super-powerful two-way DOM model binding.
View index.html
<html>
<body>
<h1 contenteditable id="title"></h1>
<input id="edit">
<script src="model.js"></script>
<script>
var m = new Model();
m.sync('greeting', document.getElementById('edit'), 'value');
m.sync('greeting', document.getElementById('title'), 'innerText');
@kig
kig / some_kind_of_diff.js
Created Aug 26, 2013
A bad string difference algo.
View some_kind_of_diff.js
var diff = function(beforeStr, afterStr) {
var i,j,prefixLen=0;
var before = beforeStr ? beforeStr.split(/ /) : [];
var after = afterStr ? afterStr.split(/ /) : [];
var arr = [];
for (i=0, j=0; i<before.length && j<after.length; i++, j++) {
if (before[i] === after[j]) {
prefixLen++;
} else {
if (prefixLen) {
@kig
kig / eventmon.js
Created Aug 20, 2013
Log all events to an element
View eventmon.js
var logEvents = function(el) {
Object.getOwnPropertyNames(el).join(" ").match(/\bon\S+/g).forEach(function(n){el[n]=function(e){console.log(e.type,e)}});
}
@kig
kig / changelist.js
Created Aug 13, 2013
ChangeList library to do OT on JSON and Strings.
View changelist.js
var ChangeList = {};
if (typeof module !== 'undefined') {
module.exports = ChangeList;
}
// Creates a new change list struct.
//
ChangeList.create = function(type) {
var type = type || ChangeList.Object;
You can’t perform that action at this time.