Skip to content

Instantly share code, notes, and snippets.

View EchoZhaoH's full-sized avatar
📸
🤔

Echo EchoZhaoH

📸
🤔
View GitHub Profile
@EchoZhaoH
EchoZhaoH / douglasPeucker.js
Created January 5, 2023 01:31 — forked from adammiller/douglasPeucker.js
Javascript implementation of the Douglas Peucker path simplification algorithm
var simplifyPath = function( points, tolerance ) {
// helper classes
var Vector = function( x, y ) {
this.x = x;
this.y = y;
};
var Line = function( p1, p2 ) {
this.p1 = p1;
@EchoZhaoH
EchoZhaoH / typescript-array-reverse.ts
Last active November 4, 2021 02:13
typescript array ArrayReverse
type ArrayReverse<T extends any[]> = T extends [infer A, ...infer B] ? [...ArrayReverse<B>, A] : T
const rAF = function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
function (cb) {
window.setTimeout(cb, 1000 / 60);
}
}();
let frame = 0
let lastTime = Date.now();
@EchoZhaoH
EchoZhaoH / prm.js
Last active August 18, 2021 09:32
print with matrix
function drawCicle(diameter = 3, placeholder='*') {
diameter = Math.floor(diameter)
diameter = diameter < 3 ? 3 : diameter
const mtx = matrix(diameter)
return translate(mtx, placeholder)
}
function matrix(len) {
const m = len
const n = len
@EchoZhaoH
EchoZhaoH / hear-dom.js
Created August 13, 2021 09:45 — forked from zerobias/hear-dom.js
Hear DOM changes with WebAudio API
/*
Copy this into the console of any web page that is interactive and doesn't
do hard reloads. You will hear your DOM changes as different pitches of
audio.
I have found this interesting for debugging, but also fun to hear web pages
render like UIs do in movies.
*/
const audioCtx = new (window.AudioContext || window.webkitAudioContext)()
const observer = new MutationObserver(function(mutationsList) {