Skip to content

Instantly share code, notes, and snippets.

View DivineDominion's full-sized avatar

Christian Tietze DivineDominion

View GitHub Profile
struct Foo: ExpressibleByBooleanLiteral {
var value: Bool
init(booleanLiteral value: BooleanLiteralType) {
self.value = value
}
}
func ==(lhs: Foo, rhs: Foo) -> Bool {
return lhs.value == rhs.value
}
@DivineDominion
DivineDominion / 201801041611 Focus ReSwift reducers to one state change.md
Created January 15, 2018 15:51
Zettel note about ReSwift reducer partitioning

Title: Focus ReSwift reducers to one state change ID: 201801041611 Tags: #reswift #srp

ReSwift reducers should not have conditional side-effects, changing different states out of convenience. That makes it hard to notice which action changed what. The condition is most of the problem, I think.

An ideal approach would be to have 1 reducer/action pair for each substate change.

When reducers overlap (they touch the same state), this can become a problem. (IncreaseCounter and DecreaseCounter are a bad example.) Conditional changes to another substate should be extracted as another action which is dispatched by a Middleware under similar circumstances.

@DivineDominion
DivineDominion / cocoaconv.rb
Last active September 28, 2018 12:09
Convert libMultiMarkdown enums to Swift-bridgeable NS_ENUMs. Pass the path to libMultiMarkdown.h to the script when running.
#!/usr/bin/env ruby
require 'optparse'
CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
FALLBACK_PATH = File.join(CURRENT_PATH, "..", "build-xcode", "Debug", "include", "libMultiMarkdown", "libMultiMarkdown.h")
options = {:mode => :nsenum}
OptionParser.new do |parser|
parser.banner = "Usage: #{$0} [options] path/to/libMultiMarkdown.h"
@DivineDominion
DivineDominion / FolderContentMonitor.swift
Last active March 10, 2023 15:50
Wrapper for using C FSEvents with Swift 4
//
// Based on: https://blog.beecomedigital.com/2015/06/27/developing-a-filesystemwatcher-for-os-x-by-using-fsevents-with-swift-2/
//
import Foundation
public struct Event: CustomStringConvertible {
public let eventId: FSEventStreamEventId
public let eventPath: String
@DivineDominion
DivineDominion / ModalDialogController.swift
Created September 6, 2016 12:51
Showing any NSWindowController as an app modal
class ModalDialogController: NSWindowController {
convenience init() {
self.init(windowNibName: "ModalDialogController")
}
@IBOutlet var closeButton: NSButton!
override func windowDidLoad() {
@DivineDominion
DivineDominion / AppDelegate.swift
Created May 18, 2016 17:17
WTF: Crashing NSTableHeaderCell subclass ¯\_(ツ)_/¯
//
// AppDelegate.swift
// TableZombies
//
// Created by Christian Tietze on 18/05/16.
// Copyright © 2016 Christian Tietze. All rights reserved.
//
import Cocoa
#!/usr/bin/env ruby
require 'optparse'
require 'fileutils'
require 'open3'
TEMPLATE_URL = "https://github.com/Weltenbastler/template-mac.git"
# Print banner when arguments are missing
ARGV << '-h' if ARGV.count < 2
@DivineDominion
DivineDominion / Gemfile
Last active May 11, 2016 07:17 — forked from erikpukinskis/lilwiki.rb
Super short & minimal wiki using Sinatra and DataMapper
# A sample Gemfile
source "https://rubygems.org"
gem 'sinatra'
gem 'sinatra-authentication'
gem 'data_mapper'
gem 'dm-sqlite-adapter'
gem 'rdiscount'
import Foundation
public struct Subscription<State: Any> {
let subscriber: AnyStoreSubscriber
let selector: (State -> Any)
init(aSubscriber: AnyStoreSubscriber) {
@DivineDominion
DivineDominion / 01 client.swift
Created October 3, 2015 12:09
Chaining async event handling
import Foundation
// Application Service, responsible for transactions
class CreateGroupedMonitor {
// Domain Services:
let monitoringService: MonitorFile
let monitorMovalService: MoveMonitor
init(monitoringService: MonitorFile, groupCreationService: CreateGroup, monitorMovalService: MoveMonitor, updateSchedule: UpdateSchedule, wordCountStrategyRegistry: WordCountStrategyRegistry, monitorRepository: MonitorRepository) {