Skip to content

Instantly share code, notes, and snippets.

View monyschuk's full-sized avatar

Mark Onyschuk monyschuk

  • Toronto, Canada
View GitHub Profile
@monyschuk
monyschuk / StateMachine.swift
Last active September 26, 2022 15:59
Simple Swift FSM
//: Playground - noun: a place where people can play
import UIKit
/// A finite state machine
final class FSM<State, Transition>: ObservableObject where State: Hashable, Transition: Hashable {
/// current state
@Published private(set) var state: State
/// state transition graph
@monyschuk
monyschuk / MicroReactive.swift
Last active March 28, 2018 08:04
Single file simple reactive programming classes for Swift
//: Playground - noun: a place where people can play
import Cocoa
import XCPlayground
// Let asynchronous code run
XCPSetExecutionShouldContinueIndefinitely()
public func log<T>(x: T) {
print("\(x)")
@monyschuk
monyschuk / MaterialIcons.swift
Created May 12, 2016 12:45
MaterialIcons with NSAttributedString, NSImage support for Swift
// MaterialIcons for Cocoa
import Cocoa
import CoreText
public enum MaterialIcon: String {
case ThreeDRotation = "\u{e84d}"
case Accessibility = "\u{e84e}"
case AccountBalance = "\u{e84f}"
case AccountBalanceWallet = "\u{e850}"
@monyschuk
monyschuk / EventManager.swift
Last active June 8, 2016 21:25
Strongly typed EventManager alternative to NSNotificationCenter in Swift
import Foundation
/**
EventType serves as a strongly typed alternative to NSNotification and its name property.
To create the equivalent of a simple notification with no associated information, declare
an empty struct conforming to EventType:
struct AppDataDidRefreshEvent: EventType {}
@monyschuk
monyschuk / DraggingStackView.swift
Created February 3, 2017 12:22
An NSStackView whose contents can be reordered via dragging
//
// DraggingStackView.swift
// Analysis
//
// Created by Mark Onyschuk on 2017-02-02.
// Copyright © 2017 Mark Onyschuk. All rights reserved.
//
import Cocoa
@monyschuk
monyschuk / DecimalString
Created February 24, 2017 13:19
String of decimal digits used to represent an arbitrarily large counter
struct DecimalString {
var value: String
private init(_ value: String) {
self.value = value
}
init(digits string: String) {
let digits = CharacterSet.decimalDigits
self.value = string.unicodeScalars.filter { digits.contains($0) } .map { String($0) } .joined()
//
// RLE.swift
// RLE
//
// Created by Mark Onyschuk on 2017-08-31.
// Copyright © 2017 Mark Onyschuk. All rights reserved.
//
import Foundation
@monyschuk
monyschuk / RunLengthEncoding.swift
Last active June 9, 2018 15:04
RunLengthEncoding.swift
//
// RunLengthEncoding
// RLE
//
// Created by Mark Onyschuk on 2017-08-31.
// Copyright © 2017 Mark Onyschuk. All rights reserved.
//
import Foundation
@monyschuk
monyschuk / NSPopover_OverrideAnimation.h
Created February 8, 2022 01:26
disables all animation of NSPopover (for use in SwiftUI apps where there is no control over popover display animation
//
// NSPopover_OverrideAnimation.h
// scrl (macOS)
//
// Created by Mark Onyschuk on 2022-02-07.
//
#import <Cocoa/Cocoa.h>
NS_ASSUME_NONNULL_BEGIN
import Foundation
#if canImport(Cocoa)
import Cocoa
#elseif canImport(UIKit)
import UIKit
#endif
public struct EdgeInsets {
var top, bottom, leading, trailing: CGFloat