Skip to content

Instantly share code, notes, and snippets.

@dreness
dreness / throttle.sh
Last active December 30, 2022 17:59
A script to apply bandwidth limits to specific traffic in OS X using pf and dummynet
#!/bin/bash
# Create a file such as /Users/you/Documents/pftable to hold a list of IPs or subnets to throttle.
# Example file contents:
# 1.2.3.4
# 2.3.4.5/16
# Reset dummynet to default config
dnctl -f flush
@dreness
dreness / logrc
Created November 6, 2022 09:13
logrc config for log(1) in macOS
# ~/.logrc config for log(1) in macOS
show:
--style compact
--color always
--last 4h
stream:
--info
--debug
@dreness
dreness / LSFileInfo example
Last active October 17, 2022 17:51
Interrogate LaunchServices using #PyObjC to query file paths for default app handler, all possible app handlers, and the UTI
xomg% python LSFileInfo.py dylib-map.sqlite
('\n', u'/Users/andre/bin/dylib-map.sqlite')
('UTI: ', u'dyn.ah62d4rv4ge81g6pqrf4gn')
('default app: ', file:///Applications/DB%20Browser%20for%20SQLite.app/)
('all apps: ', (
"file:///Applications/DB%20Browser%20for%20SQLite.app/"
))
@dreness
dreness / kc_items.sh
Last active October 9, 2022 17:08
A hopefully stable listing of identities, keys, and certs found in keychain
#!/bin/bash
function sep { printf -- '-%.0s' {1..80}; echo ''; }
sep ; echo "Identities" ; sep
security find-identity
echo ''
sep ; echo "Keys" ; sep
@dreness
dreness / open_in_background_kinda.scpt
Created October 9, 2022 04:45
This is about as close as I can get to opening an app in the background from AppleScript.
-- can't get `open -g` to work...
tell application "System Events"
set prevApp to name of first process whose frontmost is true
end tell
tell application "mpv" to launch
tell application prevApp to activate
tell application "mpv"
@dreness
dreness / vuo-load-isf-synch.patch
Created October 2, 2022 01:25
In Vuo, load ISF modules synchronously
diff --git a/compiler/VuoCompiler.cc b/compiler/VuoCompiler.cc
index 6f281f04..2c7af1af 100644
--- a/compiler/VuoCompiler.cc
+++ b/compiler/VuoCompiler.cc
@@ -1731,7 +1731,7 @@ set<dispatch_group_t> VuoCompiler::Environment::compileModulesFromSourceCode(con
__block VuoModuleCompilationQueue::Item *queueItem = moduleCompilationQueue->next();
VUserLog("Compiling %s", queueItem->moduleKey.c_str());
- dispatch_async(queue, ^{
+ dispatch_sync(queue, ^{
@dreness
dreness / fix-synalize-it.md
Last active August 14, 2022 14:32
A somewhat brutal repair of Synalize It! Pro for macOS, which is broken by linking against the system-provided python which no longer exists.

check current python linkage

% otool -L /Applications/Synalyze\ It\!\ Pro.app/Contents/MacOS/Synalyze\ It\!\ Pro | grep Python
	/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.16)

Download and install Python2.7.16 for macOS. By default this lands in /Library/Frameworks/Python.framework/Versions/2.7

Make a copy of the Synalize It! Pro app bundle, e.g. to your desktop.

cp -R /Applications/Synalyze\ It\!\ Pro.app ~/Desktop
@dreness
dreness / dns-checkup.md
Created July 25, 2022 07:44
What does macOS or iOS think about YOUR dns server?

Context

macOS (MacBookPro18,2) and iOS (iphone 11 pro) claims the DNS service in my router is flaky, occasionally displaying a dialog accusing me of being offline.

not-online-supposedly

(no, this isn't MaxMSP for iPhone - just a youtube video, settle down...)

This doesn't happen often, but when it does, it's always just after a wake or unlock. The problem is more than cosmetic, though - when it occurs, I am actaully offline on that device until it decides that I'm online again. Usually it doesn't take long, perhaps because I generally don't take this news quietly... OR, maybe recovery is hastened by a background heuristic tasked with mitigating and sharpening the other heuristics, taking a page from the generative adversarial network design... Maybe that sounds far fetched, but I would certainly like to opt into "shake to over-r

@dreness
dreness / yt-over-here.sh
Last active July 11, 2022 03:41
One-liner to open the most recent video in your YouTube watch history
# This is for macOS, and requires that you have yt-dlp and Chrome installed.
# yt-dlp gains easy access to your youtube profile by borrowing cookies from
# Chrome, so you'll need to have logged into youtube with Chrome. The yt-dlp
# command will return the URL to the video at the top of your history, which
# can then be opened using your tool of choice - in this case, I pass it to
# 'open' to use the default browser.
# I use this primarily when I am (or was) watching a YT video on my
# Internet telephone, but then I want to pick it up on the mac.
# This technique is faster for me than anything done from the phone, even if
@dreness
dreness / recent-attachments.sql
Last active June 6, 2022 00:17
Show recent file attachments from Message.app's chat DB
-- sqlite3 ~/Library/Messages/chat.db < recent-attachments.sql
-- dates in the DB are NSDate. NSDate.h says: NSTimeIntervalSince1970 978328800
select
Datetime(
created_date + strftime("%s", "2001-01-01"),
"unixepoch",
"localtime"
) as created,
mime_type,