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
/// Runs a secondary side action concurrently with a primary action. | |
/// The secondary action only starts after the specified delay. | |
/// | |
/// Usage example: showing a progress indicator UI only if the primary action | |
/// takes a significant amount of time. | |
/// | |
/// The secondary action runs in a child task (structured concurrency). | |
/// | |
/// - Note: I'd like to provide a default argument for the clock: `clock: C = .continuous`, | |
/// like `Task.sleep` does. But this doesn't compile in Swift 6.2. Related bug report: |
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/bash | |
# List Swift diagnostic groups. | |
# | |
# Author: Ole Begemann | |
# | |
# Usage: | |
# | |
# swift-list-diagnostic-groups [version] # default: main branch | |
# |
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
#!/usr/bin/env fish | |
# Swaps the staged and unstaged changes. | |
# | |
# Useful if you want to make and commit a large-ish change B while you're | |
# in the middle of another change A (which you don't want to commit yet). | |
# | |
# Assumptions: | |
# | |
# - The changes for A are staged. |
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 Observation | |
protocol P: AnyObject, Observable { | |
var value: Int { get set } | |
} | |
@Observable | |
class MyObject: P { | |
var value: Int = 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
--- === 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 |
NewerOlder