Skip to content

Instantly share code, notes, and snippets.

View icanzilb's full-sized avatar

Marin Todorov icanzilb

View GitHub Profile
@icanzilb
icanzilb / Result+Task.swift
Created September 14, 2021 15:36
Result initialized with an async operation
extension Result where Failure == Error {
init(_ task: @escaping () async throws -> Success) async {
self = await withCheckedContinuation { [task] continuation in
Task {
do {
continuation.resume(returning: .success(try await task()))
} catch {
continuation.resume(returning: .failure(error))
}
}
@icanzilb
icanzilb / Task.sleep.swift
Created September 9, 2021 09:30
Task.sleep(seconds:)
extension Task where Success == Never, Failure == Never {
/// Suspends the current task for at least the given duration in seconds.
/// Throws if the task is cancelled while suspended.
/// - Parameter seconds: The sleep duration in seconds.
static func sleep(seconds: TimeInterval) async throws {
try await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))
}
}
@icanzilb
icanzilb / gist:ad2b2696fef10e89775fe1fb3dd0d8bd
Created November 23, 2017 11:44
Copy into an issue of your own so you can check issues you've completed
Here's a prioritized list of all available tasks.
The ones marked with [R] are required (e.g. you need to complete before moving on), and the ones marked as [O] are optional (you still have to do them, but they include a direct link to the solution).
- [ ] [R] #1 **Change app window title**
- [ ] [R] #3 **Improve Table UI**
- [ ] [R] #2 **Finish server code**
- [ ] [O] #4 _Change status column width_
- [ ] [O] #5 _Change UI for error rows_
- [ ] [O] #6 _Finilize table UI_
@icanzilb
icanzilb / gist mist
Last active September 3, 2017 06:36
gist mist
0x4eEe2E90cd061E8eC4997cdCf94c348f137DD4F5
@icanzilb
icanzilb / TuplesMeasure
Created July 23, 2014 13:25
Performance test for swapping values with tuples and "old way". Tuples measure constantly better results
import UIKit
import XCTest
class SwapOptimizedTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}