Skip to content

Instantly share code, notes, and snippets.

View jasdev's full-sized avatar

Jasdev Singh jasdev

View GitHub Profile
@jasdev
jasdev / ScrimLoader.swift
Last active April 19, 2024 03:47
Rough sketch of Arc’s scrim loading view.
import SwiftUI
/**
### Exercises for the viewer
- Phase interrupt handling.
- Use Swift concurrency.
- Color scheme awareness.
- Rework animations to be more spring-like à la what shipped in `0.90.0`.
@jasdev
jasdev / srt_parser.swift
Last active November 15, 2022 20:50
Sketch of an SRT file parser.
import Parsing
import Foundation
// [SubRip file format spec.](https://en.wikipedia.org/wiki/SubRip#File_format)
let sampleSRTString =
"""
1
00:00:00,540 --> 00:00:00,960
Yo-yo
@jasdev
jasdev / geometryPreference.swift
Last active April 24, 2020 19:57
objc.io’s geometryPreference modifier and Preference view for propagating up proxied geometries and reading them.
import SwiftUI
struct Preference<PreferenceKey: SwiftUI.PreferenceKey, Content: View>: View
where PreferenceKey.Value: Equatable {
private let content: (PreferenceKey.Value) -> Content
@State private var value: PreferenceKey.Value = PreferenceKey.defaultValue
init(
_ key: PreferenceKey.Type,
@jasdev
jasdev / final_cancellation_handling.swift
Last active April 20, 2020 16:00
Final `ReplaySubject` and `.Subscription` cancellation handling.
final class ReplaySubject<Output, Failure: Error>: Subject {
typealias Output = Output
typealias Failure = Failure
private let bufferSize: Int
private var completion: Subscribers.Completion<Failure>?
private var isActive: Bool { /* … */ }
@jasdev
jasdev / postfix_type_erasure.swift
Last active March 25, 2020 21:22
Postfix type erasure in Combine.
import Combine
postfix operator ^
postfix func ^ <Publisher: Combine.Publisher>(_ publisher: Publisher)
-> AnyPublisher<Publisher.Output, Publisher.Failure> {
publisher.eraseToAnyPublisher()
}
@jasdev
jasdev / AppDefault.swift
Last active June 14, 2019 10:20
Swift nonmutating Example
import Foundation
enum AppDefault {
case APIServer, runMode, homeDirectory, reactHost
var stringValue: String? {
get {
return NSUserDefaults.standardUserDefaults().stringForKey(String(self))
}
@jasdev
jasdev / paste.txt
Created November 20, 2012 21:11
Keep fighting.
"Sometimes when I find myself comparing myself to others and losing
steam mentally/emotionally, I have to remind myself where I started, the
attitude I had when I began, and how I have already achieved things I never
thought possible and that there is no reason for that to change so long as I
stay committed, balanced, consistent and hungry."
@jasdev
jasdev / CustomCell.swift
Last active July 6, 2018 17:29
An approach to safer UITableViewCell and UICollectionViewCell reuse
class CustomCell: UITableViewCell, Reusable {
class var reuseIdentifier: String {
return "customCell"
}
}
class SupaHotCustomCell: CustomCell {
override class var reuseIdentifier: String {
return "supaHotCustomCell"
}
@jasdev
jasdev / Operation.swift
Created February 15, 2016 03:04
NSOperation Subclass with KVO Notifications
class Operation: NSOperation {
override var asynchronous: Bool {
return true
}
private var _executing = false {
willSet {
willChangeValueForKey("isExecuting")
}
@jasdev
jasdev / FoundationErrorWrapper.swift
Created July 14, 2016 02:05
An attempt at a protocol that can imply the present of specific cases
import Foundation
public protocol FoundationErrorWrapper: ErrorProtocol {
static func wrappingError(_ error: NSError) -> Self
}
enum SomeError: ErrorProtocol, FoundationErrorWrapper {
case a
case wrappingError(NSError)
}