Skip to content

Instantly share code, notes, and snippets.

Christian Tietze DivineDominion

Block or report user

Report or block DivineDominion

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 201801041611 Focus ReSwift reducers to one state change.md

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 / installation_instructions.md
Last active Dec 13, 2016
nvALT Preview Template featuring relative paths
View installation_instructions.md

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 https://gist.githubusercontent.com/DivineDominion/ab1abe8d2b93d4b73d69/raw/6a7066f1fbcf45e3c47a8d85acee475dd33bd32c/install.sh | bash 

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

@DivineDominion
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
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'
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 — forked from erikpukinskis/lilwiki.rb
Super short & minimal wiki using Sinatra and DataMapper
View Gemfile
# A sample Gemfile
source "https://rubygems.org"
gem 'sinatra'
gem 'sinatra-authentication'
gem 'data_mapper'
gem 'dm-sqlite-adapter'
gem 'rdiscount'
View Subscription.swift
import Foundation
public struct Subscription<State: Any> {
let subscriber: AnyStoreSubscriber
let selector: (State -> Any)
init(aSubscriber: AnyStoreSubscriber) {
@DivineDominion
DivineDominion / in_memory_strategy.rb
Created Sep 22, 2013
Repository in Ruby according to Eric Evans (2006): Domain-Driven Design. Tackling complexity in the heart of software, Upper Saddle River, NJ: Addison-Wesley.
View in_memory_strategy.rb
class InMemoryStrategy
def matching(criteria)
results = []
domain_objects.each do |object|
results << object if criteria.satisfied_by?(object)
end
end
end
@DivineDominion
DivineDominion / com.brettterpstra.gitlogger.plist
Last active Dec 18, 2015 — forked from ttscoff/gitlogger.rb
Logs selected git repository commits to a text file or Day One for the past day once in the morning.
View com.brettterpstra.gitlogger.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.brettterpstra.gitlogger</string>
<key>EnvironmentVariables</key>
<dict>
<key>LANG</key>
<string>en_US.UTF-8</string>
@DivineDominion
DivineDominion / README.md
Last active Dec 15, 2015
Where I show the most inefficient way to duplicate HTML rendering for JavaScript XHR form validation callbacks.
View README.md

Because Rails' Unobstrusive JavaScript (UJS) driver rails.js and jQuery won't execute any JavaScript in XMLHttpRequest's response bodies when the status code is 400 or 424 or something similar, I had to instruct the client (jQuery) myself to render error messages on form validation.

This is my first attempt to do so: instead of a JS request, respond with JSON and do the interface changes client-side. Problem is, the JavaScript code is sent to the client only once, hence ERB view templates aren't available during execution. I couldn't just use Rails helpers this way to refactor rendering flash messages. The HTML was spread across three places then: create.html.erb to handle synchroneous requests and render both flash messages and form validation error, entries.js.coffee to render errors and lastly create.js.erb to render success messages and insert the new entry.

It worked, and it was a fun ride since I didn't

You can’t perform that action at this time.