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 / 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 / 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
DivineDominion / TestCase.swift
Last active Aug 15, 2018 — forked from akolov/TestCase.swift
Bridging XCTAssertThrows to Swift to catch exceptions. (Doesn't work with assert(), though)
View TestCase.swift
class ExceptionTestCase: XCTestCase {
func raisesException() {
var exception = NSException(name: NSInternalInconsistencyException, reason: "Testing exceptions", userInfo: nil)
XCTAssertThrows({ exception.raise() })
XCTAssertThrowsSpecific({ exception.raise() }, NSInternalInconsistencyException, "Should raise NSInternalInconsistencyException")
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 /
Last active Dec 13, 2016
nvALT Preview Template featuring relative paths

Run this from your terminal to execute the setup script. It creates the directory and downloads the template right into this new folder.

curl -s | bash 

Aferwards, you can change the base directory in ~/Library/Application\ Support/nvALT/template.html as expected.

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
You can’t perform that action at this time.