Skip to content

Instantly share code, notes, and snippets.

View DivineDominion's full-sized avatar

Christian Tietze DivineDominion

View GitHub Profile
View contact_spec.rb
feature 'Contact form POST without Ajax', :js => false do
context 'without name' do
it 'shows the index' do
visit_landing_page
within('#request-form') do
fill_in 'request-email', :with => 'test@test.de'
fill_in 'request-anliegen', :with => 'Test'
fill_in 'request-seiten', :with => '123'
end
click_button 'Anfragen'
@DivineDominion
DivineDominion / ValueTransformation.swift
Created March 1, 2015 19:27
Paste this into a playground and see what happens with the two client code examples at the bottom. Should work out of the box.
View ValueTransformation.swift
import Cocoa
/// A wrapper around any type to make Result compile
class Box<T> {
let unbox: T
init(_ value: T) {
self.unbox = value
}
}
@DivineDominion
DivineDominion / DomainEvent.swift
Last active August 29, 2015 14:18
Domain Events v1.1 -- without event name enum
View DomainEvent.swift
import Foundation
public typealias UserInfo = [NSObject : AnyObject]
public protocol DomainEvent {
class var eventName: String { get }
init(userInfo: UserInfo)
func userInfo() -> UserInfo
}
View chaining-bind.swift
import Cocoa
// MARK: Part of Your New Toolkit
func bind<T, U>(optional: T?, f: T -> U?) -> U? {
if let x = optional {
return f(x)
}
else {
@DivineDominion
DivineDominion / 01 client.swift
Created October 3, 2015 12:09
Chaining async event handling
View 01 client.swift
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) {
View README.md

Where, instead of my inefficient approach, I execute XHR JavaScript responses. Behaves just like JangoSteve said it should for 400 or 424 HTTP response status codes.

Binds the event on $(document) so that dynamically created forms will be affected, too.

@DivineDominion
DivineDominion / README.md
Last active December 15, 2015 13:49
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

@DivineDominion
DivineDominion / in_memory_strategy.rb
Created September 22, 2013 10:24
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
View Subscription.swift
import Foundation
public struct Subscription<State: Any> {
let subscriber: AnyStoreSubscriber
let selector: (State -> Any)
init(aSubscriber: AnyStoreSubscriber) {
@DivineDominion
DivineDominion / Gemfile
Last active May 11, 2016 07:17 — 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'