This file contains 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
public struct Tuple<each T> { | |
public private(set) var value: (repeat each T) | |
public init(_ value: repeat each T) { self.value = (repeat each value) } | |
} | |
extension Tuple { | |
public func map<each U>( | |
_ transform: (repeat each T) throws -> (repeat each U) | |
) rethrows -> (repeat each U) { |
This file contains 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
// Cursed! Do not use! | |
// Supports most, but not all Text initializers. | |
import SwiftUI | |
extension FormatStyle { | |
func format(any value: Any) -> FormatOutput? { | |
if let v = value as? FormatInput { | |
return format(v) |
This file contains 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
struct CycledAnimationTimelineView<Content: View>: View { | |
var duration: Double | |
var isAnimating: Bool | |
@ViewBuilder var content: (Double) -> Content | |
@State private var isActuallyAnimating = false | |
@State private var startDate: Date? | |
var body: some View { | |
TimelineView(.animation(paused: !isActuallyAnimating)) { context in |
This file contains 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 | |
extension View { | |
/// Proposes a percentage of its received proposed size to `self`. | |
/// | |
/// This modifier multiplies the proposed size it receives from its parent | |
/// with the given factors for width and height. | |
/// | |
/// If the parent proposes `nil` or `.infinity` to us in any dimension, | |
/// we’ll forward these values to our child view unchanged. |
This file contains 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 | |
public struct MouseTrackingView: View { | |
public var callbacks: NSMouseTrackingView.Callbacks | |
public var isEnabled: Bool | |
public var options: NSTrackingArea.Options | |
public var hitEnabled: Bool | |
public var flipYAxis: Bool | |
This file contains 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 PlaygroundSupport | |
import SwiftUI | |
PlaygroundPage.current.setLiveView(ContentView()) | |
struct ContentView: View { | |
var body: some View { | |
Color.white.frame(width: 600, height: 800).touchVisualizer() | |
} | |
} |
This file contains 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
// TaskMeeting | |
// (c) 2022, Nikolai Ruhe | |
/// A type that synchronizes progress of two tasks. | |
public final actor TaskMeeting: Sendable { | |
private var completion: CheckedContinuation<Void, Error>? = nil | |
/// This method synchronizes two tasks so that both perform the closure at | |
/// the same time. Both tasks need to call `rendezvous`. | |
/// |
This file contains 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
extension Collection { | |
func parallelMap<T>( | |
parallelism requestedParallelism: Int? = nil, | |
_ transform: @escaping (Element) async throws -> T | |
) async throws -> [T] { | |
let defaultParallelism = 2 | |
let parallelism = requestedParallelism ?? defaultParallelism | |
let n = self.count | |
if n == 0 { |
This file contains 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/sh | |
# make sure you have imagemagick installed: brew install imagemagick | |
# your app_icons.sh file should have the correct permissions: run `chmod 775 app_icons.sh` in your terminal from where you put this file | |
# put your `my_icon.png` next to this file and run ./app_icons.sh to export your app icons | |
x=my_icon.png | |
y=${x%.*} | |
# delete the export directory so we start clean |
This file contains 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 | |
import Combine | |
public struct Event: Identifiable { | |
public let id: FSEventStreamEventId | |
public let path: String | |
public let flags: Flags | |
} | |
public class FileSystemEventStream { |
NewerOlder