Skip to content

Instantly share code, notes, and snippets.

View goofballLogic's full-sized avatar
👔
Still counting things

Andrew Stewart Gibson goofballLogic

👔
Still counting things
  • 09:04 (UTC +01:00)
View GitHub Profile
@goofballLogic
goofballLogic / cassidoo_aug_10_2026.js
Created August 10, 2026 12:15
cassidoo_aug_10_2026
const strategies = {
"leading": xs => xs.replace(/^ */, ""),
"trailing": xs => xs.replace(/ *$/, ""),
"compress": xs => xs.replaceAll(/ +/g, " ")
};
const missing => strategy =>
throw new Error(`Unknown trim type: ${strategy}`);
const trim = (strategy, xs) =>
const flatEnumerate = listOfLists =>
listOfLists.flatMap((list, listIndex) =>
list.map(x =>
[x, listIndex]));
const fulfilledOrdersBeforeFailure = (orders, { ...stock} = {}) => {
for(let [o, i] of flatEnumerate(orders)) {
if (!stock[o]) return i;
stock[o] -= 1;
const countBlinks = xs => xs
.split("_")
.slice(1, -1)
.map(x => x.length)
.reduce((a, b) => Math.max(a, b), 0)
;
@goofballLogic
goofballLogic / cassidoo_jun_29_2006.js
Last active June 29, 2026 12:26
not entirely sure i got the math spot on, and I'm fairly sure I can do this with a logarithm if I thought hard enough but...
function meanBits(n) {
let bits = 1, counted = 0, sum = 0;
while(counted < n) {
const depth = Math.pow(2, Math.max(1, bits - 1));
const count = Math.min(n - counted, depth);
sum += count * bits;
counted += count;
bits++;
}
// note that the routine would break for much of the unicode range
const latinWithPunctuation = /^[a-zA-Z\s.,\/#!$%\^&\*;:{}=\-_`~()?"'’\-]*$/;
const toggleCharCode = cc =>
(cc >= 97 && cc <= 122)
? cc - 32
: (cc >= 65 && cc <= 90)
? cc + 32
: cc;
const validatePizza = (layers, rules) =>
rules.find(([a, b]) => layers.indexOf(a) > layers.indexOf(b)) || true;
function resolvePath(fs, path) {
if (!(path in fs)) return null;
const { [path]: nextPath, ...others } = fs;
return nextPath ? resolvePath(others, nextPath) : path;
}
const resolvePath = (fs, path, ...visited) =>
visited.includes(path)
? null
: fs[path]
? resolvePath(fs, fs[path], path, ...visited)
: path
;
const swap = (xs, n, i) =>
xs.fill(
xs.splice(i+1, 1, n)[0],
i,
i+1
)
;
const chase = (xs, n, i) =>
i === xs.length - 1
// thanks: https://stackoverflow.com/a/16353241
const isLeapYear = year =>
(
// divisible by 4 but not 100
(year % 4 == 0) && (year % 100 != 0)
) || (
// divisible by 400
year % 400 == 0
);