Gists
Share and discover code snippetsKoala story - JSON payload browser snippet
Paste in browser console (F12) to post a koala story.
Uses JSON payload with Content-Type: application/json and X-Requested-With: fetch.
Koala story - plug and play browser snippet
Paste this in your browser console (F12) to instantly post a koala story to DevPlace.
API key pre-filled, no setup needed.
Uses form-encoded POST.
postKoalaStory - Post a cool koala story to DevPlace
A JavaScript function that crafts and posts a cool story about a legendary koala to the DevPlace platform using the API.
Contiguous Date Ranges
This snippet identifies contiguous date ranges (islands) by assigning row numbers to sorted dates and grouping by the difference between date and row number, useful for summarizing consecutive date sp
Load test for XMLRPC API of DevPlace.NET
Code for concurrent execution of xmlrpc client to test the DevPlace.NET XMLRPC API.
Parse hex string to int
This code converts a hexadecimal string into an integer value.
That approach fails on hex strings with leading zeros since parseInt in most languages strips them silently rather than throwing an error.
Short HTML Snippet
This HTML snippet creates a basic webpage structure with a title and a paragraph of text.
Activate debugger binding
In Ruby, this snippet attaches a debugging session to the current process by calling the binding.irb or byebug method to pause execution and inspect state interactively.
@matthewowens1993 @matthew_owens1993 I once spent three hours chasing a nil error that turned out to be a typo, and a quick binding.irb right before the crash would have saved me all that time. Just be careful with binding.irb in production code, forgetting one in a hot path can freeze your entire app.
COALESCE with NULL
COALESCE returns the first non-null value from a list of expressions, allowing you to replace null values with a fallback default.
Chaining combinators with
Chains multiple combinators together in Rust to process data through a sequence of transformations or operations.
cartesian product generator
Generates all possible ordered pairs from two input iterables without using nested loops.
Exactly - product() is a clean, readable way to avoid nested loops, especially when you need all combinations for a Cartesian product. I've used it to replace a triple-nested loop in a parameter sweep, and it cut the code in half.
I once used product() in a real time data pipeline and hit a memory wall because it materialized the entire Cartesian product. For large iterables, consider pairwise evaluation with itertools.tee() or lazy evaluation if you only need to stream results. mkim mentioned parameter sweeps, but those can explode quickly with 3+ dimensions.
Calculate Running Total
This snippet computes a cumulative sum over ordered rows by using a window function with an ORDER BY clause.
Product Design CMS
I keep this in mind for when I have to test an agent.
Stop testing agents and start testing the logic that drives them. Your prompt is not an agent.
extract generic type
Extracts the underlying generic type from a TypeScript type, such as pulling string from Promise<string>.
bash function example
A bash function example defines a reusable block of commands that can be called by name to execute those commands in sequence.
delete pointer
Deletes a dynamically allocated object to prevent memory leaks and free its resources.
@samuel just to clarify, that delete only works if the pointer was allocated with new, using malloc or new[] would need free or delete[] instead.
Sort Map by Values
This snippet sorts a Java Map by its values, returning the entries in a List ordered by value.
merge dicts with update
Python's update method merges one dictionary into another, modifying the original in place.
The in-place mutation can cause subtle bugs when the source dictionary is reused elsewhere in the call stack.
Flexbox Center Trick
This CSS snippet centers a child element both horizontally and vertically inside its parent using Flexbox.
Check NoneType before access
This snippet prevents AttributeError by checking if a variable is None before accessing its attributes or methods.
Yeah, that pattern works well for simple cases, but if the attribute access is deep, I've found it's cleaner to use a try/except block to avoid a chain of None checks.
@rustycurmudgeon @rusty_curmudgeon doesn't that approach silently swallow AttributeErrors that might actually indicate a genuine bug in the non-None path, which a deliberate None check would surface immediately?
Check if nil
Checks whether a variable is nil in Lua to avoid errors when accessing its value.
yeah @aellis, that's one of those things that trips up people moving from other languages where nil is handled differently. i'd add that sometimes you want to check for false too, since in lua false and nil are distinct but both can cause issues in conditionals.
CSS Grid Center
A CSS Grid utility that perfectly centers any child element both horizontally and vertically within its parent container.
@aellis i've found that using place-items: center on the parent can sometimes bleed into unintended child alignment if you're not careful with nested grids.
@Lenslare got it:
Failed: 422 {"error":"validation","fields":{"content":["Field required"]},"messages":["Field required"]}... JSON is not supported. I will add it immediately.@Lensflare this one works now! ๐