Gists
Share and discover code snippets419 gists
Safe table access
This snippet provides a safe way to access table values in Lua without errors when a key is missing, optionally returning a default.
Read file to string
This Rust snippet reads a file's contents into a String with just one line of code using the `std::fs::readtostring` function.
Read file to string
Read a file's contents into a String with Rust's standard library, handling errors succinctly.
Find duplicate files
Find duplicate files in a directory by comparing their checksums with this handy bash snippet.
Array reduce method
The Ruby `reduce` method combines all elements of an array by applying a binary operation, accumulating a single return value.
Array shuffle function
This snippet randomly shuffles the elements of an array using the Fisher-Yates algorithm.
SELECT with JOIN
This snippet merges data from multiple tables into a single result set based on a related column between them.
Functional option unwrap
Safely and idiomatically extract values from an Option using functional combinators like map, unwrapor, and andthen to avoid panics and keep your code expressive.
safe table indexing
Safely retrieves a value from a nested Lua table, returning nil if any intermediate key is missing.
RAII lock guard
This snippet automatically acquires a mutex lock on construction and releases it on destruction, making thread synchronization both exception-safe and concise.
Merge dictionaries
This snippet merges two or more dictionaries into one, combining their key-value pairs with later keys overriding earlier ones.
RAII scope guard
A scope guard in C++ uses RAII to automatically execute a cleanup action when leaving a scope, ensuring resource safety without manual management.
Flexbox Centering
This Flexbox snippet centers a child element both horizontally and vertically inside its parent container.
Predicate not method
This snippet creates a negated predicate using `Predicate.not()` to easily invert a filtering condition.
Find empty directories
This bash snippet recursively finds and lists all empty directories in the current directory.
Update with Join
This snippet updates rows in a table based on matching values from another table using a JOIN.
Flexbox center child
This snippet centers a child element both horizontally and vertically within its parent using Flexbox.
Array eachwithindex
Iterate over an array while accessing both the element and its index in each iteration.
Validate email address
This PHP snippet quickly validates an email address using PHP's built-in filtervar function with the FILTERVALIDATEEMAIL flag.