Skip to content

Instantly share code, notes, and snippets.

View mattadatta's full-sized avatar

Matthew Brown mattadatta

  • Ottawa, ON, Canada
View GitHub Profile
(ns util.bitwise)
(declare s->u)
(defn <<
[x n]
(s->u (bit-shift-left (s->u x) n)))
(defn >>
[x n]
import Foundation
import CoreText
struct FontUtils {
enum Error: Swift.Error {
case dataProviderConstructionFailed
case cgFontConstructionFailed
case postScriptNameUnavailable
//
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
//
import SwiftUI
import UIKit
struct UIKitTextField : UIViewRepresentable {
import RxSwift
public extension ObservableType {
public func bufferLatest<O: ObservableConvertibleType>(maxConcurrent: Int = 1, _ selector: @escaping (E) throws -> O) -> Observable<O.E> {
return Observable<O.E>.create { observer in
return SingleElementBufferLatest(
source: self.asObservable(),
observer: observer,
selector: selector,
@mattadatta
mattadatta / Anonymous.swift
Last active September 10, 2020 23:48
Rx's Observable.create -> Swift Combine "Anonymous"
import Foundation
import Combine
struct Anonymous<Output, Failure> : Publisher where Failure : Error {
var onSubscribe: (Observer) -> Cancellable
func receive<S>(subscriber: S) where Output == S.Input, Failure == S.Failure, S : Combine.Subscriber {
subscriber.receive(subscription: Sink(parent: self, downstream: subscriber))
}
@mattadatta
mattadatta / CollectionView.swift
Last active January 8, 2024 23:18
UIKit's UICollectionView implemented in SwiftUI using UIViewControllerRepresentable
//
// (See usage below implementation)
//
// SwiftUI `CollectionView` type implemented with UIKit's UICollectionView under the hood.
// Requires `UIViewControllerRepresentable` over `UIViewRepresentable` as the type that allows
// for SwiftUI `View`s to be added as subviews of UIKit `UIView`s at all bridges this gap as
// the `UIHostingController`.
//
// Not battle-tested yet, but seems to be working well so far.
// Expect changes.
@mattadatta
mattadatta / ClearingReplayRelay.swift
Created October 16, 2019 12:08
Rx ClearingReplayRelay
public final class ClearingReplayRelay<Element> : ObservableType {
public typealias E = Element
private var _element: Element?
private var _onNext: ((Element) -> Void)?
private let _lock = NSLock()
public func accept(_ event: Element?) {
let deliverNow: (Element, (Element) -> Void)? = {