Skip to content

Instantly share code, notes, and snippets.

@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 January 28, 2024 23:51
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
@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.
@dreness
dreness / animated-prompts.py
Last active January 5, 2023 19:03
stable diffusion animation prompts
#!/usr/bin/env python
import numpy as np
p1 = "portrait of a robot cyberpunk cat,"
p2 = "a cyborg steampunk dog,"
common = "octane render, 8k, high detail, global illumination, artstation, [out of frame]"
blendSteps = 300
f = open('prompts.txt', 'w')
@dreness
dreness / thyme-snippets.md
Last active April 17, 2023 03:25
A bunch of Algodoo script snippets, extracted from public files

... is pretty great. If you somehow arrived here without knowing what Algodoo is, I implore you to go try it right now.

I had a hard time finding good examples of Thyme code on ye interwebs, and this document tries to remedy that. I downloaded a bunch of public compositions by the talented matto and then made a Jupyter notebook to extract interesting Thyme snippets from the project files (which are just zip archives after all). For this purpose, I define "interesting" as:

@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