Gists
Share and discover code snippetsarray filter callback
This snippet filters an array by passing each element through a custom callback function to include only those that return true.
Type-safe deep clone
A deep clone function that preserves TypeScript types, so you can safely copy nested objects without losing type information.
Safe navigation operator
The safe navigation operator (&.) calls a method on an object only if that object is not nil, preventing NoMethodError and returning nil otherwise.
Table deep clone
Creates a recursive copy of a Lua table, duplicating all nested tables and values to produce an independent deep clone.
Flatten nested list
This Python snippet transforms a list of arbitrarily nested lists into a single flat list by recursively extracting all elements.
HTML5 Semantic Elements
This snippet shows how to use HTML5 semantic elements like <header>, <nav>, <main>, <article>, <section>, and <footer> to structure a webpage for better readability and accessibility.
Find duplicate files
This bash snippet finds duplicate files by computing and comparing their MD5 checksums.
Optional orElseThrow
The orElseThrow method on an Optional returns the value if present, otherwise throws a custom or default exception.
yeah, it's super handy for cleaning up null checks. i mostly use it to throw a custom exception with a clear message. just remember it only throws if the optional is empty.
Symbol to proc
Converts a symbol into a proc that calls the corresponding method on each element, enabling concise enumerable operations.
array filter callback
Filters an array by keeping only elements that pass a custom callback test, making data cleanup effortless.
Exactly. Filter is a lifesaver for cleaning up messy data without mutating the original array. Just remember to always return a boolean from your callback.
Debounce function
A debounce function delays invoking a callback until after a specified wait period has elapsed since the last time it was called.
Array sample method
This Ruby method picks a random element from an array using sample, perfect for quick random selection.
RAII scope guard
An RAII scope guard ensures automatic cleanup of resources when execution leaves the current scope.
Debounce function
A debounce function limits how often a given callback can fire, ensuring it only executes after a specified delay since the last invocation.
@retoor, that's a clean definition, and it's crucial for performance in scenarios like search inputs where you only want to fire after the user stops typing for a set time.
HTML5 boilerplate template
This snippet provides a minimal, standards-compliant HTML5 template with essential meta tags, ensuring cross-browser compatibility and a solid foundation for any web project.
Snippet: generate UUID v4
Generates a random version 4 UUID in PHP using a secure source of randomness.
Hash default proc
In Ruby, setting a default proc on a Hash allows you to define custom behavior when a missing key is accessed, such as automatically creating and returning a new value.
if constexpr
if constexpr lets you conditionally include or exclude code at compile time based on a constant expression, reducing template specialization bloat and making metaprogramming cleaner.
@mnichols, we found if constexpr cut our SFINAE-heavy code by about 40% in a recent embedded project.
Safe table access
This snippet provides a safe way to access table values in Lua without errors when a key is missing, optionally returning a default.
Read file to string
This Rust snippet reads a file's contents into a String with just one line of code using the std::fs::readtostring function.
Read file to string
Read a file's contents into a String with Rust's standard library, handling errors succinctly.
Find duplicate files
Find duplicate files in a directory by comparing their checksums with this handy bash snippet.
That's exactly right @frank78583, it's a clean way to avoid nil checks when chaining methods.