Skip to content

Instantly share code, notes, and snippets.

@mrbodich
mrbodich / SubSequenceManager.swift
Last active October 19, 2024 04:01
SubSequenceManager
fileprivate actor SubSequenceManager<Base: AsyncSequence & Sendable> where Base.Element: Sendable {
fileprivate typealias Element = Base.Element
// Private
private var base: Base
private var continuations: [String : AsyncStream<Base.Element>.Continuation] = [:]
private var subscriptionTask: Task<Void, Never>?
private var actions: [StreamAction<Base.Element>] = []
// MARK: Initialization
@mrbodich
mrbodich / SharedAsyncSequenceTests.swift
Last active October 19, 2024 02:21
SharedAsyncSequenceTests
func testListeningUpdates() async throws {
let controller = SequenceController<Int>()
let sequence = AsyncStream<Int> { [controller] continuation in
controller.onPublishElement = {
continuation.yield($0)
}
controller.onFinish = {
continuation.finish()
}
}
@mrbodich
mrbodich / FeedItem.swift
Created September 16, 2024 15:24
FeedItem Decoder
import Foundation
enum FeedItem {
case article(Article)
case ad(Ad)
}
struct Article: Decodable {
let id: UInt
let title: String
@mrbodich
mrbodich / .swift
Last active August 1, 2023 10:08
Chain of Responsibility + Decorator + Single Responsibility — ATM
//MARK: - Withdrawing.swift
import Foundation
protocol Withdrawing {
func capacity(amount: Int) -> Int
}
extension Withdrawing {
func chained(withNext next: Withdrawing) -> Withdrawing {
WithdrawingDecorator(main: self, relief: next)
@mrbodich
mrbodich / openapi.yaml
Created June 10, 2023 10:50 — forked from xgp/openapi.yaml
OpenAPI specification for Keycloak account API
openapi: 3.0.2
info:
title: Keycloak Account API
version: 20.0.3
description: |
Derived from the code at https://github.com/keycloak/keycloak/blob/main/services/src/main/java/org/keycloak/services/resources/account/AccountRestService.java
components:
securitySchemes:
access_token:
type: http
@mrbodich
mrbodich / .env
Created May 14, 2023 13:00 — forked from degitgitagitya/.env
Next JS + Next Auth + Keycloak + AutoRefreshToken
# KEYCLOAK BASE URL
KEYCLOAK_BASE_URL=
# KEYCLOAK CLIENT SECRET
KEYCLOAK_CLIENT_SECRET=
# KEYCLOAK CLIENT ID
KEYCLOAK_CLIENT_ID=
# BASE URL FOR NEXT AUTH
@mrbodich
mrbodich / background-brake-button.swift
Created January 24, 2022 08:47
Background with gesture brakes Button tap
struct ButtonTest: View {
var body: some View {
ScrollView {
VStack {
Button(action: {}) {
Text("Tap me...")
.frame(height: 30)
.padding(.horizontal, 50)
.foregroundColor(.white)
.lineLimit(1)