Gists
Share and discover code snippetsIterate with enumerate
Enumerate in Rust lets you iterate over a collection while automatically tracking the index of each element.
Async file read
This snippet reads the contents of a file asynchronously using Tokio's tokio::fs::readtostring function.
Ternary inline condition
Returns one of two values based on a true or false condition, mimicking an if-else statement in a single line.
COALESCE for defaults
Returns the first non-null value from a list, making it easy to set fallback defaults for missing data.
Flexbox Center Alignment
This snippet centers a child element both horizontally and vertically within its parent using Flexbox.
truncate cascade tables
This SQL snippet drops all dependent foreign key relationships before truncating a table.
File exists check
This Bash snippet returns true before attempting to write if a file exists, preventing overwrite errors.
PHP array map filter
Applies a callback to each element of an array, then filters the results based on a condition.
re.sub cleanup string
This Python snippet uses regex to remove unwanted characters or patterns from a string.
Move Semantics Example
This snippet demonstrates efficient resource transfer by using move semantics to avoid expensive deep copies when passing temporary objects.
RefCell runtime borrow
Provides interior mutability with runtime borrow checking, ensuring safe mutation of values behind shared references.
Practical lambda invoke
This snippet demonstrates how to immediately invoke a C++ lambda expression to execute a block of code inline.
list comprehension flatten
Flattens a nested list into a single list using a list comprehension with two for clauses.
INDEX with included columns
Creates a non-clustered index that stores additional column data at the leaf level to cover queries without accessing the table.
Skip the stream and use a plain for loop. It is faster and easier to debug when you inevitably need to handle exceptions.