Skip to content

Instantly share code, notes, and snippets.

@js
js / gist:9277611
Created February 28, 2014 19:09
You shouldn't use objc exceptions for flow control, among many reasons they're a tad slow.
// Output on this particular Mac
//
// Exceptions took 5.054922
// BOOL return + NSError took 0.251062
//
#import <Foundation/Foundation.h>
#import <mach/mach_time.h>
static inline void TimeDuration(NSString *description, NSUInteger runs, dispatch_block_t block)
@js
js / gist:4773884
Created February 12, 2013 22:07
Trying to wrap my head around ReactiveCocoa, by adding a repository list tableview to the GHAPIDemo sample project
// GHDUserViewController.m in the
// Take 1
- (id)initWithUserAccount:(GHGitHubUser *)user {
// .. snip ..
[[[RACSignal
merge:@[[self fetchUser], [self fetchRepos], [self fetchOrgs]]]
finally:^{
@strongify(self);
@js
js / gist:6138910
Created August 2, 2013 10:23
RACBacktrace dealloc crash
This file has been truncated, but you can view the full file.
(lldb) racbt
error: Trying to put the stack in unreadable memory at: 0x10f23ef80.
(lldb) bt
* thread #15: tid = 0x2cd18a, 0x00007fff90136fe6 libobjc.A.dylib`objc::DenseMap<objc_object*, unsigned long, true, objc::DenseMapInfo<objc_object*>, objc::DenseMapInfo<unsigned long> >::find(objc_object* const&) + 4, queue = 'com.apple.root.default-priority, stop reason = EXC_BAD_ACCESS (code=2, address=0x10f23eff8)
frame #0: 0x00007fff90136fe6 libobjc.A.dylib`objc::DenseMap<objc_object*, unsigned long, true, objc::DenseMapInfo<objc_object*>, objc::DenseMapInfo<unsigned long> >::find(objc_object* const&) + 4
frame #1: 0x00007fff90136f5b libobjc.A.dylib`_objc_rootReleaseWasZero + 126
frame #2: 0x00007fff9014f6f1 libobjc.A.dylib`-[NSObject release] + 17
frame #3: 0x00000001001fbe53 ReactiveCocoa`-[RACBacktrace .cxx_destruct](self=0x0000000102188800, _cmd=0x00007fff8e87e360) + 51 at RACBacktrace.m:153
frame #4: 0x00007fff9013dfcc libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) +
// weak-strong dance by shadowing self
foo { [weak self] in
guard let `self` = self else { return }
self.bar()
}
function current_git_branch
sh -c 'git branch --no-color 2> /dev/null' | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
end
func fetch1(where predicateFormat: String, _ args: CVarArg...) {
// using: public convenience init(format predicateFormat: String, _ args: CVarArg...)
let predicate = NSPredicate(format: predicateFormat, args)
print("fetch1 predicate: \(predicate)")
}
func fetch2(where predicateFormat: String, _ args: Any...) {
// Using: public init(format predicateFormat: String, argumentArray arguments: [Any]?)
let predicate = NSPredicate(format: predicateFormat, argumentArray: args)
print("fetch2 predicate: \(predicate)")
@js
js / rx.swift
Last active January 25, 2017 19:57
enum Event<T> {
case next(T)
case error(Error)
case completed
}
final class AnyObservable<T> {
let handler: (@escaping (Event<T>) -> Void) -> Void
init(handler: @escaping (@escaping (Event<T>) -> Void) -> Void) {
//: Playground - noun: a place where people can play
import UIKit
struct Person {
var name = Observable("Bob")
}
enum Event<T> {
case next(T)
:10000000FFFFFFFFFFFFFFFF012300230060FFFF53
:1000100041F7F1A100000000000000000000000016
:1000200000000000000000000000000000000000D0
:1000300000000000000000000000000000000000C0
:1000400000000000000000000000000000000000B0
:100050000000291E1F20212223242526272D2E2A99
:100060004C0000002B141A0815171C180C12132F23
:1000700030314A00000039041607090A0B0D0E0F33
:10008000333400284E000000E1641D1B06190511E1
:1000900010363738E5524B000000C0E2E3000000A4
#!/bin/sh
git log --no-walk --date-order --oneline --decorate $(git rev-list --branches --no-walk)