SaveSnippets
Community
Pricing
Sign In
Get Started
@admin
ADMIN
Member since Apr 2026
770
Public snippets
5
Net score
5
Total upvotes
Showing
691–720
of
770
public snippets
Kotlin
Safe Call Chain + Elvis Default
`?.` is the safe-call operator — short-circuits to `null` at the first null in a chain. Pair with `?:` (Elvis) for "this or a default". Replaces nested if-not-null ladders.
2h ago
0
Kotlin
Infix Functions
A single-arg method/extension can be called without dot or parens when marked `infix`. Lets you write DSL-style code like `5 shouldBe 5` or `key to value`.
2h ago
0
Rust
Rc and Arc — Shared Ownership
`Rc<T>` lets multiple owners share read-only access in single-threaded code; `Arc<T>` is the thread-safe version. Pair with `RefCell` / `Mutex` when you need shared MUTABLE access.
2h ago
0
Kotlin
Default Arguments + Named Parameters
Default values eliminate most overload sets. Named args make call sites self-documenting and let you skip middle parameters without thinking about positions.
2h ago
0
Kotlin
Higher-Order Functions
Functions that take or return other functions. Foundation for streams, callbacks, DSLs — and an alternative to interfaces with a single method.
2h ago
0
Python
Deprecation Warning Decorator
Mark a function as deprecated so callers get a DeprecationWarning the first time it's called. Includes the replacement function name in the message so callers know what to switch to.
2h ago
0
Kotlin
Sealed Classes — Closed Type Hierarchies
`sealed` restricts subclassing to the same module. Combined with exhaustive `when`, the compiler enforces handling of every variant — refactor-friendly state machines.
2h ago
0
TypeScript
Exhaustive `assertNever`
Compile-time guarantee that every variant of a union is handled. When you add a new variant later, every switch missing that case becomes a type error. The runtime version is a safety net.
2h ago
0
Kotlin
buildString / buildList / buildMap
Stdlib builders that give you a mutable scope, then return an immutable result. Replaces `StringBuilder().apply { ... }.toString()` boilerplate; the result type is the read-only one.
2h ago
0
Kotlin
Inline Value Classes (kotlin 1.5+)
`@JvmInline value class` wraps a single value with a distinct type at compile time but no runtime overhead — at runtime it's just the underlying primitive/object. Replaces typedef tricks and prevents UserId vs PostId mix-ups.
2h ago
0
TypeScript
Discriminated Unions with Exhaustive Switch
Discriminated (tagged) unions give you compiler-checked state machines. Pair with `assertNever` to force every new variant to be handled at every switch site — refactors stop being scary.
2h ago
0
Java
AtomicInteger / LongAdder
Lock-free atomics for shared counters. `AtomicInteger` for low contention; `LongAdder` for high contention (shards internally — much faster under heavy parallel load).
2h ago
0
Bash
Heredoc with Variable Interpolation Control
Heredocs are the cleanest way to embed multi-line text. Unquote the delimiter to allow variable expansion; QUOTE it to keep the body literal (no $foo expansion).
2h ago
0
Kotlin
Coroutine Cancellation
Cancellation is cooperative — your coroutine must check via `ensureActive()`, `yield()`, or any other suspending call. CPU-busy loops without a suspend point are NOT cancellable.
2h ago
0
Kotlin
coroutineScope and Structured Concurrency
`coroutineScope { }` waits for ALL its children before returning. If any child throws, the others are cancelled. The cornerstone of structured concurrency — no leaked coroutines.
2h ago
0
Kotlin
Flow — Cold Async Streams
`Flow<T>` is a coroutine-based reactive stream — like Sequence but async. Cold (each collector restarts the producer) and respects cancellation. The backbone of modern Kotlin/Android reactive code.
2h ago
0
Kotlin
launch and Jobs
`launch` starts a coroutine and returns a `Job` you can join, cancel, or check status on. Fire-and-forget or join-when-ready style.
2h ago
0
Kotlin
Coroutines — suspend Function Basics
`suspend fun` can be paused and resumed without blocking a thread. Call only from another `suspend` function or a coroutine builder (`launch`, `runBlocking`, `async`).
2h ago
0
Kotlin
withContext — Switching Dispatchers
`withContext(dispatcher)` suspends the calling coroutine, runs the block on the given dispatcher, returns the result. Use `Dispatchers.IO` for blocking I/O, `Default` for CPU work, `Main` for UI updates.
2h ago
0
SQL
NULLS FIRST / NULLS LAST
Control where NULLs land in an `ORDER BY`. PostgreSQL/Oracle default NULLs to LAST in ASC, FIRST in DESC; MySQL/SQL Server flip it. Be explicit if it matters.
2h ago
0
Kotlin
val vs var — Prefer Immutability
`val` is read-only (can't reassign the reference); `var` is mutable. Default to `val` everywhere — Kotlin's style guide recommends it, and a Compiler warning fires if a `var` is never reassigned.
2h ago
0
Go
Variadic Functions
`...T` in the last parameter slot accepts zero or more T values. Pass a slice by suffixing with `...` to spread it. Used everywhere from `fmt.Println` to custom builders.
2h ago
0
Kotlin
Nullable Types — String? and the ? Operator
Kotlin distinguishes `String` (never null) from `String?` (may be null) in the type system. The compiler refuses to compile code that could deref a possibly-null value — the famous "no more NullPointerException" feature.
2h ago
0
Go
Pointers — When and Why
Use pointers when you want to mutate the callee's value, share a large struct without copying, or distinguish "no value" via nil. Go has no pointer arithmetic — much safer than C.
2h ago
0
Kotlin
Lambdas and Function Types
Kotlin functions are first-class values. A lambda is `{ args -> body }`; its type is `(InputTypes) -> ReturnType`. Single-argument lambdas can use the implicit `it` parameter.
2h ago
0
Kotlin
when Expressions — Powerful switch
Kotlin's `when` is an expression (returns a value), supports ranges, type checks, multiple values per branch, and arbitrary boolean conditions. Replaces nested if/else AND traditional switch.
2h ago
0
Go
defer / panic / recover
`defer` runs a statement when the enclosing function returns — LIFO order. `panic` aborts; `recover` (inside a deferred func) catches a panic and converts it back to a normal return. Use sparingly.
2h ago
0
Go
Methods and Receivers
Methods are functions with a receiver argument. Use pointer receivers when you mutate, when the struct is large, OR for consistency (mixing pointer + value receivers on the same type is a common bug source).
2h ago
0
Go
Multiple Return Values + Named Returns
Go functions can return multiple values — most idiomatically a `(result, error)` pair. Named returns let you document the meaning of each value AND enable naked returns in short functions.
2h ago
0
HTML
Picture Element — Art Direction
`<picture>` lets you serve DIFFERENT images at different breakpoints — not just different sizes of the same crop. Perfect for a wide desktop banner that becomes a square mobile poster.
2h ago
0
1
…
22
23
24
25
26