Code snippets
Small, working examples you can read, understand, and open in the ShareCode editor to run or adapt. No setup, no sign-up — just code.
A typed Result type in TypeScript
Return errors as values the compiler forces you to handle, instead of throwing exceptions that callers can silently forget.
View snippetPythonBinary search in Python
Find an item in a sorted list in O(log n) time, with the iterative version, a recursive one, and Python's built-in bisect.
View snippetJavaScriptDebounce a function in JavaScript
Delay running a function until the calls stop coming in — the standard fix for resize, scroll, and search-as-you-type handlers that fire far too often.
View snippetJavaScriptDeep clone an object in JavaScript
Make a fully independent copy of a nested object so mutating the copy never touches the original.
View snippetPythonGroup a list of dictionaries by key in Python
Turn a flat list of records into buckets keyed by one of their fields, using only the standard library.
View snippetJavaRead a file line by line in Java
Load a text file's lines without the old BufferedReader boilerplate — and stream them when the file is large.
View snippetEvery snippet opens in a live editor
Hit “Open in ShareCode” on any snippet to drop it into a collaborative code space — then share the link to edit it together.