Skip to content

Instantly share code, notes, and snippets.

View tkrajacic's full-sized avatar
🦛

Thomas Krajacic tkrajacic

🦛
View GitHub Profile
@tkrajacic
tkrajacic / naïve_persisted_array.swift
Last active July 26, 2019 05:53
Trying to create an array that automatically persists to a JSON file on disk
import Foundation
public final class PersistedArray<T: Codable> {
private var array: [T] {
didSet {
do {
try save()
} catch {
print("\(error)")
}
// From objc.io's app architecture book
// https://github.com/objcio/app-architecture
import Foundation
extension NSObjectProtocol where Self: NSObject {
func observe<Value>(_ keyPath: KeyPath<Self, Value>, onChange: @escaping (Value) -> ()) -> Disposable {
let observation = observe(keyPath, options: [.initial, .new]) { _, change in
// See: https://bugs.swift.org/browse/SR-6066
let newValue = change.newValue ?? (nil as Any? as! Value)
* thread #19, queue = 'nio.nioTransportServices.connectionchannel', stop reason = breakpoint 2.1
* frame #0: 0x000000010000727a NIOTest`TPLinkResponseDecoder.channelRead(ctx=0x00006000026241e0, data=NIO.NIOAny @ 0x00007000084e7bd0, self=0x000060000024f5c0) at TPLinkResponseDecoder.swift:25
frame #1: 0x00000001000080d9 NIOTest`protocol witness for _ChannelInboundHandler.channelRead(ctx:data:) in conformance TPLinkResponseDecoder<A> at <compiler-generated>:0
frame #2: 0x0000000100469e72 NIO`ChannelHandlerContext.invokeChannelRead(data=NIO.NIOAny @ 0x00007000084e7bd0, self=0x00006000026241e0) at ChannelPipeline.swift:1285
frame #3: 0x000000010046e2a1 NIO`ChannelHandlerContext.fireChannelRead(data=NIO.NIOAny @ 0x00007000084e7bd0, self=0x0000600002624180) at ChannelPipeline.swift:1098
frame #4: 0x0000000100013d4b NIOTest`TPLinkEncryptionHandler.channelRead(ctx=0x0000600002624180, data=NIO.NIOAny @ 0x00007000084e7fe0, self=0x0000600000005490) at TPLinkEncryptionHandler.swift:20
frame #5: 0x000

Keybase proof

I hereby claim:

  • I am tkrajacic on github.
  • I am tkrajacic (https://keybase.io/tkrajacic) on keybase.
  • I have a public key ASDDk0yO8dsOScUPzSZFboau5TQpfjkNH_Ca1sSmT-1Jvgo

To claim this, I am signing this object:

@tkrajacic
tkrajacic / PropertyObserver.swift
Last active November 4, 2015 19:14
Why is the property observer called if no assignment takes place?
var value : String = "Test" {
didSet {
print("Changed Item Value")
}
}
let newValue = "Test"
private func changeIfNew<T: Comparable>(inout current: T, new: T) {
// This evaluates to false (as current == new) and the loop is skipped yet the property observer is still triggered
if current != new {
@tkrajacic
tkrajacic / crashlog
Created September 12, 2014 13:59
Alamofire crash when running tests in Xcode 6
Process: Xcode [27882]
Path: /Applications/Xcode-Beta.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 6.1 (6304)
Build Info: IDEFrameworks-6304000000000000~4
Code Type: X86-64 (Native)
Parent Process: launchd [204]
Responsible: Xcode [27882]
User ID: 501
@tkrajacic
tkrajacic / crashreport.crash
Created July 18, 2013 04:10
Crash report when using net-smb on Mac OS X 10.8.4 with homebrew Samba
Process: ruby [45753]
Path: /Users/USER/*/ruby
Identifier: ruby
Version: 0
Code Type: X86-64 (Native)
Parent Process: zsh [44956]
User ID: 501
Date/Time: 2013-07-18 13:06:50.654 +0900
OS Version: Mac OS X 10.8.4 (12E55)
@tkrajacic
tkrajacic / Textmate updating hang report
Created February 26, 2013 08:55
When updating Textmate 2, it sometimes hangs when trying to relaunch. Only force quitting it can solve the problem.
Date/Time: 2013-02-25 14:03:47 +0100
OS Version: 10.8.2 (Build 12C3006)
Architecture: x86_64
Report Version: 11
Command: TextMate
Path: /Applications/TextMate.app/Contents/MacOS/TextMate
Version: 2.0-alpha.9385 (9385)
Parent: launchd [150]