Skip to content

Instantly share code, notes, and snippets.

#!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 / 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 / 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 / add_fork_remote.sh
Last active May 4, 2024 08:31
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 -o pipefail
@dreness
dreness / batch-transcribe-whisper.py
Created November 27, 2023 01:31
Batch audio transcription with whisper.cpp
#!python
"""
Configure the arguments to the process_directory call at the bottom.
Start additional instances of this script until your hw is full. If you
have multiple GPUs, you're responsible for setting CUDA_VISIBLE_DEVICES.
Using the 'medium' model, a V100 is mostly utilized with two instances.
This still has some bugs probably...
"""
@dreness
dreness / powermetrics_reader.py
Created November 20, 2023 11:40
Extract just one data point from powermetrics, suitable for graphing
#!python -u
import subprocess
import plistlib
import sys
"""
Print selected power metrics from /usr/bin/powermetrics at intervals, suitable
for graphing.
"""
@dreness
dreness / pidpersec.c
Last active November 20, 2023 11:42
pidpersec.c
/*
By Andre LaBranche, with extensive help from your friend and mine, ChatGPT.
In other words, assume this code eats babies.
This program attempts to be a reasonably inexpensive replacement for
/usr/bin/pidpersec.d in macOS, which still ships, but is broken by default
(i.e. when SIP is enabled).
compile with: clang -o pidpersec pidpersec.c
*/
@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 / transcribe.sh
Created February 11, 2023 08:29
Batch-transcribe audio files with whisper.cpp
#!/bin/zsh
#
# Batch transcribe audio files with whisper.cpp and ffmpeg
# This script wants:
# - ffmpeg installed and accessible via $PATH
# - whisper.cpp built locally:
# git clone https://github.com/ggerganov/whisper.cpp
# cd whisper.cpp
# make
# The compiled binary will be called 'main' in the whisper.cpp directory.