MetaLens VGC (public/js/lib/stats.js). Win-rate bounds that stay honest on small samples (a 3-0 record reads as 44-100%, not 100%), plus meta diversity as the effective number of species: exp of the Shannon entropy of usage counts.
// Wilson score interval for a binomial proportion k/n, as [lo, hi] fractions.export function wilson(k, n, z = 1.96) { if (n === 0) return [0, 0]; const phat = k / n; const z2 = z * z; const denom = 1 + z2 / n;
One Slot Test for Cross-Filter Chips
JavaScript
MetaLens VGC (public/js/lib/aggregate.js). Positive Pokémon chips are ANDed into a single per-Pokémon test, so "Rillaboom + Life Orb" keeps teams with a Rillaboom holding Life Orb; negative chips drop any team with a match.
/** The slot test built from the positive Pokémon chips, or null if there are none. */function slotTest(chips, dex, { keys = true } = {}) { const pos = chips.filter((c) => !c.neg); const keySet = keys ? new Set(pos.filter((c) => KEY_KINDS.has(c.kind)).flatMap(chipKeys)) : new Set(); const attrs = pos.filter((c) => ATTR_KINDS.has(c.kind)); if (!keySet.size && !attrs.length) return null;
Race-Safe Data Commits in the Weekly Refresh
GitHub Actions
MetaLens VGC (.github/workflows/refresh-data.yml). Commits only public/data, then rebases onto the latest branch tip and pushes, up to 5 attempts with growing back-off, so a long pipeline run never clobbers newer commits.
- name: Commit data if changed id: commit # The pipeline can run for a long time; other commits may land on the branch # meanwhile. Rebase the data commit onto the latest branch tip before pushing # (retrying if the branch moves again). The data commit only touches # public/data, so on a conflict there the freshly built data wins (-X theirs
Exponential Backoff with Full Jitter
TypeScript
Reminder System (server/src/google/backoff.ts). Retry delay for Google API calls: the ceiling doubles per attempt up to a cap, the delay is random below it, and a server Retry-After acts as a lower bound.
Reminder System (server/src/http/csrf.ts). Safe methods pass; anything else must carry a custom header that a cross-site form or simple request cannot send.
/** Methods that never change state and so need no CSRF header. */export const SAFE_METHODS: ReadonlySet<string> = new Set(['GET', 'HEAD', 'OPTIONS']);export const isSafeMethod = (method: string): boolean => SAFE_METHODS.has(method);export const CSRF_MESSAGE = 'Missing X-Requested-With: fetch header';
Next Occurrence of a Recurring Reminder
TypeScript
Reminder System (server/src/services/recurrence.ts). The next due time is computed in the user's wall-clock time so a daily 9am reminder stays 9am across DST, and COUNT is reduced by every occurrence consumed.
/** * Next occurrence strictly after `dueAt` (and after `opts.now`), computed in wall-clock time of `tz` * so a daily 9am reminder stays 9am across DST. Returns null when the series is exhausted. * COUNT is reduced in the returned rule by every occurrence consumed (the completed one plus any skipped), * because the series restarts from the new dueAt. */
Split Text on Paragraph, Sentence, Then Word Boundaries
JavaScript
TL;DR Panel (src/lib/chunking.js). Breaks long page text into chunks under a size limit, preferring the largest natural boundary, then packs the pieces greedily.
/** Split text into pieces no longer than maxChars, preferring paragraph, then sentence, then word boundaries. */export function splitText(text, maxChars) { const limit = Number.isFinite(maxChars) ? Math.max(1, Math.floor(maxChars)) : Number.MAX_SAFE_INTEGER; const units = []; for (const para of String(text).split(/\n{2,}/)) { const p = para.trim();
Seeded Random Numbers for Procedural Generation
TypeScript
MRT Commute 3D (src/engine/rng.ts). An integer hash and a small mulberry32 generator, so the generated city is identical on every load.
/** 32-bit integer hash of two ints (identical results in JS and the GLSL `hash2u` in shaders). */export function hash2i(x: number, y: number, seed = 0): number { let h = (Math.imul(x | 0, 0x27d4eb2d) ^ Math.imul(y | 0, 0x165667b1) ^ Math.imul(seed | 0, 0x3c6ef372)) >>> 0; h ^= h >>> 15; h = Math.imul(h, 0x2c1b3c6d) >>> 0; h ^= h >>> 12;
Geodetic to ECEF Coordinates
TypeScript
MRT Commute 3D (src/geo/geodesy.ts). Converts latitude, longitude and height on the WGS84 ellipsoid to Earth-centred metres, the frame the 3D map tiles are in.
This site (src/lib/projects-core.ts). Items sort newest first with a title tiebreak, then fill each umbrella's types in config order; empty types and umbrellas drop out.
/** Newest first, ties by title. */export function sortWorks<T extends WorkLike>(works: readonly T[]): T[] { return [...works].sort((a, b) => b.data.date.getTime() - a.data.date.getTime() || a.data.title.localeCompare(b.data.title));}/** Umbrella id of a type, or undefined for an unknown one. */
Contrast and Reduced-Motion CSS Generators
JavaScript
AccessEase (extension/lib/css.js). The extension builds its page-wide CSS from settings: media is excluded from colour overrides, and animations get a near-zero duration so elements that animate in still end visible.
function contrastCss(mode) { const p = PALETTES[mode]; if (!p) return ''; return [ `html,body,body *${MEDIA_EXCLUDE}{background-color:${p.bg}${B};color:${p.fg}${B};text-shadow:none${B}}`, // ...