Skip to content

Instantly share code, notes, and snippets.

View GetToSet's full-sized avatar
🍊

Ethan Wong GetToSet

🍊
View GitHub Profile
@gruber
gruber / Save as Text File….scpt
Last active April 25, 2026 05:02
Save MarsEdit Document to Text File
-- Details and explanation:
-- https://daringfireball.net/2026/03/applescript_save_marsedit_document_to_text_file
tell application "MarsEdit"
set _doc to document of window 1
if _doc is not missing value then
-- front window is a document window
set _title to _doc's name
set _blog to _doc's current blog's name
set _tags to _doc's tags
@macguru
macguru / ScopedTask.swift
Last active May 4, 2026 16:34
ScopedTask: A wrapper around Task that auto-cancels when going out of scope.
/// A task that is cancelled if goes out of scope, i.e. the last reference on it has been discarded.
public final class ScopedTask<Success: Sendable, Failure: Error>: Sendable {
/// The underlying task
let wrapped: Task<Success, Failure>
/// Wraps a task into a scoped task.
init(wrapping task: Task<Success, Failure>) {
wrapped = task
}
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,
@krzyzanowskim
krzyzanowskim / FB15131180-extraline.md
Last active April 23, 2026 11:59
FB15131180 TextKit extra line frame is incorrect and does not respect layout fragment size (Regression)

Starting macOS 15/iOS 18 TextKit 2 extra line frame is more broken (height always been broken) than previously. The same code return different values when run on macOS 14/iOS 17 and macOS 15/iOS 18.

The problem is that extra line fragment (NSTextLineFragment) origin and size is incorrect. I sketch the problem with the code snippet below:

// Storage
let textContentManager = NSTextContentStorage()

// Layout
@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 April 22, 2026 17:20
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)