Gists
Share and discover code snippets417 gists
Row Number Over Partition
Splits data into groups and assigns a sequential number to each row within its partition.
Generate UUID v4
PHP function to generate a random UUID v4 using cryptographically secure random bytes.
extract array unique values
This snippet removes duplicate values from an array, returning only the unique elements.
Lazy Loading Images
Lazy loading defers image loading until users scroll near them, speeding up initial page load.
Array destructuring swap
Swaps two variables without a temporary variable by using array destructuring assignment.
Ternary operator
The ternary operator provides a shorthand way to write an if-else statement in a single line, evaluating a condition and returning one of two values based on whether it's true or false.
Check if empty
This function returns true when a Lua table or string contains no elements or characters.
String copy w/ bounds check
Copies a string safely by checking that the destination buffer has enough space before copying.
Count character frequency
Counts how often each character appears in a string and returns a dictionary of frequencies.
Vector lerp function
Returns a vector linearly interpolated between two vectors by a given fraction.
debug.traceback
Returns the current call stack as a string for debugging errors and tracing execution flow.
Flexbox Centering Trick
Use Flexbox to center any element both horizontally and vertically with just three lines of CSS.
Responsive Image Embed
Embeds images that automatically scale to fit any screen size for responsive layouts.
SELECT DISTINCT column
This SQL snippet retrieves only unique values from a specified column, removing any duplicate entries.
constexpr auto value
This C++ snippet declares a `constexpr` variable named `value` that is evaluated at compile time for constant expressions.
Bind socket to port
This snippet binds a socket to a specified port using the bind function and a sockaddrin structure.
Useful pipe tricks
This snippet demonstrates useful pipe tricks in Bash for chaining commands efficiently.
Get nested value safely
This TypeScript snippet safely retrieves a nested value from an object without throwing an error if any intermediate property is undefined.
Reverse a string
This Python snippet reverses a string in place using slicing with a step of negative one.
constexpr auto factorial
Computes the factorial of a compile-time constant using constexpr for zero overhead.
Merge dicts safely
This snippet merges two dictionaries, preserving existing keys and avoiding overwrites, using `{dict1, dict2}` with dict2 taking priority.