Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Alexis Bridoux ABridoux

:octocat:
View GitHub Profile
@ABridoux
ABridoux / ReducedReplayAsyncStream.swift
Created Jan 29, 2022
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 Sep 21, 2022
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 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)
/// - Already in use in [SplashBuddy](https://github.com/macadmins/SplashBuddy/blob/main/SplashBuddy/Tools/LoginWindow.swift)
@ABridoux
ABridoux / NotificationObserver.swift
Last active Aug 10, 2021
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 Dec 17, 2022
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