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 / WindowPosition.swift
Last active April 14, 2024 12:01
Logic to easily set a NSWindow's origin horizontally and vertically in a screen (AppKit and SwiftUI)
// Free to use
// Written by Alexis Bridoux - https://github.com/ABridoux
import AppKit
#if canImport(SwiftUI)
import SwiftUI
#endif
// MARK: Model
@ABridoux
ABridoux / NotificationObserver.swift
Last active August 10, 2021 18:27
A handy class to observe notifications with automatic unsubscribing and friendly syntax.
// 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 / EventService.swift
Last active March 30, 2023 13:40
A service to send events to restart, shutdown, put to sleep or logout the computer.
// 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 / 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
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 / 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.
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 / AsyncQueue.swift
Last active October 13, 2023 09:42
Async queue to enqueue elements and consume them in an `AsyncSequence`.
// MARK: - Queue
struct Queue<Element> {
private var enqueueArray: [Element] = []
private var dequeueArray: [Element] = []
var isEmpty: Bool {
enqueueArray.isEmpty && dequeueArray.isEmpty
}
}
@ABridoux
ABridoux / OSStatus+Error.swift
Created June 16, 2024 21:38
OSStatus map to error
// MARK: - Check error
extension OSStatus {
/// Error mapped from an `OSStatus`.
public struct StatusError: Error {
// MARK: Properties
let status: OSStatus