Skip to content

Instantly share code, notes, and snippets.

View indragiek's full-sized avatar

Indragie Karunaratne indragiek

View GitHub Profile
@indragiek
indragiek / gist:383c4cd74c86098506b1
Created February 20, 2014 21:44
List of XEP's supported by Flamingo (http://flamingo.im)
XEP-0115 (Capabilities)
XEP-0054 (vCard)
XEP-0153 (Avatars)
XEP-0092 (Software Version)
XEP-0085 (Chat State)
XEP-0199 (Ping)
XEP-0203 (Delay)
XEP-0095 (Stream Initiation)
XEP-0096 (SI File Transfer)
XEP-0065 (SOCKS5 Bytestreams)
// Create an RBTCentralManager
self.manager = [[RBTCentralManager alloc] init];
// Scan and connect to all the peripherals
RACDisposable *disposable = [[[[[self.manager.stateSignal
takeUntilBlock:^BOOL(NSNumber *state) {
return (state.integerValue == CBCentralManagerStatePoweredOn);
}] then:^RACSignal *{
return [self.manager scanForPeripheralsWithServices:nil options:nil];
}] reduceEach:^(CBPeripheral *peripheral, NSDictionary *advertisementData, NSNumber *RSSI) {
@indragiek
indragiek / LTClientBrowser.h
Last active August 29, 2015 14:01
ReactiveCocoa-based wrapper around NSNetServiceBrowser
//
// LTClientBrowser.h
// LayerTreeServer
//
// Created by Indragie Karunaratne on 2014-05-21.
// Copyright (c) 2014 Indragie Karunaratne. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <LayerTreeKit/LayerTreeKit.h>
@indragiek
indragiek / gist:0b163d8a1d998aa44ff6
Last active August 29, 2015 14:02
Swift compiler segfault when accessing computed property on class extension
struct SomeStruct {
let value: String
}
extension UIView {
var ind_someProperty: SomeStruct {
return SomeStruct(value: "Broken compiler")
}
}
@indragiek
indragiek / KeypathExtensions.swift
Last active August 29, 2015 14:07
Implementation of -valueForKeyPath: that supports indexed subscripts, implemented in Swift.
//
// KeypathExtensions.swift
//
// Created by Indragie on 10/3/14.
// Copyright (c) 2014 Indragie Karunaratne. All rights reserved.
//
import Foundation
let KeyRegex = NSRegularExpression(pattern: "^(\\w[\\w\\d]*)?(\\[\\d+\\])*$", options: NSRegularExpressionOptions(0), error: nil)

Keybase proof

I hereby claim:

  • I am indragiek on github.
  • I am indragie (https://keybase.io/indragie) on keybase.
  • I have a public key whose fingerprint is 9B62 C6E3 9E0D C285 1423 1EB3 3FA7 3F1A E47E 67A6

To claim this, I am signing this object:

@indragiek
indragiek / gist:88a148c7006aca6c3dbf
Created January 3, 2015 04:14
UITextView crash
* thread #1: tid = 0x4ec0b, 0x0000000102444b8a libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000102444b8a libobjc.A.dylib`objc_exception_throw
frame #1: 0x00000001027abe6d CoreFoundation`+[NSException raise:format:] + 205
frame #2: 0x00000001066f79f6 UIFoundation`-[NSConcreteTextStorage attribute:atIndex:effectiveRange:] + 131
frame #3: 0x00000001066c351b UIFoundation`-[NSAttributedString(NSAttributedStringUIFoundationAdditions) rangeOfTextTable:atIndex:] + 65
frame #4: 0x00000001066f9e1b UIFoundation`-[NSTextBlockLayoutHelper initWithTextTable:charIndex:text:layoutManager:containerWidth:collapseBorders:] + 376
frame #5: 0x00000001066fe85f UIFoundation`-[NSTextTable rectForBlock:layoutAtPoint:inRect:textContainer:characterRange:] + 355
frame #6: 0x00000001066fcc3b UIFoundation`-[NSTextTableBlock rectForLayoutAtPoint:inRect:textContainer:characterRange:] + 116
frame #7: 0x0000000106706b3b UIFoundation`-[NSType
@indragiek
indragiek / generics.swift
Last active August 29, 2015 14:13
This code doesn't compile (Xcode 6.1.1, Swift 1.1)
public protocol TableViewSectionType {
typealias ItemCollection: CollectionType
}
public protocol TableViewCellFactoryType {
typealias Item
}
public final class TableViewDataSource<
SectionCollection: CollectionType,
@indragiek
indragiek / CGFloatFormattingBug.swift
Created January 29, 2015 02:48
Swift bug when formatting CGFloats
import Cocoa
// Doesn't work for CGFloats
let a: CGFloat = 1.0
let b: CGFloat = 2.0
String(format: "%f %f", a, b) // "0.000000 0.000000"
// Works for Floats
let c: Float = 1.0
let d: Float = 2.0
func crashOnError<T>(f: Void throws -> T) -> T {
do {
return try f()
} catch {
fatalError("Uncaught error")
}
}
enum TestError: ErrorType {
case AnError