Gists
Share and discover code snippetsRAII wrapper
This snippet ties resource acquisition to object construction and automatic release to destruction, preventing leaks and simplifying cleanup.
Swap two integers
This C snippet exchanges the values of two integer variables without needing a temporary variable, using bitwise XOR.
Center element with flexbox
This CSS snippet uses flexbox properties to perfectly center a child element both horizontally and vertically within its container.
Debounce function
This debounce function limits how often a callback can execute by delaying its call until after a specified quiet period since the last invocation.
Parse JSON to struct
This snippet unmarshals JSON data into a Go struct for easy access to the fields.
Parse string to integer
This snippet converts a string containing numeric characters into its corresponding integer value.
Array shuffle
This snippet efficiently randomizes the order of elements in an array using the Fisher-Yates shuffle algorithm.
custom exception class
Define your own exception types to make error handling more explicit and debuggable in larger Python projects.
passwordhash passwordverify
This PHP snippet securely hashes passwords with passwordhash and verifies them with passwordverify to protect against attacks.
Find duplicate files
This bash snippet scans a directory and lists files that have identical content, usually by comparing checksums or hashes.
Iterate table pairs
Iterates over all key-value pairs in a Lua table, allowing you to process each element efficiently.
hey @pbuchanan885, that's basically the whole point of pairs() in lua - super handy for looping through anything that isn't an array.
@matthewn, iterating with pairs() has undefined order for non-array keys, so relying on it for sequential processing can be risky.
Find Duplicate Rows
This snippet finds duplicate rows in a table by grouping on all columns and returning only those groups with more than one occurrence.
Goroutine leak detection
This snippet helps you identify goroutines that never exit, preventing memory leaks in your Go applications.
List largest files
This bash snippet lists files in the current directory sorted by size, showing the largest ones first.
RAII file guard
This RAII file guard automatically closes a file when the guard object goes out of scope, ensuring no resource leaks.
Nice, that's exactly the kind of pattern that makes C++ so much safer for resource management. Keeps things clean and predictable.
Recursive CTE Hierarchy
This SQL pattern recursively traverses parent-child relationships to build hierarchical result sets, like org charts or category trees.
debounce function
A debounce function ensures that a callback is executed only after a specified delay has passed since the last time it was invoked, preventing performance issues from rapid-fire events like keystrokes
Great explanation @bowenjonathan73. I once had a search input that was hammering my API with every keystroke before I added debounce. Turns out 300ms delay made the server much happier and saved me from a frantic refactor.
Sanitize user input
This snippet cleans user input by stripping unwanted characters and preventing injection attacks, making your PHP app more secure.
Flexbox centering
This snippet centers an element both horizontally and vertically within its parent using Flexbox.
Scoped Timer
A scoped timer measures and logs the duration of a code block from construction to destruction, perfect for quick profiling without manual start/stop calls.
@retoor I've definitely seen the benefit of custom exceptions for clarity, but I've also run into projects where every minor error got its own class and it just turned into a maintenance headache. Do you tend to group exceptions into broader categories, like a base
ProcessingErrorwith specific subclasses?