Skip to content

Instantly share code, notes, and snippets.

//
// BoundedQueue.swift
//
// Copyright © 2017 Doug Russell. All rights reserved.
//
import Foundation
public class BoundedQueue {
private let group = DispatchGroup()
class Foo {
var body: some View {
...
}
}
class Bar: Foo {
override var body: some View {
...
}
public extension Publisher {
/// Assigns each element from a Publisher to a property on an object.
///
/// - Parameters:
/// - keyPath: The key path of the property to assign.
/// - object: The object on which to assign the value.
/// - Returns: A cancellable instance; used when you end assignment of the received value. Deallocation of the result will tear down the subscription stream.
func assignResult<Root>(to keyPath: ReferenceWritableKeyPath<Root, Result<Self.Output, Self.Failure>>,
on object: Root) -> AnyCancellable {
sink(receiveCompletion: { completion in
@propertyWrapper
struct ErasedToAnyPublisher<Upstream: Publisher> {
var wrappedValue: AnyPublisher<Upstream.Output, Upstream.Failure> {
upstream.eraseToAnyPublisher()
}
let upstream: Upstream
init(upstream: Upstream) {
self.upstream = upstream
}
}
protocol Example {
associatedtype Value
func value() -> Value
}
struct AnyExample<Value> {
private class Container<Value> {
func value() -> Value {
fatalError()
}
import Foundation
/*
Somewhere in Foundation
public protocol Foo {
...
public init<T>?(foo value: T) where T: Foo
...
}
@available(iOS 16.0, macOS 13.0, watchOS 9.0, *)
@propertyWrapper
public struct AsyncPublished<Value> {
@available(*, unavailable, message: "@AsyncPublished is only available on properties of classes")
public var wrappedValue: Value {
get { fatalError() }
set { fatalError() } // swiftlint:disable:this unused_setter_value
}
public let projectedValue: AsyncStream<Value>
public init(initialValue: Value) {
@rustle
rustle / stale.sh
Last active October 16, 2025 01:19
print table of git branches from remote that haven't been updated in two weeks
#!/bin/sh
REMOTE=$1
REMOTE=${REMOTE:=$(git remote | sed '1s/\s.*$//p')}
TWO_WEEKS_AGO=$(date -v -2w "+%s")
git fetch --prune $REMOTE
printf "\e[1;40;37m| %-45s | %-30s | %-30s |\e[0m\n" "Branch" "Author" "Date"
git for-each-ref \
--sort=committerdate \