Skip to content

Instantly share code, notes, and snippets.

@jakebromberg
jakebromberg / JBCommonInit.h
Last active December 28, 2015 04:09
Macro to reduce boilerplate code for simple initializer methods. Your initializers must implement - commonInit, and rely entirely on that method for initialization.
#define JB_COMMON_INIT(superInit) \
^id (typeof(self) __self) { \
if (!(__self = superInit)) return nil; \
[__self commonInit]; \
return __self; \
}(self)
#endif
This file has been truncated, but you can view the full file.
3855728084165267427602774016750250750215154106538872005386275855200744485445722025212324644501868066020574030848366545271557552452518623475628808471607805366146042844883512647401525020570854014608124013521304812045232864231700262123702578364031843118116261537140056271742313651014420820321100133372050070378031505885182656485588734415104052338850581814138006722620651370728436302406050044726786416844607314360422635540182808583336308432545463025646165037726804586378005674841671672482458306107452383564852175062662277678550628387345015272846345561300861357201485634205351633420725284162180656386141025825675788806620713311774070317340573370214864328103007114110056080572775463215274412730663374005645366375156133121605012634751028225653072063046022817823366871643172031543814374656032716142262666177080720815637324870836071657383654154358782080354335327626814221411316864580353703312577388585481010705873761448604854534242852555763251015864165726413145286355326261107874126751386512782183550652744140057877126457877825071871
### Keybase proof
I hereby claim:
* I am jakebromberg on github.
* I am jakebromberg (https://keybase.io/jakebromberg) on keybase.
* I have a public key whose fingerprint is 9028 194A 2F87 1267 26E8 342C B120 B683 C4FB 0DA0
To claim this, I am signing this object:
@jakebromberg
jakebromberg / gist:7cf6b8496409e5ef38d1
Created June 24, 2014 16:32
NSString Block Append
@interface NSString (Append)
- (NSString *(^)(NSString *))append __attribute__((const));
@end
@implementation NSString (Append)
- (NSString *(^)(NSString *))append
{
@jakebromberg
jakebromberg / keypath macro
Created September 23, 2014 17:55
Allows code-time validation of key-value coding. Inspired by Justin Spahr-Summers.
#define keypath(object, keypath) \
((void)(NO && ((void)object.keypath, NO)), @ # keypath )
// generators provide a 'one shot' mechanism for repeatedly computing the next element.
struct FibonacciGenerator<T: IntegerArithmeticType> : GeneratorType {
var num1 : T
var num2 : T
mutating func next() -> T? {
let value = num1
(num1, num2) = (num2, num1 + num2)
@jakebromberg
jakebromberg / observer pattern.swift
Last active February 14, 2016 23:04
observer pattern in swift
import Swift
import UIKit
protocol EventType {
typealias RegistrationType : Hashable
typealias MessageType
mutating func registerObserver(observer: RegistrationType, callback: MessageType -> ())
mutating func removeObserver(observer: RegistrationType)
final class Node<T>: Sequence {
let value: T
var next: Node<T>?
init(_ value: T, next: Node<T>?) {
self.value = value
self.next = next
}
func makeIterator() -> List<T> {
import Foundation
import Swift
extension Int {
public func pow(exp: Int) -> Int {
return (0..<exp).reduce(1) { (acc, _) in
return acc * self
}
}
}
extension Sequence where Element == Int {
func pairsOfSum(k: Int) -> [(Int, Int)] {
var cache = [Int:Int]()
var result = [(Int, Int)]()
for i in self {
cache[i] = k - i
}
for (num, inv) in cache {