Skip to content

Instantly share code, notes, and snippets.

View queviva's full-sized avatar

queviva

View GitHub Profile
@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);
@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 / cryptoFloats.js
Last active July 9, 2022 23:32
random floats from zero-to-one using crypto.getRandomValues()
const crandomValue = () => [...crypto.getRandomValues(new Uint32Array(1))].map(v => v / 4294967296.5)[0];
const crandomArray = (n=1) => [...crypto.getRandomValues(new Uint32Array(n))].map(v => v / 4294967296.5);
@queviva
queviva / sliceArrayOnCondition.js
Created February 10, 2022 23:21
slices an array based either on the condition of an element, or just uniformly by quantity
const sliceArrayOnCondition=(a,f)=>a.reduce((x,v,i)=>((isNaN(f)?f(v):i%f===0)&&i!==0?x.push([v]):x.at(-1).push(v),x),[[]]);
@queviva
queviva / monthNames.js
Last active December 15, 2023 19:38
list of month names
const // create a var ...
months // called months ...
= // that is equal to ...
[...Array(12)] // a twelve element array ...
.map( // that gets mapped using ...
@queviva
queviva / zeroPad.js
Created February 3, 2022 18:16
front pads number with zero
('00000' + n).slice(-3)
@queviva
queviva / cssVars.js
Last active February 4, 2022 07:44
create list of all css variables
// run after all styles load
const cssVars = {
list : () => [...new Set([...[
[...document.styleSheets]
.map(s => [...s.cssRules]
.map(r => r.cssText)),
[...document.querySelectorAll('[style]')]
@queviva
queviva / Liz.js
Created February 1, 2022 09:24
add|remove the same listener for multiple events
const Liz = {
lizzers: [
[obj, 'event', e=>{...}],
[obj, 'event,event,...', e=>{...}],
[obj, 'event,event,...', e=>{...},{ passive: true }]
],
@queviva
queviva / toNumArray.js
Last active February 5, 2022 21:18
converts a string into an array of numbers
const toNumArray = s => s.match(/[\d\.-]+/g).map(p=>Number(p));
@queviva
queviva / xModByM.js
Last active January 31, 2022 22:37
returns a value of x, cyclically-modulated by M
const xModByM = (x, M) => ((x % M) + M) % M;