Skip to content

Instantly share code, notes, and snippets.

View T1T4N's full-sized avatar
👽

Robert Armenski T1T4N

👽
View GitHub Profile
@T1T4N
T1T4N / .swiftlint.yml
Last active February 24, 2025 12:17
Default SwiftLint configuration as only_rules
# strict: true
# File organization
# included:
# - Sources
# - Tests
excluded:
- .build
- .swiftpm
- DerivedData
@T1T4N
T1T4N / .swiftformat
Created February 10, 2025 17:00
Default SwiftFormat v0.55.5 rules assembled from the official documentation
--swiftversion 5.9
# Opt-in rule config
--disable all
# Explicitly disabled (opt-in) rules:
# See: https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#acronyms
--disable acronyms
@T1T4N
T1T4N / SendingSelf.swift
Created February 3, 2025 00:01
Fix for "Sending 'self' risks causing data races" in Swift 6
// 1. Decorate the class itself with e.g. @MainActor
// 2. If that isn't possible, here is an example workaround:
deinit {
nonisolated(unsafe) let obj = self
MainActor.assumeIsolated {
obj.dismiss(animated: false)
}
}
@T1T4N
T1T4N / PrintHeapAddress.swift
Created February 3, 2025 00:00
Print heap memory address in Swift
print(Unmanaged.passUnretained(self).toOpaque())
@T1T4N
T1T4N / ScreenAudioRecording.md
Last active December 9, 2024 11:29
Record screen and microphone audio on macOS

Record screen and microphone audio on macOS

This guide shows the steps required to set up a macOS device so that a screen recoding can capture both what the presenter is speaking (via the input device), as well as any system audio (such as conference call questions).

Prerequisities

Setup

@T1T4N
T1T4N / UnsafeSendableBox.swift
Created August 13, 2024 08:10
A generic box type for adding unchecked Sendable conformance to a type
@dynamicMemberLookup
final class UnsafeSendableBox<T>: @unchecked Sendable {
let value: T
init(_ value: T) {
self.value = value
}
subscript<Value>(dynamicMember keyPath: KeyPath<T, Value>) -> Value {
value[keyPath: keyPath]
}
@T1T4N
T1T4N / DispatchMemoryPressure6.swift
Created August 12, 2024 10:19
Swift 6 concurrency-friendly way of monitoring memory pressure
@discardableResult
func logMemoryPressure() -> DispatchSourceProtocol {
// Wrapper class to make DispatchSourceMemoryPressure sendable
final class SendableDispatchMemoryPressureSource: @unchecked Sendable {
let source: any DispatchSourceMemoryPressure
init(_ source: any DispatchSourceMemoryPressure) {
self.source = source
}
func activate() {
@T1T4N
T1T4N / DispatchMemoryPressure.swift
Last active August 12, 2024 10:18
Preconcurrency (Swift 6) way of monitoring memory pressure in Swift
@discardableResult
@preconcurrency func logMemoryPressure() -> DispatchSourceProtocol {
let source = DispatchSource.makeMemoryPressureSource(eventMask: .all, queue: nil)
let queue = DispatchQueue(
label: "com.example.memoryPressure")
queue.async {
source.setEventHandler {
guard !source.isCancelled else { return }
let event = source.data
@T1T4N
T1T4N / UInt+Bits.swift
Last active August 9, 2024 09:52
Add support for manipulating specific bits within an integer by treating it like an array of Bool values
// Source: https://www.douggregor.net/posts/swift-for-cxx-practitioners-extensions/
extension UInt32 {
subscript(index: Int) -> Bool {
get {
(self & UInt32(1) << index) != 0
}
set {
let mask = UInt32(1) << index
self = (self & ~mask) | (newValue ? mask : 0)
@T1T4N
T1T4N / gist:77ccc29445d1bf8e8da87509ddfe9af4
Created July 16, 2024 10:23
Open Microsoft Edge on macOS with a specified Workspace
# Source: https://www.reddit.com/r/MicrosoftEdge/comments/16u0nuf/i_know_how_to_launch_edge_into_a_specific_profile/
cat "$HOME/Library/Application Support/Microsoft Edge/Default/Workspaces/WorkspacesCache"
open -a '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge' --args --profile-directory="ProfileName" --launch-workspace=<workspace-id>