This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- === ScreenConfigNotifier === | |
--- | |
--- Displays a local notification when the screen configuration changes. | |
--- | |
--- With some modifications, this can be used as the basis for triggering | |
--- other actions when the screen config changes. | |
--- Usage: | |
--- 1. Save this file as `OleScreenConfigNotifier.spoon/init.lua` in your Hammerspoon config folder. | |
--- 2. In your root `init.lua`, add these lines: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension Thread { | |
/// Helper for debugging (because Thread.current is noasync) | |
static var currentThread: Thread { | |
current | |
} | |
} | |
nonisolated class NonSendable { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// swift-tools-version: 6.0 | |
// The swift-tools-version declares the minimum version of Swift required to build this package. | |
import PackageDescription | |
let package = Package( | |
name: "MyPackage", | |
products: [ | |
.library(name: "MyLibrary", targets: ["MyLibrary"]), | |
], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func inheritCallerIsolation( | |
isolation: isolated (any Actor)? = #isolation, | |
// Closure executes on different threads, depending on attributes | |
operation: () async -> Void | |
// operation: @Sendable () async -> Void | |
// operation: @isolated(any) () async -> Void | |
// operation: @isolated(any) @Sendable () async -> Void | |
) async { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://adventofcode.com/2024/day/13 | |
import AppKit | |
// Button A: X+94, Y+34 | |
// Button B: X+22, Y+67 | |
// Prize: X=8400, Y=5400 | |
let X: CGFloat = 8400 | |
let Y: CGFloat = 5400 | |
let x_a: CGFloat = 94 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Overload for tuple values. | |
func tupleLength<each T>(_ tuple: (repeat each T)) -> Int { | |
var count = 0 | |
for _ in repeat (each tuple) { | |
count += 1 | |
} | |
return count | |
} | |
tupleLength(()) // → 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make sure both the string and the substring are larger than 15 UTF-8 bytes | |
// to avoid the small string optimization | |
var str = "Hello world 1 Hello world 2 Hello world 3 Hello world 4 Hello world 5 Hello world 6 Hello world 7 Hello world 8 Hello world 9" | |
let prefixToStrip = 14 | |
var substr = str.dropFirst(prefixToStrip).prefix(27) | |
let strToAppend = "+++APPENDED+++" | |
// ⚠️ It makes a difference how you mutate the Substring: | |
// - substr.append → Apparently makes a copy of the entire original string | |
// *and* even shifts the original string contents back to make room, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
@main | |
struct GroupWithTaskApp: App { | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/// An "extension" of FloatingPointFormatStyle that adds a `minusSign` API to customize | |
/// the character(s) used as the minus sign. | |
/// | |
/// You could add additional extensions by following the same pattern. | |
/// | |
/// All other APIs are copied from FloatingPointFormatStyle and forward to it for their | |
/// implementation. This isn’t a full replica of the FloatingPointFormatStyle API, though, | |
/// because it’s only intended as a proof of concept. |
NewerOlder