Gists
Share and discover code snippets419 gists
swap using XOR
Swap two integers without a temporary variable by using the bitwise XOR operator to toggle their bits between each other.
throttle function
A throttle function ensures a given callback is executed at most once within a specified time interval, preventing rapid repeated calls.
Centering with Flexbox
Easily center any element both horizontally and vertically inside a flex container.
Responsive Meta Tag
This essential HTML meta tag ensures your webpage scales properly on mobile devices by setting the viewport width to the device width and initial scale to 1.
debounce async hook
This handy React hook debounces an async function, delaying its execution until after a specified wait time since the last call, perfect for rate-limiting API requests or handling rapid user input.
Responsive Navigation Bar
This HTML snippet creates a navigation bar that adapts to different screen sizes for better mobile usability.
RAII lock guard
An RAII lock guard automatically acquires a mutex upon creation and releases it when the object goes out of scope, ensuring exception-safe and deadlock-free locking.
Option combinators
Use Rust's Option combinators like `map`, `andthen`, and `unwrapor` to elegantly chain operations on optional values without messy nested match statements.
Deep copy table
Creates a complete independent copy of a table, including all nested tables and values.
Flexbox centering
This snippet uses Flexbox to perfectly center an element both horizontally and vertically within its parent container.
Memoize function
A memoize function caches the results of expensive function calls to avoid recomputation when the same inputs occur again.
Centering with Flexbox
Easily center any element both horizontally and vertically with just a few lines of Flexbox CSS.
Strongly typed useState
"Leverage TypeScript's generics with useState to enforce strict typing on your component's state for safer code."
Semantic HTML5 skeleton
This snippet gives you a semantic HTML5 boilerplate with proper landmark elements for structure and accessibility.
Flatten list of lists
This snippet flattens a list of lists into a single list using a list comprehension.
Array partition filter
Splits an array into two arrays based on a predicate, returning both filtered and remaining elements in one call.
dictionary merge update
Merges and updates dictionaries by adding key-value pairs from another dictionary, overwriting existing keys.
Find Duplicate Values
This query uses GROUP BY and HAVING to identify duplicate values in a column for quick data quality checks.
array shuffle
This snippet randomly reorders the elements of an array in place using the Fisher-Yates algorithm.
find all symlinks
Recursively locate all symbolic links in the current directory tree using the find command.