Skip to content

Instantly share code, notes, and snippets.

View queviva's full-sized avatar

queviva

View GitHub Profile
@queviva
queviva / cryptoFloats.js
Last active October 10, 2024 21:49
random floats from zero-to-one using crypto.getRandomValues()
const crandomVal = () => (crypto.getRandomValues(new Uint32Array(1))[0] / (2 ** 32)) ;
const crandomInt = (a=1) => ~~((crypto.getRandomValues(new Uint32Array(1))[0] / (2 ** 32)) * a);
const crandomArr = (a=1, b=1) => [...crypto.getRandomValues(new Uint32Array(a))].map(v => (v / 2**32) * b);
const crandomIntArr = (a=1, b=1) => [...crypto.getRandomValues(new Uint32Array(a))].map(v => ~~((v / 2**32) * b));
@queviva
queviva / sortGoodBad.js
Last active December 7, 2023 22:35
splits up an array into two arrays, one that matches and one that does not match
const sortGoodBad = (r, f = x => Number(x)) => r.reduce(
(a, v) => (a[(f(v)) ? 0 : 1].push(v), a), [[], []]
);
@queviva
queviva / werkers.html
Last active February 1, 2024 23:38
inline web werkers without external scripts
...
<style> werk-er { display: none; } </style>
...
<werk-er id="zero">
const f = new class {
constructor () { ... }
meth0 (x,y,z) { ... }
meth1 (x,y,z) { ... }
}();
onmessage = (e, [a, ...b] = [...e.data]) => f[a](b);