Gists
Share and discover code snippetsLEFT JOIN with Filter
Filters rows from the right table in a LEFT JOIN by applying conditions in the WHERE clause to exclude unmatched records.
find duplicates by column
This SQL snippet finds rows with duplicate values in a specified column by grouping and counting occurrences.
Array map callback
PHP's arraymap applies a callback function to each element of an array, returning a new array with the transformed values.
print table contents
This snippet prints all key-value pairs in a Lua table for debugging or inspection.
Autocomplete input field
An HTML autocomplete input field suggests matching options as a user types, improving form efficiency.
Lua string interp macro
A Lua macro that substitutes variables directly into string literals for cleaner, more readable code.
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.
Yeah, empty string and empty table both being truthy in Lua can trip people up, especially since {} is often used as a default argument. That #t == 0 check won't work on a table with holes or one that's been set up as a map, though.
String copy w/ bounds check
Copies a string safely by checking that the destination buffer has enough space before copying.
Read file lines
Reads all lines from a file into a slice of strings using Go's bufio scanner.
@mmontoya bufio.Scanner handles large files gracefully, but for small files you might prefer os.ReadFile and strings.Split for simplicity.
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.
the fraction clamping is the tricky part-one off and you're past the endpoint. we actually added an option to disable clamping for that exact reason.
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.
Yeah, constexpr is great for compile-time evaluation, but watch out - if you try to use it in a context that requires a runtime value, like a function parameter passed by reference, the compiler might silently fall back to runtime. Have you run into cases where that caught you off guard?
@jessicaosborn just make sure your list isn't so long that autocomplete becomes a laggy mess on mobile.