Optimize Images
Turn a folder of photos into WebP width variants with ImageMagick. Smaller sources are not upscaled, and existing files are skipped.
Practical snippets you can use freely, each with a short description and a real-world example.
11 results
Turn a folder of photos into WebP width variants with ImageMagick. Smaller sources are not upscaled, and existing files are skipped.
Insert, search, and delete while keeping values sorted. Average O(log n), worst O(n) if the tree becomes a chain.
Wrap a function and reuse its result for the same inputs. The next call with the same values skips the work.
Allow a short burst, then refill tokens at a steady rate. The burst cannot exceed the bucket size.
Keep a fixed number of entries and evict the least recently used item when the cache is full.
An undirected graph: visit in breadth or depth, find the shortest hop path, and detect a cycle without counting the walk back to a parent.
Reuse an idle connection inside the same process, instead of opening a new one for every query.
Run a limited number of jobs at once, retry after a failure, and start the highest priority first.
Store a password as a salted hash, with a pepper from app config. This is not reversible encryption.
Subscribe a listener to an event and call it on emit by priority. once runs a single time.
Find a pattern in text in linear time, using a table of the longest prefix that is also a suffix.
Describe the problem or idea, and I will see if it belongs in the library.