Skip to content

Instantly share code, notes, and snippets.

@pronebird
pronebird / DumpPlistTextSection.swift
Created September 15, 2025 12:59
Playground for dumping text section with __launchd_plist
import Cocoa
import MachO
if let handle = dlopen("/Applications/App.app/Contents/MacOS/some.helper.binary", RTLD_LAZY) {
defer { dlclose(handle) }
if let ptr = dlsym(handle, MH_EXECUTE_SYM) {
let mhExecHeaderPtr = ptr.assumingMemoryBound(to: mach_header_64.self)
var size: UInt = 0
@pronebird
pronebird / Cargo.toml
Created August 18, 2025 09:52
Rust: udp SO_REUSEADDR tester
[package]
name = "udpbind"
version = "0.1.0"
edition = "2024"
[dependencies]
nix = { version = "0.30.1", features = ["net"] }
anyhow = "*"
@pronebird
pronebird / stack-size.rs
Last active July 26, 2025 14:27
Rust: get stack size in bytes on Windows
fn get_stack_size() -> usize {
let mut low: usize = 0;
let mut high: usize = 0;
unsafe {
windows::Win32::System::Threading::GetCurrentThreadStackLimits(
&mut low as _,
&mut high as _,
)
};
high - low
@pronebird
pronebird / print-struct-byte-by-byte.rs
Created March 4, 2024 12:45
Print rust struct byte by byte
unsafe fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
::core::slice::from_raw_parts(
(p as *const T) as *const u8,
::core::mem::size_of::<T>(),
)
}
let bytes: &[u8] = unsafe { any_as_u8_slice(&req) };
for byte in bytes {
print!("{:02x} ", byte);
@pronebird
pronebird / NSAttributedString+BasicMarkdown.swift
Last active May 26, 2023 12:36
Basic markdown support for attributed string
import UIKit
import PlaygroundSupport
extension NSAttributedString {
enum MarkdownElement {
case paragraph, bold
}
struct MarkdownStylingOptions {
var font: UIFont
@pronebird
pronebird / NENWPath+Private.swift
Created March 2, 2023 10:56
NetworkExtension NWPath private extension to obtain interface name
import NetworkExtension
extension NetworkExtension.NWPath {
var interfaceName: String? {
let interface = self.value(forKeyPath: "_internalPath.direct") as? nw_interface_t
return interface.map { String(cString: nw_interface_get_name($0)) }
}
}
@pronebird
pronebird / UIPresentationController+Private.swift
Created January 19, 2023 11:29
Private notifications posted by UIPresentationController
extension UIPresentationController {
static let presentationTransitionWillBegin = Notification.Name(
"UIPresentationControllerPresentationTransitionWillBeginNotification"
)
static let presentationTransitionDidEndNotification = Notification.Name(
"UIPresentationControllerPresentationTransitionDidEndNotification"
)
static let dismissalTransitionWillBeginNotification = Notification.Name(
@pronebird
pronebird / FormsheetPresentationController.swift
Last active August 30, 2022 07:37
Custom formsheet presentation
class FormsheetPresentationController: UIPresentationController {
private static let dimmingViewOpacityWhenPresented = 0.5
private var isPresented = false
private let dimmingView: UIView = {
let dimmingView = UIView()
dimmingView.backgroundColor = .black
return dimmingView
}()
@pronebird
pronebird / bulk-convert-video.sh
Last active September 6, 2024 18:16
Convert videos in bulk to H264 baseline/YUV420p, preserve metadata and sanitize filenames
caffeinate &
CAFFEINATE_PID=$!
for FILE in *.mkv; do
OUTPUT=$(echo $FILE | sed -r "s/[ ]*[\.-\(]?(480p|720p|1080p|WEB|576p|HDTV|Xvid).*(\.[a-z4]+)$/\2/I")
if [ "$OUTPUT" = "$FILE" ]; then
OUTPUT=$(echo $OUTPUT | sed -r "s/(\.[a-z4]+)$/.converted\1/I")
fi
@pronebird
pronebird / UnfairLock.swift
Created March 2, 2022 12:56
Wrapper type for os_unfair_lock
class UnfairLock: NSLocking {
private var _lock = os_unfair_lock()
func lock() {
os_unfair_lock_lock(&_lock)
}
func unlock() {
os_unfair_lock_unlock(&_lock)
}