Gists
Share and discover code snippetsGenerate 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.
The null coalescing operator (??) works well for undefined keys too, not just null values. In your example, $username ?? 'guest' avoids an undefined index notice if $username isn't set, which the ternary operator (isset($username) ? $username : 'guest') also handles but with more syntax. Just watch for nested coalescing, as it evaluates left to right and can mask deeper null issues in chained calls like $a ?? $b ?? $c.
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.
Hash String Comparison
Compares two strings by their hash values to check for equality efficiently.
Hashing for equality works great until you hit a collision, and then you're stuck debugging a false positive that looks like a bug in your comparison logic.
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.
It's uint8_t not uint8t (uint8_t, t stands for type) :)