Skip to content

Instantly share code, notes, and snippets.

@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}
@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
@joemaller
joemaller / webhook_validate.php
Last active November 20, 2021 12:29
Validate Github webhook signatures with PHP
<?php
$sig_check = 'sha1=' . hash_hmac('sha1', Request::getContent(), $_ENV['github_webhook_secret']);
if ($sig_check === Request::header('x-hub-signature')) { // php >=5.6 and above should use hash_equals() for comparison
// sigs match, do stuff
}
@joemaller
joemaller / pager.js
Created August 18, 2019 21:19
Assistive technology pager for NY State Anti-Sexual Harassment Training https://www1.nyc.gov/site/cchr/law/sexual-harassment-training.page
// Paste this into the console
//
// Why? The site is horribly built and it's very easy to lose your progress and be forced to start over.
wait = () => {
setTimeout(() => {
console.log("tap");
if ($("#Text_Entry_Box_2").length) return;
Array.from($("video")).forEach(v => (v.currentTime = v.duration - 0.25));
const sel = [

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 / 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 / wpa_supplicant.conf
Last active November 8, 2020 22:50
Default wpa_supplicant.conf file for enabling wifi on a headless Raspberry Pi. Working as of 2020-11-08
country=us
update_config=1
ctrl_interface=/var/run/wpa_supplicant
network={
scan_ssid=1
ssid="MyNetworkSSID"
psk="Pa55w0rd1234"
}
@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'