Skip to content

Instantly share code, notes, and snippets.

View kig's full-sized avatar

Ilmari Heikkinen kig

View GitHub Profile
#!/usr/bin/ruby
USAGE = "dataurize filename [mimetype] > filename.dataURI"
require 'base64'
mime = ARGV[1] || `file -ib '#{ARGV[0].gsub(/'/, "'\\\\''")}'`.strip
STDOUT.write("data:#{mime};base64,")
File.open(ARGV[0], 'rb') {|f|
STDOUT.write(Base64.encode64(f.read(4500))) until f.eof?
@kig
kig / gzip.js
Last active August 1, 2019 08:59
TarGZ = function(){};
// Load and parse archive, calls onload after loading all files.
TarGZ.load = function(url, onload, onstream, onerror) {
var o = new TarGZ();
o.onload = onload;
o.onerror = onerror;
o.onstream = onstream;
o.load(url);
return o;
BlenderExport.tmpVec = vec4.create();
BlenderExport.tmpNo = vec4.create();
BlenderExport.rv = vec3.create();
BlenderExport.nrv = vec3.create();
BlenderExport.v = vec4.create();
BlenderExport.n = vec4.create();
BlenderExport.setFrame = function(frame) {
if (!this.frameVertices)
this.frameVertices = new Float32Array(this.vertices);
5-year-period histogram of the top 100 sci-fi books
based on http://home.austarnet.com.au/petersykes/topscifi/lists_books_rank1.html
1800-1804:
1805-1809:
1810-1814:
1815-1819: #
1820-1824:
1825-1829:
1830-1834:
@kig
kig / gist:781535
Created January 16, 2011 03:41
Filesystem prefetch init.d script
#!/bin/bash
### BEGIN INIT INFO
# Provides: usr-prefetch
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Prefetch system files to page cache.
# Description: Prefetches files under /opt, /usr and /etc, and the FS entries for /.
### END INIT INFO
DrawHistorySerializer = Klass({
magic: 'SRBL',
majorVersion: 0,
minorVersion: 0,
getVersionTag : function() {
return [this.magic, this.majorVersion, this.minorVersion, ''].join(",")
},
serialize : function(history) {
@kig
kig / gist:856848
Created March 6, 2011 00:09
WebGLExport.py Blender WebGL exporter fork
#!BPY
"""
Name: 'WebGL JavaScript (.js)'
Blender: 249
Group: 'Export'
Tooltip: 'WebGL JavaScript'
"""
# --------------------------------------------------------------------------
@kig
kig / gist:856850
Created March 6, 2011 00:10
Blender WebGL exporter JS import script thing
BlenderExport.splitByMaterial = function(matIndexes, verts, sz) {
var matVerts = [];
for (var i=0; i<matIndexes.length; i++) {
var idx = matIndexes[i];
if (matVerts[idx] == null) {
matVerts[idx] = [];
}
for (var j=0; j<sz; j++) {
matVerts[idx].push(verts[i*sz + j]);
// Prototyping a test harness autogen
// Here's a run against Array.prototype
Test_Array = {
run_tests : function() {
for (var i in this) {
if (/^test_/.test(i)) {
var __obj = new Array(args);
this[i](__obj);
}
@kig
kig / gist:900687
Created April 3, 2011 19:14
Scribbling some generic array mixin madness
/*
Object.extend(Float32Array.prototype, ArrayMixin);
var vecf32 = function(arg){ return new Float32Array(arg); };
var a = vecf32([1,2,3,4,5,6]);
// (1,2,3,4,5,6)
a.filter(function(v) { return v>3; });
// (4,5,6)
a.reverse();
// (6,5,4,3,2,1)
a.replaceSlice(1,-1, vecf32([100, 200]));