Gists
Share and discover code snippets419 gists
type-safe deep clone
This TypeScript snippet performs a deep clone while preserving the original object's type, ensuring full type safety without relying on any.
print table contents
This snippet prints all key-value pairs in a Lua table, making it easy to inspect the table's contents during debugging.
Flatten nested list
This code snippet recursively flattens any nested list into a single flat list of elements.
Database prepared statement
This PHP snippet uses a prepared statement to securely execute a database query, preventing SQL injection by separating SQL logic from user-supplied data.
Array#sample
Returns a random element (or multiple random elements if given an argument) from an array.
DeepReadonly type utility
This TypeScript utility recursively makes all properties of an object type read-only, including nested objects and arrays.
hash default value
In Ruby, setting a hash's default value lets you specify a fallback for missing keys instead of returning nil.
Flexbox 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.
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.
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.