Skip to content

Instantly share code, notes, and snippets.

View GetToSet's full-sized avatar
🍊

Ethan Wong GetToSet

🍊
View GitHub Profile
import SwiftUI
import Combine
// MARK: - onTimer
extension View {
/// Adds an action to perform at specified intervals.
///
/// - Parameters:
/// - interval: The time interval on which to publish events. For example, a value of `0.5` publishes an event approximately every half-second.
@jasonsnell
jasonsnell / countdupes.py
Last active February 8, 2025 22:02
Count Duplicates in List
import subprocess
import re
import sys
from Levenshtein import ratio
from collections import defaultdict, Counter
# Configuration: Adjust as needed
INCLUDE_PARENTHESES = False # Set to True to include parentheticals, False to exclude them
OUTPUT_TO_CLIPBOARD = True # Set to True to copy output to clipboard, False to print to console
@janodev
janodev / waitForExpectation.swift
Last active May 16, 2025 17:13
waitForExpectation
import Foundation
import Testing
func waitForExpectation(
timeout: Duration,
description: String,
fileID: String = #fileID,
filePath: String = #filePath,
line: Int = #line,
column: Int = #column,
@rnapier
rnapier / MainActorRun.swift
Last active September 1, 2025 19:42
Regarding MainActor.run
// In regards to https://mastodon.social/@mattiem/112285978801305971
// MainActor class with synchronous methods
@MainActor final class M {
func methodA() {}
func methodB() {}
}
// Actor that relies on M.
actor A {
@ole
ole / swift-has-feature.sh
Last active August 27, 2025 16:42
swift-list-features: List Swift compiler upcoming and experimental feature flags. If you're using Swift 6.2 or later, `swift -print-supported-features` does something very similar, but only for the compiler version you have installed. · swift-has-feature: Check if a given compiler knows a specific feature flag, and whether it's an upcoming or ex…
#!/bin/zsh
# Test if the Swift compiler knows about a particular language feature.
#
# Usage:
#
# swift-has-feature [--swift SWIFT_PATH] [--language-version LANGUAGE_VERSION] FEATURE
#
# The feature should be an upcoming or experimental language feature,
# such as `"StrictConcurrency"` or `"ExistentialAny"`.
import Foundation
extension MainActor {
/// Invoke `body`, running synchronously if possible.
///
/// This method is equivalent to `Task { @MainActor in <body> }`, except that
/// the first thread hop is elided if the caller is already on the main thread.
/// Thus if `<foo>` has no subsequent thread hops, it can run fully synchronously.
@discardableResult
public static func runAsap<Success>(
# This will respond to keyboard input after either a 12ms delay (capital A) or
# no delay (lowercase a).
# For some reason this causes up to 50ms of difference in Terminal.app.
# Press Ctrl-C to stop.
import os, time, re, tty, termios
try:
old_settings = termios.tcgetattr(0)
tty.setraw(0)
@helje5
helje5 / SwiftUIDataUnitTest.swift
Created August 17, 2023 16:19
Unit Testing a SwiftUI Query
//
// Created by Helge Heß.
// Copyright © 2023 ZeeZide GmbH.
//
import XCTest
import UIKit
import SwiftData
import SwiftUI
@WeZZard
WeZZard / homebrew.distcc.service
Last active January 8, 2025 05:49
Changes to Homebrew distcc installation for being a compilation server.
[Unit]
Description=Homebrew generated unit for distcc
[Install]
WantedBy=default.target
[Service]
Type=simple
ExecStart=/opt/homebrew/opt/distcc/bin/distccd --allow 192.168.50.0/23 --daemon --no-detach
Restart=always
@ole
ole / set-photos-keyboard-shortcuts.sh
Last active May 4, 2024 02:10
Assign a keyboard shortcut to the Export Unmodified Originals menu command in Photos.app on macOS
#!/bin/bash
# Assigns a keyboard shortcut to the Export Unmodified Originals
# menu command in Photos.app on macOS.
# @ = Command
# ^ = Control
# ~ = Option
# $ = Shift
shortcut='@~^e'