Skip to content

Instantly share code, notes, and snippets.

@joemaller
joemaller / setup.sh
Last active October 21, 2023 16:40
Helper script for installing apps on a new Mac
#!/usr/bin/env bash
# Download this file then run:
# % chmod a+x setup.sh
# % ./setup.sh
# Or run directly from this Gist:
# % curl https://gist.githubusercontent.com/joemaller/55aca1bcffe44558cf93527153d6896a/raw/setup.sh | bash
# Install Homebrew first https://brew.sh
set -u
@joemaller
joemaller / attributes.md
Last active February 6, 2022 17:15
Out of deference to Prettier, I'm switching to filling empty attributes

Previously, for "cleaner HTML" I tended to prefer something like this:

<?php 
$classes = ['cat', 'dog'];
$classAtt = empty($classes) ? "" : " class='" . implode($classes, ' ') . '"'; 
?>
<div<$= $classAtt ?>>Text</div>

That string concatenation is just gross, but the HTML is "nicer"; the opening tag will either be or.

@joemaller
joemaller / resize safari.applescript
Last active January 18, 2022 03:53
AppleScript snippet to resize the front-most Safari window to a given size
tell application "Safari" to set the bounds of the front window to {0, 0, 1600, 1080}

Three package-lock.json files generated by node v14.16.0 and npm v6.14.11 on macOS, Ubuntu and Windows. Windows and macOS generated an identical file, Ubuntu omitted two optional packages, bindings and file-uri-to-path.

As expected, npm ci installs an exact snapshot from package-lock.json, so installing from the ubuntu-generated lockfile on mac or windows will not install those packages. Doing the opposite and installing from the mac/windows lockfiles on Ubuntu causes no issues since the optional packages are not needed.

Source project is ideasonpurpose/docker-build, docker-based build tools primarily for developing WordPress sites.

WordPress Admin Menu Indexes

WordPress Admin menus are populated from a global $menu variable which is only generated in admin contexts. Items can be added or re-ordered from the admin_menu action.

This is the default order:

  1. Dashboard
  2. wp-menu-separator
  3. Posts
@joemaller
joemaller / crontab
Last active November 2, 2023 13:38
Example cron task for auto-removing old downloads on macOS Big Sur and Catalina
# Cron on modern macOS systems (10.14+) requires Full Disk Access permissions
# in System Preferences->Privacy & Security. To enable this, drag the cron
# binary from /usr/sbin/cron into the Full Disk Access list.
# More here: https://apple.stackexchange.com/a/372810/42898
# https://gist.github.com/joemaller/c4c0a6000ac53c8b1a70ff66c547380a
# Removes downloads older than 14 days. Runs every 6 hours
45 */6 * * * echo "$(date)\nRemoving downloads older than 14 days (cron)" >> /tmp/cron.log
45 */6 * * * find ~/Downloads -maxdepth 1 -mtime +14 -exec du -sh {} \+ | sort -rh >> /tmp/cron.log
46 */6 * * * find ~/Downloads -maxdepth 1 -mtime +14 -exec rm -rf {} \; >> /tmp/cron.log 2>&1
@joemaller
joemaller / WufooEndpoint.php
Last active December 1, 2020 17:29
A class for creating a WordPress rewrite rule to serve a stylesheet from a persistent top-level url
<?php
namespace IdeasOnPurpose;
/**
* This class created a nice little persistent endpoint for an
* externally referenced stylesheet. This was necessary because
* our themes are versioned with each release living in a different-
* named directory. All assets are also generated by Webpack and
* have hashed filenames.
@joemaller
joemaller / ip-address-log.sh
Last active October 10, 2020 18:53
Script for logging IP address changes. Checked with shfmt: `docker run --rm -it -v "$PWD":/src peterdavehello/shfmt shfmt -i 2 -w /src/ip-address-log.sh`
#! /usr/bin/env bash
# Stop on errors, unset vars and broken pipes
set -o errexit
set -o nounset
set -o pipefail
LOG_FILE=${1:-}
if [ -z "$LOG_FILE" ]; then
echo "Please provide a logfile as the first argument"
@joemaller
joemaller / inotifywait
Created August 28, 2020 02:00
inotifywait docker command
docker run -it -v $PWD:/app alpine sh -c 'apk --no-cache add inotify-tools; inotifywait -m --format "%e %f" /app'
@joemaller
joemaller / macos-onedrive-migration.sh
Created June 17, 2020 20:27
Rename commands for migrating a macOS fileserver to Microsoft OneDrive
#! /usr/bin/env bash
# This is a small collection of helper commands for migrating a legacy macOS fileserver
# to OneDrive/Sharepoint. Filenames on cloud platforms are more restrictive than macOS, so
# a large number of files needed renaming before they could be synced to the Microsoft Cloud.
# 1. Use the rename CLI tool. It's installed by default on Debian/Ubuntu but needs to be
# installed on macOS and some other platforms. More here: http://plasmasturm.org/code/rename/
brew install rename