Gists
Share and discover code snippets418 gists
Iterate over HashMap
Iterate over a Rust HashMap's key-value pairs using a `for` loop with `&map` to borrow immutably.
Option unwrapor
Takes an `Option` and returns its inner value if `Some`, otherwise returns a provided default value.
arrayfilter callback
Use arrayfilter with a custom callback to easily remove unwanted elements from an array based on any condition.
Common Table Expression
A Common Table Expression lets you define a temporary result set within a query, making complex logic easier to read and reuse.
Type-safe event emitter
This TypeScript snippet defines a generic event emitter that enforces correct event names and payload types at compile time.
flatten nested list
This snippet takes a nested list and returns a single flat list containing all elements.
Type-safe object keys
This snippet ensures you only access valid object keys by enforcing type safety at compile time.
RAII wrapper
This snippet ties resource acquisition to object construction and automatic release to destruction, preventing leaks and simplifying cleanup.
Swap two integers
This C snippet exchanges the values of two integer variables without needing a temporary variable, using bitwise XOR.
Center element with flexbox
This CSS snippet uses flexbox properties to perfectly center a child element both horizontally and vertically within its container.
Debounce function
This debounce function limits how often a callback can execute by delaying its call until after a specified quiet period since the last invocation.
Parse JSON to struct
This snippet unmarshals JSON data into a Go struct for easy access to the fields.
Parse string to integer
This snippet converts a string containing numeric characters into its corresponding integer value.
Array shuffle
This snippet efficiently randomizes the order of elements in an array using the Fisher-Yates shuffle algorithm.
custom exception class
Define your own exception types to make error handling more explicit and debuggable in larger Python projects.
passwordhash passwordverify
This PHP snippet securely hashes passwords with `passwordhash` and verifies them with `passwordverify` to protect against attacks.
Find duplicate files
This bash snippet scans a directory and lists files that have identical content, usually by comparing checksums or hashes.
Iterate table pairs
Iterates over all key-value pairs in a Lua table, allowing you to process each element efficiently.
Find Duplicate Rows
This snippet finds duplicate rows in a table by grouping on all columns and returning only those groups with more than one occurrence.
Goroutine leak detection
This snippet helps you identify goroutines that never exit, preventing memory leaks in your Go applications.
List largest files
This bash snippet lists files in the current directory sorted by size, showing the largest ones first.