Skip to content

Instantly share code, notes, and snippets.

@dreness
dreness / add_fork_remote.sh
Last active April 24, 2024 18:19
Use gh cli and fzf to add a remote for a fork of the current repo
#!/bin/sh
# Scenario:
# - you have a local checkout of a github repo
# - you're looking at public forks of that repo
# - you want to add a remote to your local checkout for one of the forks
set -e
set PIPEFAIL
#!python -u
import re
from datetime import datetime
import click
import subprocess
import json
"""
NOTE: this requires a log config profile that enables 'private data' logging.
@dreness
dreness / empty-file-in-front-finder-window.scpt
Created April 16, 2024 06:56
Make a new empty file in the front finder window
use scripting additions
use framework "Foundation"
tell application "Finder"
-- path to frontmost Finder window
set windowPath to POSIX path of (target of front window as alias)
-- selected items in Finder, if any
set itemlist to selection as alias list
if length of itemlist > 0 then
repeat with i from 1 to length of itemlist
@dreness
dreness / longtone_finder.py
Last active April 9, 2024 12:58
Extract "long notes" from audio, optimized for speech.
import parselmouth
# import IPython
import os
import sys
import pandas as pd
# Feed me audio files as command line arguments
# uncomment this to stop pandas from being so coy in its repr()s
# pd.set_option("display.max_rows", None, "display.max_columns", None)
@dreness
dreness / favserver.py
Created March 29, 2024 06:49
Favicon Force-feeder
import http.server
import socketserver
import random
import os
import uuid
from http import HTTPStatus
'''
I wanted a quick way to spawn a bunch of Safari tabs with distinct favicons, so made a little webserver
to rotate through some PNGs. A substantially smaller program was sufficient for Chrome, which does what
@dreness
dreness / list_launchd_notifications.sh
Created October 14, 2023 13:14
LaunchEvents -> com.apple.notifyd.matching
find /System/Library/LaunchDaemons /System/Library/LaunchAgents -name "*.plist" \
| while read p ; do plutil -convert json -o - ${p} \
| jq -r ' .. | objects | with_entries(select(.key == "Notification")) | select(. != {}).Notification'
done | sort -u > ~/Desktop/all-launchd-notifications.txt
@dreness
dreness / private-data.mobileconfig
Created February 8, 2024 04:57
enable private data in macOS logs
<?xml version="1.0"encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadDisplayName</key>
<string>ManagedClient logging</string>
<key>PayloadEnabled</key>
@dreness
dreness / powerConsumption.py
Last active January 31, 2024 02:41
Display rate of charge / discharge of an Apple laptop battery
#!python
# To use this, you need Python 3 and also the pyobjc module.
# pip install pyobjc
import objc
from Foundation import NSBundle, NSString
import datetime
import time
import sys
@dreness
dreness / wake_requests.py
Last active January 26, 2024 01:10
Reconstitute the "wake requests" data from `pmset -g log` into a more digestible form
#!python3
import re
import fileinput
import sys
import csv
# 2022-10-31 01:57:27 -0700 Wake Requests [*process=mDNSResponder request=Maintenance deltaSecs=7198 wakeAt=2022-10-31 03:57:25 info="upkeep wake"] [process=powerd request=TCPKATurnOff deltaSecs=316637 wakeAt=2022-11-03 17:54:44] [process=powerd request=UserWake deltaSecs=7850 wakeAt=2022-10-31 04:08:17 info="com.apple.alarm.user-visible-com.apple.CalendarNotification.EKTravelEngine.periodicRefreshTimer,14054"]
# 2024-01-18 18:18:15 -0800 Wake Requests [process=mDNSResponder request=Maintenance deltaSecs=2648 wakeAt=2024-01-18 19:02:23 info="DHCP lease renewal"] [*process=dasd request=SleepService deltaSecs=950 wakeAt=2024-01-18 18:34:05 info="com.apple.dasd:501:com.apple.proactive.ProactiveHarvesting.Harvest.DelayedBudgeted"] [process=powerd request=TCPKATurnOff deltaSecs=316858 wakeAt=2024-01-22 10:19:13] [process=powerd request=CSPNEvaluation deltaSecs=7253 wakeAt=2024-01-18 20:19:08] [process=powerd request=UserWake del
#!/bin/zsh
TARGET=$1
# to be used as an egrep pattern
SYMS='getprogname|NSGetArgv|NSGetArgc|optarg|optind|getopt|getopt_long'
sudo find ${TARGET} -type f -perm +111 \! -name "*.dylib" | \
while read f ; do
sudo nm -u ${f} 2> /dev/null | \