Skip to content

Instantly share code, notes, and snippets.

View DivineDominion's full-sized avatar

Christian Tietze DivineDominion

View GitHub Profile
@DivineDominion
DivineDominion / gdcr2019.rb
Created November 16, 2019 15:32
A weird implementation idea for Game of Life
#!/usr/bin/env ruby
require "rspec"
class God
def kill!(cell)
cell.sacrifice_to self
end
def surrender(process)
@DivineDominion
DivineDominion / execute.rb
Last active October 29, 2019 08:23
Extract note links from a source note
#!/usr/bin/env ruby
# Avoid all the script configuration and use this convenience script instead!
#
# 1) Put it into the same folder,
# 2) run the script: `ruby _execute.rb PATH/TO/THE_NOTE.txt`
##################
# Configure here #

Keybase proof

I hereby claim:

  • I am divinedominion on github.
  • I am ctietze (https://keybase.io/ctietze) on keybase.
  • I have a public key ASAeEXhO_3ukmYArB4BCULSfFFT-rpg6j_aXiWWv_zmBEwo

To claim this, I am signing this object:

@DivineDominion
DivineDominion / reswift-order.md
Created June 17, 2019 08:21
How to affect the order of subscription callbacks in ReSwift/Redux

Affect the order/priority of subscription callbacks in ReSwift

(Reply to "Any way to control the priority of subscription callbacks?" ReSwift/ReSwift#404)

ReSwift does not guarantee any subscription callback order. Since ReSwift uses an unordered Set as its subscription store, there's no reliable way to know when a subscription is invoked.

This implementation detail is hidden by design. If you find yourself wanting to affect the order of subscription callbacks, there's a concept of a sequence waiting to be extracted somehow.

These are the ways out:

@DivineDominion
DivineDominion / AppDelegate.swift
Created December 19, 2018 11:25
`NSAppearance` change notification when you cannot use `NSApp.effectiveAppearance` which is available for macOS 10.14+ only
import Cocoa
import RxSwift
import RxCocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
let disposeBag = DisposeBag()
@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 / TestCase.swift
Last active August 15, 2018 09:14 — forked from akolov/TestCase.swift
Bridging XCTAssertThrows to Swift to catch exceptions. (Doesn't work with assert(), though)
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")
}
}
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 / 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() {