Skip to content

Instantly share code, notes, and snippets.

View zz85's full-sized avatar

Joshua Koo zz85

View GitHub Profile
@zz85
zz85 / README
Last active March 21, 2018 22:55
Audio Experiements
Idea: use web rtc/ web audio to record a short audio clip, do pitch changing on it
Links
- http://recordrtc.org/
- https://github.com/danielstorey/WebAudioTrack
- https://www.webrtc-experiment.com/msr/audio-recorder.html
@zz85
zz85 / GPUComputationRenderer.js
Last active January 20, 2020 14:37
Faster Pixel Sort
/**
* @author yomboprime https://github.com/yomboprime
*
* GPUComputationRenderer, based on SimulationRenderer by zz85
*
* The GPUComputationRenderer uses the concept of variables. These variables are RGBA float textures that hold 4 floats
* for each compute element (texel)
*
* Each variable has a fragment shader that defines the computation made to obtain the variable in question.
* You can use as many variables you need, and make dependencies so you can use textures of other variables in the shader
@zz85
zz85 / DragControls.js
Last active October 22, 2021 13:05
Spline / Path Bend Modifier for Three.js
/*
* @author zz85 / https://github.com/zz85
* @author mrdoob / http://mrdoob.com
* Running this will allow you to drag three.js objects around the screen.
*/
THREE.DragControls = function ( _objects, _camera, _domElement ) {
if ( _objects instanceof THREE.Camera ) {
@zz85
zz85 / greenlet.js
Last active June 17, 2019 20:52
Greenlet.js Annotated
// This is @zz85's attempt to understand and annotate the greenlet.js lib
// from https://github.com/developit/greenlet/blob/master/greenlet.js
/** Move an async function into its own thread.
* @param {Function} fn The (async) function to run in a Worker.
*/
export default function greenlet(fn) { // greenlet takes in a function as argument
let w = new Worker( // creates a web worker
URL.createObjectURL( // that has a local url
new Blob([ // created from a blob that has the following content
@zz85
zz85 / flame_sunburst.html
Created September 28, 2017 11:21
Flamegraphs + Donuts Sunburst Charts
<html>
<body>
<script>
class File {
constructor(name, size) {
this.name = name;
this.size = size;
}
}
@zz85
zz85 / draw.js
Created September 27, 2017 20:59
minimal dom
function draw(path, current) {
const navs = [
elm('h5', { class: 'nav-group-title' }, `${path.join('/')} ${format(current.value)}`, {
onclick: () => State.navigateTo(path.slice(0, -1))
})
]
// let str = '----------\n'
const nodes = current._children || current.children || []
@zz85
zz85 / counter.js
Last active August 23, 2017 04:26
Simple Counter
class Counter {
constructor() {
this.map = new Map();
}
add(key) {
this.map.set(key, this.map.has(key) ? this.map.get(key) + 1 : 1);
}
print() {
@zz85
zz85 / lag.js
Last active August 8, 2017 10:04
Node Event Loop Lag
// Also see https://github.com/tj/node-blocked/blob/master/index.js and https://stackoverflow.com/questions/28563354/how-to-detect-and-measure-event-loop-blocking-in-node-js
const blocked = require('blocked');
blocked(function(ms) {
console.log("Blocked", ms);
}, { threshold: 10 });
var blockDelta = 1;
var interval = 500;
@zz85
zz85 / poc.js
Last active July 11, 2017 17:24
Distributed Consistent Hashing
const { EventEmitter } = require('events');
// const jumphash = require('jumphash');
const _jumphash = require('@ceejbot/jumphash'),
crypto = require('crypto');
function jumphash(key, buckets, algo='md5') {
const buffer = crypto
.createHash(algo)
.update(key)
@zz85
zz85 / Cache.js
Created July 8, 2017 18:38
Generic Cache
class GenericCache {
constructor() {
this.cache = new Map();
}
set(key, promise, options) {
if (typeof promise === 'function') {
promise = promise();
}