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
| // A URLSession extension that fetches data from a URL and decodes to some Decodable type. | |
| // Usage: let user = try await URLSession.shared.decode(UserData.self, from: someURL) | |
| // Note: this requires Swift 5.5. | |
| extension URLSession { | |
| func decode<T: Decodable>( | |
| _ type: T.Type = T.self, | |
| from url: URL, | |
| keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys, | |
| dataDecodingStrategy: JSONDecoder.DataDecodingStrategy = .deferredToData, | |
| dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .deferredToDate |
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 | |
| typealias Continuation<Ret> = (Ret) -> Void | |
| typealias ContinuationMonad<Value> = (@escaping Continuation<Value>) -> Void | |
| typealias Transform<T,U> = (T) -> ContinuationMonad<U> | |
| func async<Value>(_ wrappedValue: Value) -> ContinuationMonad<Value> { | |
| { $0(wrappedValue) } | |
| } |
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
| extension Array { | |
| func parallelMap<T>(transform: (Element) -> T) -> [T] { | |
| var result = ContiguousArray<T?>(repeating: nil, count: count) | |
| return result.withUnsafeMutableBufferPointer { buffer in | |
| DispatchQueue.concurrentPerform(iterations: buffer.count) { idx in | |
| buffer[idx] = transform(self[idx]) | |
| } | |
| return buffer.map { $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
| import SwiftUI | |
| @MainActor | |
| class PhotoStore: ObservableObject { | |
| @Published private(set) var isSaving: Bool = false | |
| // Made nonisolated because Playgrounds does not run on | |
| // @MainActor. There's probably a cleaner way of doing this | |
| nonisolated init() {} |
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
| // | |
| // BreathAnimation.swift | |
| // breathing-animation | |
| // | |
| // Created by Denise Nepraunig on 17.05.21. | |
| // | |
| // Code is based on this tutorial: | |
| // https://www.youtube.com/watch?v=KUvkJOhpB9A | |
| // Thanks Adam :-) |
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
| extension Color { | |
| /// Return a random color | |
| static var random: Color { | |
| return Color( | |
| red: .random(in: 0...1), | |
| green: .random(in: 0...1), | |
| blue: .random(in: 0...1) | |
| ) | |
| } | |
| } |
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
| // | |
| // Clubhouse.swift | |
| // Playground | |
| // | |
| // Created by Nav Singh on 2/11/21. | |
| // | |
| import SwiftUI | |
| struct Clubhouse: View { |
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
| // | |
| // Lightnings fun | |
| // | |
| // BEWARE highly unoptimized! | |
| // | |
| // Created by Pavel Zak on 30/11/2020. | |
| // | |
| import SwiftUI |
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
| // Modified from @mutsuda's https://medium.com/@mutsuda/create-an-ios-widget-showing-google-spreadsheets-data-856767a9447e | |
| // by @levelsio | |
| // HOW TO | |
| // 1) Make a Google Sheet, we'll pull the first cell e.g. A1 | |
| // 2) Publish your Google Sheet, File -> Publish To Web | |
| // 3) Copy the SHEET_ID in the URL, put it in here below: | |
| const endpoint = "https://spreadsheets.google.com/feeds/cells/SHEET_ID/1/public/full?alt=json" | |
| // 4) Install Scriptable @ https://apps.apple.com/us/app/scriptable/id1405459188 | |
| // 5) Copy this entire script in to Scriptable (tip: you can send it to your iPhone via Whatsapp/Messenger/Telegram etc) |
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
| // | |
| // RotatorView.swift | |
| // | |
| // Created by Pavel Zak on 16/11/2020. | |
| // original idea by: https://twitter.com/beesandbombs/status/1326312738033983489?s=20 | |
| // | |
| import SwiftUI | |
| func pow(_ x: Int, _ y: Int) -> Int { |