Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Bash Epoch ↔ Human Date Conversion
`date +%s` gives now-as-epoch; `date -d @N` converts an epoch number back to a human date. Often what API responses expect / return.
Bash Convert Between Timezones
Set TZ inline to print a date in a specific timezone, then read with another TZ. Avoids messing with the system timezone.
Bash Add / Subtract Time from Date
GNU date accepts natural-language deltas: "+1 day", "-3 weeks", "now + 2 hours". Combine with -d to compute against any reference date.
Bash Format Date Like a Pro
`date` accepts a format string + optional override of the date being formatted. The +%FT%TZ form gives you ISO-8601 / RFC-3339 in one call.
Bash Wait For Service With Timeout
Block until a TCP port accepts connections, with a deadline. Used everywhere in docker-compose entrypoints — wait for the DB to be ready before running the app.
Bash List Listening Ports
`ss` is the modern netstat — faster, more readable, ships everywhere. Show only listening TCP ports with their owning process.
Bash SSH to Multiple Hosts in Parallel
Run the same command on a fleet of hosts. Three patterns: serial loop (simplest), GNU parallel (fastest), pssh (purpose-built).
Bash DNS Lookup (dig / host / getent)
Three options depending on what's installed: dig is most flexible, host is concise, getent uses the system's resolver and respects /etc/hosts.
Bash Get Public IP Address
Several free services return your public IP as plain text. Useful when scripts running behind NAT need to know what address the outside world sees.
Bash Check If Port Is Open
Several ways to probe a remote port: nc (most portable), bash's /dev/tcp pseudo-device (zero deps), or curl. Pick by what's available.
Bash Unique While Preserving Order
`sort -u` re-orders. `awk '!seen[$0]++'` is the classic order-preserving dedupe — and it's a single line.
Bash Extract JSON Field with jq
jq is the de-facto JSON tool. Pipe any JSON in, get a parsed/filtered/reshaped result out. Indispensable in deploy scripts that consume API output.
Bash Word Frequency Count
Classic shell one-liner: split text into words, sort, count uniques, sort by count. Useful for log analysis, content audits, and tag-cloud-style summaries.
Bash Sort by a Specific Column
Sort takes -k for column-based ordering and -t to set the delimiter. -h sorts human-readable sizes ("1.5G", "300K") correctly.
PHP Random Readable Token
Generate a short, human-readable random token using an alphabet that omits look-alike characters (0/O, 1/l/I). Useful for invite codes, short-lived signin tokens, password reset codes — anything a human might type.
PHP Validate Uploaded File
A defense-in-depth check for $_FILES uploads: confirms the upload completed, the size is within bounds, the MIME type matches an allow-list (by libmagic, not by extension), and the file landed where PHP expected.
PHP Highlight Search Term in Text
Wrap every case-insensitive occurrence of a search term in <mark> tags for quick visual highlighting in search results. Properly escapes HTML so user input cannot inject markup.
Kotlin buildString / buildList / buildMap
Stdlib builders that give you a mutable scope, then return an immutable result. Replaces `StringBuilder().apply { ... }.toString()` boilerplate; the result type is the read-only one.