Skip to content

Instantly share code, notes, and snippets.

Avatar

Justin Spahr-Summers jspahrsummers

View GitHub Profile
View EXPatchMasterExample.m
[NSWindow ex_patchInstanceSelector: @selector(sendEvent:) withReplacementBlock: ^(EXPatchIMP *patch) {
return ^(NSEvent *event) {
NSWindow *window = (__bridge NSWindow *) patch->self;
if (window != self.window && [event type] == NSLeftMouseUp && [window isKeyWindow]) {
/* The last view seen */
static NSView *lastView = nil;
NSPoint point = [window.contentView convertPoint: [event locationInWindow] fromView: nil];
NSView *hitView = [window.contentView hitTest: point];
View gist:f6424839cdeb505e31ee
RACSignal *signal = [RACSignal create:^(id<RACSubscriber> subscriber) {
for (NSUInteger i = 0; !subscriber.disposable.disposed; i++) {
[subscriber sendNext:@(i)];
}
}];
@jspahrsummers
jspahrsummers / ObjectWrapper.swift
Last active Aug 29, 2015
Workaround for “unimplemented IR generation feature non-fixed class layout”
View ObjectWrapper.swift
class ObjectWrapper<T> {
let backingVar: T[]
var value: T {
get {
return backingVar[0]
}
set(newValue) {
backingVar[0] = newValue
View gist:13d08b4bd69abcd87cc5
0 swift 0x000000010c789608 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x000000010c789af4 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff8d7185aa _sigtramp + 26
3 libsystem_platform.dylib 0x00007fb542170838 _sigtramp + 3030745768
4 swift 0x000000010ca1990b swift::BoundGenericType::get(swift::NominalTypeDecl*, swift::Type, llvm::ArrayRef<swift::Type>) + 331
5 swift 0x000000010caa4091 swift::Type::transform(std::__1::function<swift::Type (swift::Type)> const&) const + 4001
6 swift 0x000000010caa3298 swift::Type::transform(std::__1::function<swift::Type (swift::Type)> const&) const + 424
7 swift 0x000000010ca0f9dd substDependentTypes(swift::ArchetypeBuilder&, swift::Type) + 205
8 swift 0x000000010caa3120 swift::Type::transform(std::__1::function<swift::Type (swift::Type)> const&) const + 48
9 swift 0x000000010caa32ff swift::Type::tr
@jspahrsummers
jspahrsummers / gist:7061ea467b767c4ae604
Created Jun 16, 2014
How a Functor hypothetically should be implemented in Swift(?)
View gist:7061ea467b767c4ae604
protocol Functor {
typealias Element
func map<U, UF: Functor where UF.Element == U>(f: Element -> U) -> UF
}
struct FunctorImpl<T>: Functor {
typealias Element = T
var value: T
@jspahrsummers
jspahrsummers / gist:2f482aa03009cb7a8646
Created Jun 22, 2014
Capturing an `inout` parameter for later use
View gist:2f482aa03009cb7a8646
struct Property<T> {
let name: String
let _getter: () -> T
let _setter: T -> ()
var value: T {
get {
return _getter()
}
@jspahrsummers
jspahrsummers / gist:cb9ae22c0fd0da0d539b
Last active Aug 29, 2015
Covariance + generics = 😢
View gist:cb9ae22c0fd0da0d539b
class Stream<T> {
// But I want `Stream<U>` to instead be typed as whatever subclass this is invoked upon
func map<U>(f: T -> U) -> Stream<U>
}
@jspahrsummers
jspahrsummers / fail.swift
Created Oct 5, 2014
Why does this use of SequenceType cause a compiler error? https://github.com/ReactiveCocoa/ReactiveCocoa/pull/1518
View fail.swift
public static func fromSequence<S: SequenceType where S.Generator.Element == T>(sequence: S) -> Producer<T> {
return Producer { consumer in
for value in sequence { // error: cannot convert the expression's type 'S' to type 'S'
consumer.put(.Next(Box(value)))
}
consumer.put(.Completed)
}
}
@jspahrsummers
jspahrsummers / gist:00d1ad24afbe26cd7abe
Last active Aug 29, 2015
Scenarios to consider for FRP APIs
View gist:00d1ad24afbe26cd7abe
  Hot Cold Notes
Behaviors Always Property values over time
Events Maybe Maybe This is a design decision, but picking “hot” requires introducing some concept of buffering
Promises Sorta Sorta Promises don't do work until started, but only do it once, and share/buffer their result
@jspahrsummers
jspahrsummers / gist:2a66e64afd0d44fbc92a
Created Oct 27, 2014
Build failures for ObjectiveGit iOS
View gist:2a66e64afd0d44fbc92a
*** Cleaning ObjectiveGit iOS...
*** Building and testing ObjectiveGit iOS...
[Info] Loading settings for scheme 'ObjectiveGit iOS' ... (5076 ms)
=== TEST ===
xcodebuild build build
Quick / Quick-iOS (Debug)
~ Check dependencies (227 ms)