Gists
Share and discover code snippets419 gists
Debounce function
A debounce function delays the execution of a callback until a specified time has passed since the last call, preventing excessive or repeated triggers.
RAII mutex lock guard
This snippet automatically locks a mutex when the guard is created and unlocks it when the guard goes out of scope, ensuring safe and exceptionβproof resource management.
Responsive Navigation Bar
This HTML snippet creates a navigation bar that adapts to different screen sizes, making it mobile-friendly without extra CSS frameworks.
Stream filter collect
Filters a stream based on a predicate and collects the matching elements into a collection.
Go HTTP handler
This snippet defines a simple HTTP handler function that responds to requests with a specified status code and message.
RAII wrapper class
This RAII wrapper ensures automatic resource cleanup by acquiring a resource in the constructor and releasing it in the destructor.
extract tar.gz archive
This bash snippet decompresses and extracts the contents of a tar.gz archive.
symbol to proc
Converts a symbol into a proc that calls the corresponding method on each element, enabling concise iteration like `array.map(&:method)`.
RAII lock guard
This snippet uses RAII to automatically acquire a mutex lock on construction and release it on destruction, preventing resource leaks and deadlocks.
Find and replace
This bash snippet replaces all occurrences of a search pattern with a replacement string in a file using sed.
find and replace text
This handy bash snippet uses sed to globally find and replace a specific string across a file.
Sanitize user input
This function removes or encodes dangerous characters from user input to prevent injection attacks and ensure data integrity.
sortArrayByKey
Sorts an array of objects by a given key, making it easy to organize data in ascending or descending order.
unwraporelse closure
Use unwraporelse on Option or Result to provide a closure that returns a fallback value when the value is absent or an error occurred.
Find duplicate records
This SQL snippet helps you find duplicate records by grouping on key columns and filtering for counts greater than one.
RAII lock guard
Automatically acquires a mutex lock on construction and releases it on destruction, ensuring exception-safe resource management.
Sanitize Input String
Sanitize an input string by stripping HTML tags and encoding special characters to prevent XSS attacks.
find . -name
Recursively searches for files and directories starting from the current directory whose names match a specified pattern.
Defer file close
Use defer to automatically close a file after you finish reading or writing it, preventing resource leaks.
Lambda comparator sort
This Java snippet uses a lambda expression to define a custom comparator and sort a list in one clean line.
Deep clone object
This snippet creates a fully independent copy of a JavaScript object, including all nested properties, so changes to the clone don't affect the original.
Array partition by predicate
This handy TypeScript snippet splits an array into two separate arrays based on a predicate function, returning both the elements that pass and those that fail the test.
CSS Flexbox Centering
This CSS snippet uses Flexbox to easily center content both horizontally and vertically within a container.