Gurkirat Singh
← Writing

Snippets I keep reaching for

30 Jun 2026 · #code #shell #typescript

Some code I copy-paste often enough that it lives here now. It doubles as a test of how code renders here: filenames, a copy button, and the odd highlighted line, all applied at build time.

find the biggest files

When a disk fills up, this is the first thing I run:

Terminal window
# top 20 largest files under the current directory
du -ah . | sort -rh | head -n 20

a typed debounce

Small enough to remember, annoying enough to re-derive every time:

debounce.ts
export function debounce<A extends unknown[]>(
fn: (...args: A) => void,
ms = 200,
): (...args: A) => void {
let timer: ReturnType<typeof setTimeout>;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), ms);
};
}

Use it like const onScroll = debounce(handler, 100) — the handler only fires once the events settle.

the CSS reset I always start with

reset.css
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
}

That’s it — three things I’ve stopped re-googling.