Inserts a row or updates it if a conflict on a unique key occurs. A clean pattern for syncing external data without duplicate errors (PostgreSQL syntax).
INSERT INTO products (id, name, price)
VALUES (42, 'Widget Pro', 19.99)
ON CONFLICT (id) DO UPDATE SET
name = EXCLUDED.name,A typed utility that wraps the Fetch API with error handling and JSON parsing, returning a structured result or error object.
async function fetchJSON<T>(
url: string
): Promise<{ data: T | null; error: string | null }> {
try {Recursively flattens a deeply nested list into a single flat list using Python's built-in generator pattern.
def flatten(lst):
for item in lst:
if isinstance(item, list):
yield from flatten(item)Delays execution of a function until after a specified wait time has elapsed since the last call. Useful for search inputs and resize events.
function debounce(fn, wait) {
let timer;
return (...args) => {
clearTimeout(timer);