More in Systems
Worker pool with a wait group in Go
Systems
Fixed number of goroutines draining a channel, with the group ensuring main waits for all of them.
Null-safe chaining in Kotlin
Systems
?. stops at the first null and ?: supplies the fallback, replacing a stack of if statements.
Read a file into a string in Go
Systems
os.ReadFile replaced ioutil.ReadFile in 1.16 and is the one-liner for small files.
Result and the question mark operator in Rust
Systems
? propagates the error to the caller, which is why Rust functions rarely need explicit error branches.
Nullable reference types in C#
Systems
Turning the feature on makes the compiler point at every place a null could slip through.
Iterate and collect in Rust
Systems
Filter and map fuse into a single pass; collect decides what comes out the other end.
Context with a timeout in Go
Systems
Cancels the request and everything downstream of it after two seconds. The defer is not optional.
Async/await with a task group in Swift
Systems
Runs the downloads concurrently and collects them, with cancellation propagating to all of them.
Random picks
Narrow a union with a type guard
TypeScript
A predicate returning `x is T` teaches the compiler what a runtime check proved.
Find the largest files under a directory
Shell
Sorts everything beneath the working directory by real disk usage and shows the twenty worst offenders.
RAII file handling in C++
Systems
The stream closes itself when it leaves scope, whether the function returns normally or throws.
Group an array by a key
JavaScript
Object.groupBy is available in current runtimes; the reduce version is the fallback for older ones.
List branches merged into main
Git
Finds the branches that are safe to delete, and the ones that are not.
Responsive images that do not blow the bandwidth budget
Web & CSS
srcset lets the browser pick; sizes tells it how wide the image will actually be rendered.
Rename a batch of files with a pattern
Shell
Strips a prefix from every file in a directory using shell parameter expansion, no rename utility required.
Generate an SSH key and add it to the agent
Security
Ed25519 rather than RSA: shorter, faster, and no key-size decision to get wrong.