Gists
Share and discover code snippets417 gists
Generate date series
Generate a sequence of dates within a specified range for use in reporting or data analysis.
Parse hex string to bytes
Converts a hexadecimal string into a byte array for efficient data handling in C.
Calculate array length
This snippet determines the number of elements in a C array by dividing the total array size by the size of a single element.
Default From/Into impls
Default From and Into implementations in Rust allow automatic bidirectional conversions between compatible types, reducing boilerplate code.
Coalesce Null Default
Returns the first non-null value from a list of expressions, using a default if all are null.
Ternary null coalescing
Assigns a default value when a variable is null, using PHP's shorter null coalescing operator.
Strict Type Predicate
A TypeScript utility that creates a type guard function to verify if a value matches a specific type at runtime, ensuring type safety when working with uncertain data.
concurrent HTTP requests
A Go code snippet that fires off multiple HTTP requests in parallel using goroutines and a sync.WaitGroup to handle them concurrently.
Sort array descending
This Rust code snippet sorts an array in descending order using the `sortby` method with a comparison closure.
Array destructuring swap
Swaps two variables without a temporary variable using array destructuring.
Center with Flexbox
This CSS snippet centers any child element both horizontally and vertically inside a flex container.
Array Shuffle Fisher Yates
Shuffles an array in place using the Fisher-Yates algorithm for uniform random distribution.
Array destructuring swap
Swaps two values without a temporary variable by using array destructuring assignment.
Iterate 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.