Skip to content

Instantly share code, notes, and snippets.

@pudquick
pudquick / color_change.sh
Created March 28, 2023 19:57
Change color in Terminal tab depending on current working directory in zsh
# put this in your .zshrc
function background_danger_color_change() {
case $PWD/ in
/Users/frogor/dangerous/*)
# uh oh, be careful in here
osascript<<END
tell application "Terminal"
get the background color of the selected tab of the front window
if the result is not equal to {65535, 0, 0} then
set the background color of the selected tab of the front window to {65535, 0, 0}
@pudquick
pudquick / 00-reproducible-mach-o.md
Last active May 17, 2024 04:24
Reproducible Builds for macOS

Reproducible Builds for macOS

There's a neat writeup I stumbled across recently titled "Reproducible codesigning on Apple Silicon" from Keith Smiley about some gotchas when it comes to compiling a binary in a way that's repeatable and always generates the exact same byte output (which would then checksum to the exact same hash) - even if compiled on a different Mac.

In applying the suggestions I found in the blog post, I found a few other corner cases that I just wanted to get documented more explicitly somewhere.

Tools Matter

Footnote 2 from that blog post is important:

@pudquick
pudquick / self_signed.sh
Last active April 2, 2024 21:04
Non-interactive self-signed unencrypted keypair generation for HTTPS for arbitrary domain with SAN
# Make a self-signed private/public keypair usable for HTTPS, including SAN / Subject Alternative Name and CN / Common Name, non-interactively and without additional files
# Parentheses around the command spin it up in a subshell so that the FQDOMAIN variable is local to execution and doesn't persist after it's created
(FQDOMAIN="example.local" && openssl req -x509 -nodes -newkey rsa:4096 -keyout server_key.pem -keyform PEM -days 365 -subj "/CN=${FQDOMAIN}" -addext 'basicConstraints=CA:FALSE' -addext "subjectAltName=DNS:${FQDOMAIN}" -addext 'keyUsage=digitalSignature' -addext 'extendedKeyUsage=serverAuth' -out server_cert.pem -outform PEM 2>/dev/null)
# Alternatively, if you're setting FQDOMAIN somewhere else, you can just run directly:
openssl req -x509 -nodes -newkey rsa:4096 -keyout server_key.pem -keyform PEM -days 365 -subj "/CN=${FQDOMAIN}" -addext 'basicConstraints=CA:FALSE' -addext "subjectAltName=DNS:${FQDOMAIN}" -addext 'keyUsage=digitalSignature' -addext 'extendedKeyUsage=serverAuth' -out server_
@pudquick
pudquick / sublime_session.py
Last active January 4, 2023 18:39
Split Sublime Text saved .sublime_session into separate text files in the current working directory
import uuid, json
def find_all_keys(key, var):
if hasattr(var,'items'):
for k, v in var.items():
if k == key:
yield v
if isinstance(v, dict):
for result in find_all_keys(key, v):
yield result
@pudquick
pudquick / steamdeck_scripts.md
Last active May 20, 2024 12:27
Running shell scripts easily in Gaming mode on Steam Deck

Running shell scripts easily in Gaming mode on Steam Deck

(Alternatively: "How I stopped using Syncthing on Steam Deck")

Disclaimer: As the title implies, this is about shell scripting on your Steam Deck. The guide won't teach you how to do that part, it assumes you already have ideas in mind about what scripts you'd want to write. Stopping the usage of Syncthing was what I wanted to do with it, but you can do whatever you like.

Background (you can skip this part)

If you're an avid gamer who picked up a Steam Deck and now you're splitting your time between it and a more traditional gaming computer (or in my case, several other gaming systems as well), you may come across a situation where at some point you want to start doing more advanced things on your Steam Deck - which may mean "how do I get files onto or off of this thing".

@pudquick
pudquick / brew.md
Last active June 11, 2024 22:02
Lightly "sandboxed" homebrew on macOS

brew is a bad neighbor

This isn't a guide about locking down homebrew so that it can't touch the rest of your system security-wise.

This guide doesn't fix the inherent security issues of a package management system that will literally yell at you if you try to do something about "huh, maybe it's not great my executables are writeable by my account without requiring authorization first".

But it absolutely is a guide about shoving it into its own little corner so that you can take it or leave it as you see fit, instead of just letting the project do what it likes like completely taking over permissions and ownership of a directory that might be in use by other software on your Mac and stomping all over their contents.

By following this guide you will:

  • Never have to run sudo to forcefully change permissions of some directory to be owned by your account
@pudquick
pudquick / steamdeck.md
Last active July 11, 2023 17:44
Steam Deck notes

Steam Deck Notes


Running scripts in Gaming mode easily

This became its own writeup: https://gist.github.com/pudquick/981a3e495ffb5badc38e34d754873eb5

Artwork on non-Steam games

There's several different kinds of art that can be configured for an entry. The only real place to configure them all is from Desktop mode, not Game mode.

@pudquick
pudquick / arch_fix.sh
Created December 16, 2021 23:51
Fix python.org uiversal 2 python 3 packages so they don't trigger Rosetta 2 installs on Apple silicon
#!/bin/zsh
function cleanup {
if [ ! -z "$TMPD" ]; then
rm -rf "$TMPD"
fi
}
trap cleanup EXIT
if [ "$#" -eq 0 ]; then
@pudquick
pudquick / 01_helper.h
Last active August 4, 2021 02:57
Calling a non-external local C function (dlsym does not resolve it) with ctypes in python (or by using an address directly)
// helper.h
// two functions in this dylib - helper and helpersecret
void helper();
void helpersecret();
@pudquick
pudquick / findpboard.py
Created January 30, 2021 00:37
Get / Set shared Find Pasteboard state on macOS via pyobjc
from AppKit import NSPasteboard, NSFindPboard, NSStringPboardType, NSString
def get_fboard():
fboard = NSPasteboard.pasteboardWithName_(NSFindPboard)
if NSStringPboardType in fboard.types():
return fboard.stringForType_(NSStringPboardType)
def set_fboard(findstr):
fboard = NSPasteboard.pasteboardWithName_(NSFindPboard)
fboard.declareTypes_owner([NSStringPboardType], None)