Regular Expressions Explained: How Regex Really Works

<.+> against <b>bold</b> and <i>italic</i> doesn’t match <b>. It matches the whole string, from the first < to the very last >. Nothing is broken. That is what a greedy quantifier is supposed to do, and it is also the most common “regex is matching too much” bug there is. Once you know what the engine does while it reads your pattern, this bug and most of its relatives stop being mysteries. ...

October 28, 2026 Â· 8 min Â· 1540 words Â· SpaghettiCoder

TypeScript Generics Explained With Examples

Why Does any Lose the Type You Passed In? Type a parameter as any and TypeScript stops checking everything that comes out of the function: 1 2 3 4 5 6 function firstElement(arr: any[]): any { return arr[0]; } const n = firstElement([1, 2, 3]); n.toUpperCase(); // compiles, crashes at runtime You know you passed an array of numbers. The compiler doesn’t, because any tells it to stop looking. n comes back as any, so calling a string method on a number compiles cleanly and throws TypeError: n.toUpperCase is not a function when it runs. ...

October 27, 2026 Â· 7 min Â· 1491 words Â· SpaghettiCoder

Exceptions vs Error Values: How to Pick a Strategy

Open a file that doesn’t exist in Python and open() raises a FileNotFoundError that unwinds out of your function. Do the same thing in Go and os.ReadFile hands back an error value sitting next to a nil byte slice. Same failure, two different shapes of code around it. The difference is not cosmetic. It decides whether a caller can ignore the failure by accident, and whether the compiler notices when they do. ...

October 26, 2026 Â· 8 min Â· 1506 words Â· SpaghettiCoder

Git Worktree: How to Work on Multiple Branches at Once

You’re three files into a feature branch, nothing committed, when a teammate pings you about a null-pointer crash in production. The usual move is git stash, check out main, fix it, push, then git stash pop and hope nothing in your half-finished feature depended on the files you switched away from. git worktree skips the shuffle. It checks out the hotfix branch into a second folder, next to your feature branch, with both backed by the same repository. ...

October 24, 2026 Â· 5 min Â· 974 words Â· SpaghettiCoder

API Rate Limiting: Algorithms and How to Build One

One client stuck in a retry loop with no backoff can put more load on your API in a minute than your other ten thousand clients combined. From your side it won’t look like an attack. It looks like a bug on their end, and it becomes an incident on yours. A rate limiter caps that client before it gets there. What does a rate limiter actually decide? On every request, the limiter asks one thing: has this key made too many requests in the current window? Three choices turn that into something you can implement. ...

October 23, 2026 Â· 7 min Â· 1478 words Â· SpaghettiCoder

LLM Function Calling and Tool Use, Explained

What LLM function calling actually does Ask a model “what’s the weather in Austin right now” with no connection to the outside world, and it has two options: say it doesn’t know, or make something up. Function calling gives it a third option. It describes what it needs, hands that description to your code, and waits for a real answer before replying. The name is slightly misleading. The model does not call anything. It emits a block of structured data saying which tool it wants and with what arguments, and your application decides whether to run it and what to do with the result. “Tool use” is the more accurate term, and it’s the one Anthropic’s docs use; OpenAI and Google mostly say function calling. The mechanism is the same under both names. The model only ever produces a request, never the side effect. ...

October 22, 2026 Â· 7 min Â· 1489 words Â· SpaghettiCoder

Intersection Observer API: Lazy Loading and Infinite Scroll

A scroll listener on window can fire hundreds of times during one swipe. Run getBoundingClientRect() on every card in a feed on each of those events and fifty images are enough to make the page stutter. The Intersection Observer API takes that check off the scroll path: you register which elements to watch, and the browser tells you when their visibility actually changes. How IntersectionObserver works An observer watches one or more target elements against a root (the viewport, by default) and calls a callback whenever a target crosses a visibility threshold. ...

October 21, 2026 Â· 5 min Â· 1043 words Â· SpaghettiCoder

What Is Unicode and How UTF-8 Encoding Works

Open a file saved as UTF-8 in a tool that assumes a different encoding and cafĂ© turns into café. The bytes on disk did not change. Only the rule used to turn those bytes back into characters did, and the two rules disagree about what byte 0xC3 means. Most “weird characters” bugs come from the same mismatch: broken filenames, mangled form submissions, emoji that crash a database insert, two strings that look identical but fail an equality check. Behind each one is the same confusion between two separate things, Unicode and UTF-8. ...

October 20, 2026 Â· 8 min Â· 1514 words Â· SpaghettiCoder

JavaScript Closures Explained With Examples

What Is a Closure in JavaScript? 1 2 3 4 5 6 7 8 9 10 11 12 function makeCounter() { let count = 0; return function () { count += 1; return count; }; } const counter = makeCounter(); console.log(counter()); // 1 console.log(counter()); // 2 console.log(counter()); // 3 makeCounter runs once, returns a function, and is done. The call is over and its stack frame is gone. Yet every call to counter() still reads and updates count, a variable declared inside a function that has already finished. count isn’t reset to 0, and it isn’t copied. It’s the same variable, still live, three calls later. ...

October 19, 2026 Â· 7 min Â· 1296 words Â· SpaghettiCoder

What Is TDD and How the Red-Green-Refactor Cycle Works

A test written after the code tends to check what the code does, not what it was supposed to do. Test-driven development fixes that by flipping the order: write the test, watch it fail, then write the smallest piece of code that makes it pass. Because the test exists before the code it checks, it can’t quietly confirm whatever the code happens to return. Kent Beck formalized the loop as red, green, refactor in his 2002 book Test-Driven Development: By Example. The name stuck. ...

October 18, 2026 Â· 7 min Â· 1346 words Â· SpaghettiCoder