Skip to content

Instantly share code, notes, and snippets.

Indragie Karunaratne indragiek

Block or report user

Report or block indragiek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@indragiek
indragiek / CStringArray.swift
Last active Nov 14, 2019
Helper for working with char ** in Swift
View CStringArray.swift
// Copyright © 2015 Indragie Karunaratne. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@indragiek
indragiek / Image.swift
Created Oct 18, 2015
vImage_Buffer wrapper
View Image.swift
// Copyright © 2015 Indragie Karunaratne. All rights reserved.
import Foundation
import Accelerate
public class Image {
private var buffer: vImage_Buffer
public var size: CGSize {
return vImageBuffer_GetSize(&buffer)
View FuzzySet.swift
/// Used to lift a bounding value for a `Double` into the type system.
/// This is an ugly workaround for the lack of dependent types in Swift.
public protocol BoundingValueType {
static var value: Double { get }
}
/// Type that represents a bounding value of 1.0
public struct _1: BoundingValueType {
public static var value: Double { return 1.0 }
}
View TerribleErrorHandling.swift
func crashOnError<T>(f: Void throws -> T) -> T {
do {
return try f()
} catch {
fatalError("Uncaught error")
}
}
enum TestError: ErrorType {
case AnError
@indragiek
indragiek / Theming.swift
Last active Feb 3, 2018
Swift API for theming on iOS
View Theming.swift
// Created by Indragie on 5/3/15.
// Copyright (c) 2015 Indragie Karunaratne. All rights reserved.
import UIKit
public protocol ThemeType {
typealias Target
func apply(target: Target)
}
View JumpFixTableViewController.swift
//
// JumpFixTableViewController.swift
//
// Created by Indragie on 1/3/15.
// Copyright (c) 2015 Indragie Karunaratne. All rights reserved.
//
import UIKit
/// Table view controller that implements a workaround for a bug where
@indragiek
indragiek / CGFloatFormattingBug.swift
Created Jan 29, 2015
Swift bug when formatting CGFloats
View CGFloatFormattingBug.swift
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
@indragiek
indragiek / generics.swift
Last active Aug 29, 2015
This code doesn't compile (Xcode 6.1.1, Swift 1.1)
View generics.swift
public protocol TableViewSectionType {
typealias ItemCollection: CollectionType
}
public protocol TableViewCellFactoryType {
typealias Item
}
public final class TableViewDataSource<
SectionCollection: CollectionType,
View gist:88a148c7006aca6c3dbf
* 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
View keybase.md

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:

You can’t perform that action at this time.