Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
final actor Worker: ObservableObject {
@MainActor @Published private(set) var lastWorkDoneAt: Date?
private var counter = 0
func doWork() {
self.counter += 1
DispatchQueue.main.async {
self.lastWorkDoneAt = .now
}
import SwiftUI
struct UnderConstructionModifier: ViewModifier {
func body(content: Content) -> some View {
content
.redacted(reason: .placeholder)
.blur(radius: 8)
.overlay(Color.pink.opacity(0.33))
.overlay(
Text("🚧🚧🚧")
import SwiftUI
@available(iOS, deprecated: 16.0, message: "Use SwiftUI.scrollContentBackground()")
struct HidesScrollContentBackground: ViewModifier {
init() {
if #unavailable(iOS 16.0) {
// beware, affects the app-global appearance proxy:
// UITableView.appearance().backgroundColor = .clear
}
}
import UIKit
let json1 = """
{"results": [{"name": "bob"}]}
""".data(using: .utf8)!
let json2 = """
{"people": [{"name": "Jane"}]}
""".data(using: .utf8)!
import UIKit
enum Item: Codable {
case int(Int)
case string(String)
private enum CodingKeys: String, CodingKey {
case kind
case value
}
@js
js / .gitconfig
Last active May 22, 2019 10:05
fuzzy selection of git branch, files to (un)stage using https://github.com/lotabout/skim
....
[alias]
sel = select
asel = add-select
rsel = reset-select
...
#!/bin/sh
git log --no-walk --date-order --oneline --decorate $(git rev-list --branches --no-walk)
:10000000FFFFFFFFFFFFFFFF012300230060FFFF53
:1000100041F7F1A100000000000000000000000016
:1000200000000000000000000000000000000000D0
:1000300000000000000000000000000000000000C0
:1000400000000000000000000000000000000000B0
:100050000000291E1F20212223242526272D2E2A99
:100060004C0000002B141A0815171C180C12132F23
:1000700030314A00000039041607090A0B0D0E0F33
:10008000333400284E000000E1641D1B06190511E1
:1000900010363738E5524B000000C0E2E3000000A4
//: Playground - noun: a place where people can play
import UIKit
struct Person {
var name = Observable("Bob")
}
enum Event<T> {
case next(T)
@js
js / rx.swift
Last active January 25, 2017 19:57
enum Event<T> {
case next(T)
case error(Error)
case completed
}
final class AnyObservable<T> {
let handler: (@escaping (Event<T>) -> Void) -> Void
init(handler: @escaping (@escaping (Event<T>) -> Void) -> Void) {