Skip to content

Instantly share code, notes, and snippets.

View kig's full-sized avatar

Ilmari Heikkinen kig

View GitHub Profile
@kig
kig / eventmon.js
Created August 20, 2013 04:02
Log all events to an element
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 August 13, 2013 11:07
ChangeList library to do OT on JSON and Strings.
var ChangeList = {};
if (typeof module !== 'undefined') {
module.exports = ChangeList;
}
// Creates a new change list struct.
//
ChangeList.create = function(type) {
var type = type || ChangeList.Object;
@kig
kig / my_bucket_put
Created February 4, 2013 17:26
A script to upload files to an S3 bucket. Sets mime type headers for HTML, CSS, JS, JPEG, GIF and PNG. Sets a thirty-year Expires header for images. Gzips HTML, CSS and JS.
#!/usr/bin/ruby
# USAGE: my_bucket_put FILE_1 [FILE_N...]
# Uploads $local_path_for_bucket/FILE_1 to my_bucket/FILE_1
# This script has very little configuration to keep it simple (and serve my limited needs).
# Create a pre-configured copy of this for all your buckets. Or add command line flags.
#
# Change this to your bucket name
bucketname = "my_bucket"
@kig
kig / test.js
Created June 12, 2012 19:47
DataStream testing
var embed = [
'tag', 'uint32be',
'code', 'uint32le',
'greet', 'cstring'
];
var def = [
'tag', 'cstring:4',
'code', 'uint32le',
'embed', embed,
'length', 'uint16be',
@kig
kig / gist:2898047
Created June 8, 2012 20:44
Chrome ASM instructions sorted by count (/Developer/usr/bin/otool -tV Google\ Chrome\ Framework > ~/chrome.S)
4988782 movl
918146 calll
668426 leal
513400 popl
445392 pushl
438901 addl
435478 je
405022 cmpl
349294 testl
312041 jmp
@kig
kig / ABStruct.js
Created May 22, 2012 21:29
ArrayBuffer struct overlay
ABStruct = {};
ABStruct.create = function(def) {
var f = function(dataView) {
this.dataView = dataView;
};
f.prototype = {};
var idx = [0];
for (var i in def) {
Object.defineProperty(f.prototype, i, ABStruct.getter(def[i], idx));
}
http://fhtr.org/structdef.js/shp.html
http://github.com/kig/structdef.js/
var xyDef = {x: 'float64le', y: 'float64le'};
var polyDef = {
minX: 'float64le',
minY: 'float64le',
maxX: 'float64le',
maxY: 'float64le',
partCount: 'int32le',
@kig
kig / struct.js
Created May 18, 2012 10:26
ArrayBuffer struct reader & writer
/**
Struct definition object:
var myStruct = {
'width': 'uint32',
'height': 'uint32',
'channels': 'uint8',
'bias': 'float32',
'name': 'cstring',
'thumbnail': {
@kig
kig / arrayToNative.js
Created May 18, 2012 09:35
Change Typed Array endianness
ArrayBuffer.littleEndian = new Int8Array(new Int16Array([1]).buffer)[0] > 0;
var arrayToNative = function(array, arrayIsLittleEndian) {
if (!!arrayIsLittleEndian == ArrayBuffer.littleEndian) {
return array;
} else {
return flipArrayEndianness(array);
}
};
@kig
kig / app.yaml
Created April 30, 2012 10:58
App Engine static website
application: website-12345
version: 1
runtime: python
api_version: 1
#default_expiration: "30d"
handlers:
- url: /