Skip to content

Instantly share code, notes, and snippets.

View kig's full-sized avatar

Ilmari Heikkinen kig

View GitHub Profile
@kig
kig / line_server.rs
Created May 9, 2020 17:59
Rust Hyper stdin lines web server
use {
hyper::{
service::{make_service_fn, service_fn},
Body,
Request,
Response,
Server,
},
std::net::SocketAddr,
tokio::io::{BufReader, AsyncBufReadExt},
@kig
kig / workcrew.js
Created September 2, 2011 11:03
WorkCrew - a WebWorker work queue library
/*
WorkCrew - a WebWorker work queue library
Usage:
// Create an 8 worker pool using worker.js.
var crew = new WorkCrew('worker.js', 8);
// Do something whenever a job is completed.
// The result object structure is
struct float4
{
float x;
float y;
float z;
float w;
};
export void runner_main(uniform int work_groups[3], uniform struct inputs& input, uniform struct outputs& output)
{
#define SPIRV_INLINE inline
struct int3
{
int x;
int y;
int z;
};
struct float4
#version 450
#extension GL_ARB_separate_shader_objects : enable
#define WORKER_SIZE 16
#define WORKGROUP_SIZE 4
layout (local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1 ) in;
struct Pixel{
vec4 value;
@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 / 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;
@kig
kig / gist:34506
Created December 10, 2008 22:06
canvas.hs
-- canvas.hs
module Canvas where
import Graphics.UI.Gtk hiding (fill,drawPolygon,lineWidth)
import Graphics.Rendering.Cairo
import Data.Time.Clock.POSIX
import Time
frac = snd . properFraction
modf a b = frac (a / b) * b
@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 / mic.js
Created October 6, 2018 07:25
Microphone input to MP3
// 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);
};