Skip to content

Instantly share code, notes, and snippets.

View gregzanch's full-sized avatar

Greg Zanchelli gregzanch

View GitHub Profile
@gregzanch
gregzanch / beam.js
Created January 25, 2021 17:32
Wave equation solution for a beam
const { sqrt, sin, cos, sinh, cosh, tanh, sign, round, PI, abs } = Math;
const pi = PI;
/** Solves the wave equation for a beam
*
* @param {number} N Number of modes
* @param {number} L Length
* @param {number} W Width
* @param {number} H Height
* @param {number} M Mass
@gregzanch
gregzanch / index.html
Created January 22, 2021 23:41
Read a text file in javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<input type="file" id="fileinput"></input>
@gregzanch
gregzanch / test.js
Created September 18, 2020 19:19
test
console.log(window);
console.log(this);
console.log(globalThis);
console.log([
[
"Object",
"Function",
"Array",
"Number",
"parseFloat",
@gregzanch
gregzanch / array-ops.js
Created September 18, 2020 17:57
some array operations
const diff = (A,B) => [A,B].map((x,i,a)=>x.filter(y=>!a[(i+1)%2].includes(y)));
const unique = (A,B) => [...new Set([...A, ...B])];
@gregzanch
gregzanch / stock.json
Last active September 18, 2020 17:50
stock properties and methods on globalThis in various browsers
[
"Object",
"Function",
"Array",
"Number",
"parseFloat",
"parseInt",
"Infinity",
"NaN",
"undefined",
@gregzanch
gregzanch / at.js
Created January 22, 2020 03:17
Get an object property via a path like string
const obj = {
name: "obj",
userData: {
position: {
x: 3,
y: 4,
z: 10
}
}
@gregzanch
gregzanch / literal-glsl.ts
Created December 21, 2019 03:33
Concatenation of an es6 template literal with arguments.
/**
* This is a tagged template function for using inline glsl in javascript.
* Also helpful for inline html, css, etc.
*
* @param x this is the template literal split up by the arguments
* @param args the arguments passed in ${like.this}
* @returns {string} the joined string
*
* @example
* const frag = glsl`
@gregzanch
gregzanch / convert-base.ts
Created November 12, 2019 06:38
Base Conversion
function base_10_to_base_n(v: number,b: number,r:number[]=[]): number[]{
if(b==0) return;
if (Math.floor(v) != v || Math.floor(b) != b) return;
const div = Math.floor(v / b);
const rem = v - div * b
r.push(rem);
return div == 0 ? r.reverse() : base_10_to_base_n(div, b, r);
}
function base_n_to_base_10(val: number[], base: number) {
if (base == 0) return;