Gists
Share and discover code snippets419 gists
Debounce function
A debounce function delays executing a callback until after a specified wait time has elapsed since the last invocation, preventing excessive calls.
Remove duplicate rows
This snippet deletes or filters out duplicate rows from a table, typically by using a window function like ROWNUMBER() to keep only one occurrence per unique set of columns.
async retry wrapper
Wraps an async function to automatically retry on failure with configurable attempts and delays.
safe navigation operator
The safe navigation operator (&.) in Ruby allows you to safely call methods on potentially nil objects without raising a NoMethodError, returning nil instead.
list flattening
Easily flatten any nested list structure into a single-level list with a concise recursive or iterative Python snippet.
Concurrent worker pool
A concurrent worker pool pattern in Go lets you limit the number of goroutines processing jobs from a channel, preventing resource exhaustion while maximizing throughput.
Find Duplicate Records
This SQL snippet identifies duplicate records in a table by grouping rows based on specified columns and counting occurrences to find those with more than one entry.
List comprehension filter
List comprehensions with a conditional clause let you create a new list by filtering elements from an existing iterable based on a boolean condition.
binary search
This snippet efficiently finds the position of a target value within a sorted array by repeatedly dividing the search interval in half.
Read file lines
Reads all lines from a file into a list, handling exceptions with a try-catch block.
String copy function
This C code snippet provides a function to copy a string from a source buffer to a destination buffer, properly handling null terminators and ensuring safe memory boundaries.
Sort files by size
This bash snippet lists files in a directory sorted by their size, from smallest to largest, making it easy to find the biggest files cluttering your disk.
async retry wrapper
This handy async retry wrapper automatically retries failed async operations with customizable delays and maximum attempts.
Array random shuffle
This JavaScript snippet randomly shuffles the elements of an array in place using the Fisher-Yates algorithm.
Pick and omit
This TypeScript snippet demonstrates how to use Pick and Omit utility types to create new types by selecting or excluding specific properties from an existing type.
Top N per group
This SQL snippet uses a window function (like ROWNUMBER) to fetch the top N records from each category or group in your dataset.
Move semantics example
This snippet demonstrates how move semantics in C++ efficiently transfer resource ownership without costly copying.
Sanitize user input
This PHP snippet strips unwanted characters from user input to prevent injection attacks and keep your data clean.
Read Properties File
This snippet loads key-value pairs from a properties file into a Java Properties object for easy configuration retrieval.
Throttle function
A throttle function limits how often a given callback can be invoked, ensuring it runs at most once per specified time interval.
Read file to string
This snippet uses `std::fs::readtostring` to instantly load a file's contents into a `String`.
Try-With-Resources
The try-with-resources statement automatically closes any resources declared within it when the block finishes, preventing resource leaks.