Skip to content

Instantly share code, notes, and snippets.

View ABridoux's full-sized avatar
:octocat:

Alexis Bridoux ABridoux

:octocat:
View GitHub Profile
@ABridoux
ABridoux / AsyncQueue.swift
Last active October 13, 2023 09:42
Async queue to enqueue elements and consume them in an `AsyncSequence`.
View AsyncQueue.swift
// MARK: - Queue
struct Queue<Element> {
private var enqueueArray: [Element] = []
private var dequeueArray: [Element] = []
var isEmpty: Bool {
enqueueArray.isEmpty && dequeueArray.isEmpty
}
}
@ABridoux
ABridoux / MatrixMixerNodeWrapper.swift
Last active November 18, 2023 18:20
Wrapper around an `AVAudioUnit` of type `kAudioUnitType_Mixer` and sub type `kAudioUnitSubType_MatrixMixer` for convenient usage.
View MatrixMixerNodeWrapper.swift
import AVFoundation
// MARK: - MatrixMixerNodeWrapper
/// Wrapper around an audio unit node of type `kAudioUnitSubType_MatrixMixer` for convenience.
public final class MatrixMixerNodeWrapper {
// MARK: Properties
/// Matrix mixer to map input channels
@ABridoux
ABridoux / ReducedReplayAsyncStream.swift
Created January 29, 2022 11:12
An AsyncSequence that allows to be consumed several times. Returning the current state as specified in a reduce function
View ReducedReplayAsyncStream.swift
struct ReducedReplayAsyncStream<Element> {
typealias Reduce = (_ partialResult: inout Element, _ nextResult: Element) -> Void
private let storage: _Storage
private var originalStream: AsyncStream<Element>
init(
bufferingPolicy limit: AsyncStream<Element>.Continuation.BufferingPolicy = .unbounded,
initialResult: Element,
@ABridoux
ABridoux / EventService.swift
Last active March 30, 2023 13:40
A service to send events to restart, shutdown, put to sleep or logout the computer.
View EventService.swift
// Free to use
// Written by Alexis Bridoux - https://github.com/ABridoux
import AppKit
import Foundation
/// Service to shut down, restart, or put the computer to sleep. Also log out the user.
///
/// ### Resources
/// - [Apple doc](https://developer.apple.com/library/archive/qa/qa1134/_index.html)
@ABridoux
ABridoux / NotificationObserver.swift
Last active August 10, 2021 18:27
A handy class to observe notifications with automatic unsubscribing and friendly syntax.
View NotificationObserver.swift
// Free to use
// Written by Alexis Bridoux - https://github.com/ABridoux
/// Observes a notification and executes the provided block upon reception
///
/// Unregister the stored observer upon deinitialization
final class NotificationObserver {
var name: Notification.Name
var observer: NSObjectProtocol
@ABridoux
ABridoux / WindowPosition.swift
Last active January 10, 2024 01:36
Logic to easily set a NSWindow's origin horizontally and vertically in a screen (AppKit and SwiftUI)
View WindowPosition.swift
// Free to use
// Written by Alexis Bridoux - https://github.com/ABridoux
import AppKit
#if canImport(SwiftUI)
import SwiftUI
#endif
// MARK: Model