Skip to content

Instantly share code, notes, and snippets.

Christian Tietze DivineDominion

View GitHub Profile
DivineDominion / AppDelegate.swift
Created Dec 19, 2018
`NSAppearance` change notification when you cannot use `NSApp.effectiveAppearance` which is available for macOS 10.14+ only
View AppDelegate.swift
import Cocoa
import RxSwift
import RxCocoa
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
let disposeBag = DisposeBag()
DivineDominion / Example.swift
Last active Sep 7, 2018
Extension to @IanKeen's Partial<T> for more sexy and very verbose validations
View Example.swift
// - MARK: Example Code
/// A model
struct User {
let firstName: String
let lastName: String
let age: Int?
/// Initializer using a Partial<T> -- You could generate this with Sourcery
View ExpressibleByBooleanLiteral==.swift
struct Foo: ExpressibleByBooleanLiteral {
var value: Bool
init(booleanLiteral value: BooleanLiteralType) {
self.value = value
func ==(lhs: Foo, rhs: Foo) -> Bool {
return lhs.value == rhs.value
View 201801041611 Focus ReSwift reducers to one state

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 / cocoaconv.rb
Last active Sep 28, 2018
Convert libMultiMarkdown enums to Swift-bridgeable NS_ENUMs. Pass the path to libMultiMarkdown.h to the script when running.
View cocoaconv.rb
#!/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} do |parser|
parser.banner = "Usage: #{$0} [options] path/to/libMultiMarkdown.h"
DivineDominion / FolderContentMonitor.swift
Last active Apr 14, 2019
Wrapper for using C FSEvents with Swift 4
View FolderContentMonitor.swift
// Based on:
import Foundation
public struct Event: CustomStringConvertible {
public let eventId: FSEventStreamEventId
public let eventPath: String
DivineDominion / ModalDialogController.swift
Created Sep 6, 2016
Showing any NSWindowController as an app modal
View ModalDialogController.swift
class ModalDialogController: NSWindowController {
convenience init() {
self.init(windowNibName: "ModalDialogController")
@IBOutlet var closeButton: NSButton!
override func windowDidLoad() {
DivineDominion / AppDelegate.swift
Created May 18, 2016
WTF: Crashing NSTableHeaderCell subclass ¯\_(ツ)_/¯
View AppDelegate.swift
// AppDelegate.swift
// TableZombies
// Created by Christian Tietze on 18/05/16.
// Copyright © 2016 Christian Tietze. All rights reserved.
import Cocoa
View install_wiki.rb
#!/usr/bin/env ruby
require 'optparse'
require 'fileutils'
require 'open3'
# Print banner when arguments are missing
ARGV << '-h' if ARGV.count < 2
DivineDominion / Gemfile
Last active May 11, 2016 — forked from erikpukinskis/lilwiki.rb
Super short & minimal wiki using Sinatra and DataMapper
View Gemfile
# A sample Gemfile
source ""
gem 'sinatra'
gem 'sinatra-authentication'
gem 'data_mapper'
gem 'dm-sqlite-adapter'
gem 'rdiscount'
You can’t perform that action at this time.