Gists
Share and discover code snippets419 gists
Recursive CTE Hierarchy
This SQL pattern recursively traverses parent-child relationships to build hierarchical result sets, like org charts or category trees.
debounce function
A debounce function ensures that a callback is executed only after a specified delay has passed since the last time it was invoked, preventing performance issues from rapid-fire events like keystrokes...
Sanitize user input
This snippet cleans user input by stripping unwanted characters and preventing injection attacks, making your PHP app more secure.
Flexbox centering
This snippet centers an element both horizontally and vertically within its parent using Flexbox.
Scoped Timer
A scoped timer measures and logs the duration of a code block from construction to destruction, perfect for quick profiling without manual start/stop calls.
RAII mutex lock
Utilizing object lifetime to automatically acquire a mutex on construction and release it on destruction, ensuring exception-safe and deadlock-free synchronization.
Goroutine worker pool
This snippet sets up a fixed pool of goroutines that efficiently process tasks from a shared channel, limiting concurrency and avoiding resource exhaustion.
Array shuffle function
This snippet randomly reorders array elements using the Fisher-Yates algorithm for an unbiased in-place shuffle.
unwrap and expect
Quickly panic on `None` or `Err` values with `unwrap`, or use `expect` to panic with a custom message for clearer debugging.
Responsive grid layout
This CSS snippet generates a responsive grid that automatically adjusts the number of columns based on the viewport width using auto-fit and minmax.
Read lines from file
Reads a file line by line with efficient buffering and error handling using Rust's BufReader and lines iterator.
Symbol to proc
This snippet converts a symbol into a proc that calls the matching method on each argument, letting you write concise enumerable operations like `&:upcase`.
debounce function implementation
This debounce function delays executing a callback until after a specified wait period has passed since the last invocation, preventing excessive calls from rapid events.
flatten nested list
This snippet recursively flattens a nested list into a single-level list of all contained elements.
Flexbox centering trick
Use Flexbox's `display: flex; justify-content: center; align-items: center;` to perfectly center content both horizontally and vertically within a container.
Hash transform values
Transforms the values of a hash using a given block, returning a new hash with the same keys.
Array sample random
Returns a random element (or multiple random elements) from an array without repetition.
swap two integers
This snippet efficiently swaps the values of two integer variables, often using a temporary variable or XOR to avoid extra memory.
Concurrent worker pool
Manage a fixed number of goroutines to process tasks concurrently, controlling resource usage and throughput.
Try-With-Resources
The try-with-resources statement automatically closes resources like streams and connections after use, making resource management cleaner and leak-free.
dig nested hash
This snippet uses Ruby's `dig` method to safely retrieve values from deeply nested hashes without raising errors for missing keys.