Code Bytes.
Useful code. Written down.
A friendly time-since label with native JavaScript
Format a timestamp as a readable relative-time label, with explicit UTC dates and honest approximate months and years.
Open Code ByteGet a visitor's approximate country with Cloudflare Workers
Read Cloudflare's country metadata at the edge without exposing the visitor's IP address or setting a tracking cookie.
Open Code ByteA small Gulp, Dart Sass and BrowserSync setup
Compile SCSS and refresh a loopback-only local preview with modern Gulp tasks and Dart Sass, without old Ruby Sass plugins.
Open Code ByteShow a small, safe list of links from an RSS feed
Use WordPress's feed parser and cache, handle unavailable feeds, and escape external titles and links before rendering them.
Open Code ByteRedirect old numbered URLs without breaking useful numbers
A tightly scoped Apache rule for a known legacy URL pattern, with checks for collisions, query strings and permanent redirect mistakes.
Open Code ByteStop New Relic injecting browser scripts into WordPress AMP pages
Disable automatic browser instrumentation only on AMP responses without editing a plugin or switching off server-side monitoring.
Open Code ByteUpdate a footer year without document.write
Keep a footer year current using a small JavaScript enhancement or a server-rendered PHP date, with a readable fallback.
Open Code ByteConvert a list of UK dates to Unix timestamps in PHP
Validate day/month/year dates, choose a timezone explicitly and convert a whole list without silently accepting impossible dates.
Open Code ByteHighlight the current navigation link with JavaScript
Match same-site navigation paths with native JavaScript and mark the current page with an active class and aria-current.
Open Code ByteUpdate several columns with PDO and an explicit allowlist
Bind values safely, keep table and column names under application control, and scope every UPDATE to the intended record.
Open Code ByteParse a UK date explicitly instead of guessing with strtotime()
Convert a strict DD/MM/YYYY value into a validated PHP date, reject impossible dates and avoid ambiguous separator tricks.
Open Code ByteFind undersized images with PHP before moving anything
Make a read-only report of small local images, skip invalid files and keep originals intact instead of moving everything that fails a dimension check.
Open Code ByteGenerate a year dropdown in PHP
Build a labelled year select with integer comparisons, a deliberate timezone and validation of a requested selected year.
Open Code ByteBatch-rename files on a Mac with a preview first
A zsh rename plan that preserves extensions, ignores directories and symlinks, and refuses existing destinations before moving any files.
Open Code ByteAnimate a progress display without inventing progress
Give a known percentage a small visual entrance, keep its value accessible and distinguish a demonstration from real upload or task progress.
Open Code ByteMove WordPress to HTTPS without redirect loops
Establish working TLS, update the correct WordPress addresses and add HTTPS redirects in the layer that actually terminates the connection.
Open Code ByteKeep Google Maps from hijacking page scrolling
Configure cooperative gestures in the Google Maps JavaScript API instead of guessing touch devices from screen width.
Open Code ByteReplace HTTP URLs safely in a WordPress database
Preview an exact-domain HTTPS replacement with WP-CLI, preserve serialized values and avoid a blanket database-wide SQL update.
Open Code ByteShare heading styles with CSS or a Sass range helper
Style h1–h6 with a low-specificity CSS selector, or generate a validated heading range with a small non-recursive Sass function.
Open Code ByteCount up from a date with JavaScript
Display elapsed days, hours, minutes and seconds from an explicit timestamp, with independent timer state, pause/resume and cleanup.
Open Code ByteMark the current navigation link in PHP
Render accessible active navigation from a small PHP route list, using exact path matching and escaped output instead of parsing HTML strings.
Open Code ByteReturn a proper 503 maintenance page with Apache
Show a self-contained maintenance page with the correct HTTP status and retry guidance, without redirecting every visitor to a misleading success page.
Open Code ByteAdd a trailing slash only where your routes expect one
Normalise selected page URLs with Apache without adding slashes to assets, APIs, unknown paths or payment callbacks.
Open Code ByteFind duplicate values with a JavaScript Map
Count exact duplicate IDs in one pass, preserve meaningful leading zeroes and show a readable result without constructing selectors from input.
Open Code ByteValidate a numeric input without blocking typing
Let people type, paste and edit normally, then validate a clearly defined decimal format with accessible feedback and server-side checks.
Open Code ByteKeep one static directory outside a CMS's Apache rewrites
A precise Apache rewrite exception for a standalone directory, with path-boundary matching and a clear distinction from redirects and access control.
Open Code ByteRedirect an old domain while keeping its page paths
Move an Apache-hosted domain to a fixed HTTPS destination, preserve useful URLs and test before making redirects permanent.
Open Code ByteList approved files from a directory with PHP
Build a small public download list with a fixed directory, an extension allowlist, escaped labels and no hidden files or symlink traversal.
Open Code ByteJustify the last line of text with CSS
Use text-align-last instead of a pseudo-element spacer, and keep justification limited to places where the spacing remains readable.
Open Code ByteRefresh one part of a page with fetch
Poll a small same-origin JSON endpoint without overlapping requests, keep the last good value on failure and stop cleanly when the view is removed.
Open Code ByteCount down to a date with plain JavaScript
Build an independent countdown with an explicit UTC deadline, a finished state, start/pause controls and cleanup instead of shared timer state.
Open Code ByteReveal an element on scroll with Intersection Observer
Add a short, once-only entrance when an element reaches the viewport, with visible content by default and a reduced-motion fallback.
Open Code ByteDownload a password-protected file safely with PHP cURL
Fetch a fixed HTTPS resource with HTTP Basic authentication, bounded response size and timeouts, then save without overwriting an existing file.
Open Code ByteSort a WordPress post list without replacing the main query
Use a separate WP_Query for an alphabetical list, escape its output and restore the original post context afterwards.
Open Code ByteGenerate nth-child rules with a Sass for loop
Use a small SCSS loop for a deliberate sequence of styles, understand through versus to, and avoid generating unnecessary CSS.
Open Code ByteDisplay a Facebook Page count without relying on the old public endpoint
Why the anonymous Facebook likes snippet is no longer a sound integration, and how to render an authorised, cached count safely.
Open Code ByteFind text between HTML tags in Sublime Text
Use a scoped regular-expression search for simple HTML edits, with examples for heading text and multiline comments and clear limits.
Open Code ByteKeep your WordPress team's visits out of analytics
Exclude editorial users at the tracking integration, check caching and consent, and avoid reviving the retired Universal Analytics script.
Open Code ByteGet out of Vim command mode in Sublime Text
Return to normal typing in Sublime Text's Vintage mode, or disable Vintage while preserving your other editor settings.
Open Code Byte