Skip to content

Instantly share code, notes, and snippets.

@fruitcoder
fruitcoder / AsyncStreamNotSendable.swift
Last active August 2, 2024 11:00
Trying to add a timeout functionality to AsyncStream fails because AsyncStream isn't Sendable
extension AsyncSequence where Self.Element : Equatable & Sendable {
func first(
_ search: Self.Element,
timeout: TimeInterval = 1.0
) async throws {
do {
try await _until(where: { $0 == search }, timeout: timeout)
} catch is CancellationError {
print("cancelled before element was emitted or timeout was reached.")
throw CancellationError()
@fruitcoder
fruitcoder / TestHelpers.swift
Created August 1, 2024 16:36
Trying to make a timeout work for Swift 6
final actor ActorIsolatedExpectation<Value: Sendable & Equatable> {
/// The actor's expected value
let expectedValue: Value
/// The actor's current value (initially `nil`)
var currentValue: Value?
let id = UUID()
/// Initializes the actor with an expexted value.
@fruitcoder
fruitcoder / CA+Extensions.swift
Last active September 17, 2021 16:23
Returns the simulator drag coefficient when Slow Animations are enabled, otherwise (and non simulator builds) 1.0
import UIKit
#if targetEnvironment(simulator)
@_silgen_name("UIAnimationDragCoefficient") func UIAnimationDragCoefficient() -> Float
func simulatorDragCoefficient() -> CFTimeInterval {
let drag = UIAnimationDragCoefficient()
if drag > 1 {
return CFTimeInterval(drag)
}
return 1
@fruitcoder
fruitcoder / wait_for_ios_version.rb
Last active September 14, 2018 13:42
This script waits for a new version and sends a local notification via AppleScript when it's available on the App Store
#!/usr/bin/ruby
# It's so annoying that the 'Ready for Sale' status on AppStoreConnect doesn't mean that the app
# is available for your users, since the cache might not have been invalidated yet.
# This is why I created this script to run and scrape the App Store page of an app and its currently live version.
# Once the expected version is live, a local notification is sent. This can be easily extended to send a Slack message via a web hook.
require 'open-uri'
require 'nokogiri'
@fruitcoder
fruitcoder / gist:e3895060644d35b1b7c55bb87ce8919e
Created December 2, 2016 11:09
Adding loading and reloading UI to everything owning a UIView
````
import UIKit
import Foundation
public protocol LoadStateIndicating {
/// Shows a blur view over the current context with an animated activity indicator.
func startLoading()
/// Hides blur view and activity indicator.
func stopLoading()