Skip to content

Instantly share code, notes, and snippets.

View lightsprint09's full-sized avatar

Lukas Schmidt lightsprint09

View GitHub Profile
@lightsprint09
lightsprint09 / Automerge.swift
Last active April 25, 2020 17:27
Automerge Swift API
struct MyModel {
let created: Date
var mutableData: [String]
var text: Text
}
let content = MyModel(created: Date(), mutableData: [], text: Text("hi"))
let document = Automerge<MyModel>(content: content)
// accessing data
@lightsprint09
lightsprint09 / MultiClientDataProvider
Created October 23, 2017 11:26
A DataProvider which can be used by different dataSources at the same time
final public class NameDifferentDataProvider<Element>: DataProviding {
/// Closure which gets called, when a data inside the provider changes and those changes should be propagated to the datasource.
/// **Warning:** Only set this when you are updating the datasource.
public var whenDataProviderChanged: ProcessUpdatesCallback<Element>? {
get {
return realWhenDataProviderChanged
}
set {
newValue.map { didChanges.append($0) }
}
import Foundation
struct Event<T> {
let key: String
}
extension Event {
var notificationName: Notification.Name {
return Notification.Name(key)
struct Train {
let name: String
let date: Date
}
extension Train: Equatable {
static func ==(lhs: Train, rhs: Train) -> Bool {
return lhs.name == rhs.name
}
}
extension Array {
/**
Hacky way to may a Array with Type Elemnet to an arry with Supertype T. T must be Supertype of Array.Element
- returns: array of type T
*/
func mapType<T>() -> Array<T> {
let mappedCategorys: Array<T> = self.map { return $0 as! T }
return mappedCategorys
extension Array {
/**
Hacky way to may a Array with Type Elemnet to an arry with Supertype T. T must be Supertype of Array.Element
- returns: array of type T
*/
func mapType<T>() -> Array<T> {
let mappedCategorys: Array<T> = self.map { return $0 as! T }
return mappedCategorys
//
// ViewController+Instatiation.swift
// CardScore
//
// Created by Lukas Schmidt on 17.09.15.
// Copyright © 2015 Lukas Schmidt. All rights reserved.
// License MIT
//
import UIKit
@lightsprint09
lightsprint09 / ShowFxSnippet
Created December 17, 2013 13:29
Snippet to show JFx zeugs
AnchorPane anchorPane = (AnchorPane) FXMLLoader.load(fx.GuiAppAppointmentController.class.getResource("creatAppointmentView.fxml"));
Scene scene = new Scene(anchorPane);
stage.setScene(scene);
stage.setTitle("heHo");
stage.show();