Skip to content

Instantly share code, notes, and snippets.

View soxjke's full-sized avatar

Petro Korienev soxjke

View GitHub Profile
@soxjke
soxjke / picking.swift
Last active March 10, 2017 10:46 — forked from vojto/picking.swift
struct RectangleConfig {
var width: Int = 0
var height: Int = 0
}
class ConfigView: NSView {
// Models
let config = MutableProperty<RectangleConfig?>(nil)
var width: SignalProducer<Int?, NoError>!
extension Signal where Error == NoError {
public func sample(each timeInterval: DispatchTimeInterval,
on scheduler: DateScheduler = QueueScheduler()) -> Signal<[Value], NoError> {
return Signal<[Value], NoError> { observer in
let valueHolder : MutableProperty<[Value]> = MutableProperty<Value>([])
let disposable = CompositeDisposable()
var sampler: Signal<(), NoError>? = nil
disposable += timer(interval: until, on: QueueScheduler()).startWithSignal { signal, _ in
signal = innerSignal.map { _ in () }
}
@soxjke
soxjke / NSObject+Cast.h
Created March 15, 2017 20:56
NSObject+Cast
@interface NSObject (Cast)
+ (instancetype)cast:(id)object;
@end
@soxjke
soxjke / Generic.h
Last active March 15, 2017 21:18
ObjC++ generic
@interface DBManager<ObjCType, CPPType> : NSObject
- (ObjCType)performOperation:(darkmatter::Result<CPPType> (^)())operation
withMap:(ObjCType (^)(darkmatter::Result<CPPType> fetchedObject))map
returningError:(NSError **)error;
@end
@interface StringContainer : NSObject
- (instancetype)initWithString:(NSString *)string;
@property (nonatomic, unsafe_unretained) NSString *string;
@end
@implementation StringContainer
- (instancetype)initWithString:(NSString *)string {
@soxjke
soxjke / StackTrace.txt
Last active March 27, 2017 15:42
RaceCondition2
Thread 5Queue : com.apple.root.user-initiated-qos (concurrent)
#0 0x000000010f181d2b in objc_release ()
#1 0x000000010f1831d1 in (anonymous namespace)::AutoreleasePoolPage::pop(void*) ()
#2 0x00000001125037ce in _dispatch_root_queue_drain ()
#3 0x0000000112503059 in _dispatch_worker_thread3 ()
#4 0x00000001128cb4de in _pthread_wqthread ()
#5 0x00000001128c9341 in start_wqthread ()
@soxjke
soxjke / NoRetainCycle.swift
Created September 26, 2017 16:45
NoRetainCycle
//: Playground - noun: a place where people can play
import Foundation
prefix operator ~
prefix func ~<Entity, Parameters>(_ param: ((Entity) -> (Parameters) -> (), Entity)) -> WeakCallback<Parameters>
where Entity: AnyObject
{
return WeakCallback.weakifyFunction(param.0, object: param.1)
//: Playground - noun: a place where people can play
import Foundation
precedencegroup boolImply {
associativity: left
}
infix operator ~>: boolImply
//: Playground - noun: a place where people can play
import Foundation
func work<R, T0>(_ f: @escaping (T0) -> R) -> (T0) -> R {
return { (arg0: T0) -> R in return f(arg0) }
}
func work<R, T0, T1>(_ f: @escaping (T0, T1) -> R) -> (T0, T1) -> R {
return { (arg0: T0, arg1: T1) -> R in return f(arg0, arg1) }
@soxjke
soxjke / File.swift
Last active October 18, 2017 10:20
Swift 4 crash
public protocol A {
associatedtype V
associatedtype E
var a: V { get }
}
public protocol B {
associatedtype V
var b: V { get }
}