Gists
Share and discover code snippetsFlexbox Center Alignment
This snippet uses Flexbox to easily center both horizontally and vertically any child element within its parent container.
HTTP middleware logger
This Go HTTP middleware logs each incoming request's method, path, and response status for easy debugging and monitoring.
count lines in files
Use this bash snippet to count lines in files with wc -l, summing totals across multiple files.
Flexbox centering
This CSS snippet centers an element both horizontally and vertically within its parent using flexbox.
Responsive Navigation Bar
A responsive navigation bar built with HTML and CSS that adapts to different screen sizes for a seamless mobile-friendly user experience.
string interpolation
String interpolation in Ruby lets you embed expressions directly into a string using #{}, making code cleaner and more readable.
Flexbox Centering Trick
This CSS snippet demonstrates how to perfectly center an element both horizontally and vertically using Flexbox.
Null Coalescing Operator
This snippet uses PHP's null coalescing operator to safely retrieve a value and fall back to a default when the original is null.
Responsive Grid Layout
This HTML snippet creates a flexible grid layout that automatically adjusts column sizes based on screen width, making it perfect for responsive web design.
if let Some
"if let Some" in Rust provides a concise way to safely unwrap an Option and run code only when it contains a value, binding that value for use inside the block.
deepPartial type utility
Makes all properties of an object type optional, recursively through nested objects, so you can easily work with partial updates or configurations.
YES, DeepPartial is a game-changer for handling nested configs or partial updates. Love how it keeps type safety while allowing flexibility.
@davidmalone recursive partials are handy but i've found they can mask missing required fields in deeply nested objects. ever run into that?
Hash transform values
Transforms all values in a hash using a given block, returning a new hash with the same keys.
Read file to string
Easily load the entire contents of a file into a single string variable in Java.
Yeah, since Java 11 you can just use Files.readString(path) - super clean, no loops or streams needed. If you're on an older version, new Scanner(file).useDelimiter("\\Z").next() does the trick in one line too.
debounce function
A debounce function limits how often a given callback can be called, ensuring it runs only after a specified pause in repeated invocations.
HTML5 doctype
This snippet declares the document type as HTML5, ensuring the browser renders the page in standards mode.
Option unwrapordefault
Unwraps an Option, returning the contained value if Some, or the default value for the type if None.
Safe navigation operator
The safe navigation operator (&.) in Ruby allows you to call a method on an object that may be nil, returning nil instead of raising a NoMethodError.
yeah @brownk1991 i love &. but sometimes it masks a nil i wasn't expecting, making bugs harder to track down, specially in long chains.
binary search
Finds a target value in a sorted array by repeatedly dividing the search interval in half, achieving O(log n) time complexity.
Deep clone utility
Creates a complete independent copy of nested objects and arrays, preventing unintended mutations to the original data.
Yeah, deep cloning is crucial for avoiding those nasty side effects in state management. I usually reach for structuredClone or JSON.parse(JSON.stringify()) for simple cases.
dictionary merge update
Use the update method or the merge operator to combine two dictionaries, with later values overwriting earlier ones for duplicate keys.
Center anything flexbox
This snippet centers any element both vertically and horizontally using Flexbox with just three lines of CSS.
Heap allocation example
Allocate and deallocate memory on the heap with malloc and free in this handy C snippet.
If the parent doesn't have an explicit height, that flex centering won't kick in vertically, so I always pair it with a min-height or height on the container. Did you run into that when the parent's height came from content?