Skip to content

Instantly share code, notes, and snippets.

View KingOfBrian's full-sized avatar

Brian King KingOfBrian

  • Boston Massachusetts
View GitHub Profile
import Foundation
class Foo {
func bar() {
println("Swift Hello, World!")
}
@objc
func baz() {
println("baz")
}
@KingOfBrian
KingOfBrian / xcassetgen.swift
Last active August 29, 2015 14:22
Code Generation of .xcasset resources
import Foundation
/**
* Build script to generate a type safe wrapper around your projects .xcasset file.
* This will fail your build if you reference an image in your .xcasset file that has
* changed or been removed, as well as provide code completion help for all your images.
*
* Copy this file into a new `Run Phase` in your project, with `/usr/bin/env xcrun swift`
* specified for `Shell`.
*
* Configure the variables below:
//
// NSObject+BlockObservation.h
// Version 1.0
//
// Andy Matuschak
// andy@andymatuschak.org
// Public domain because I love you. Let me know how you use it.
//
#import <Cocoa/Cocoa.h>
@KingOfBrian
KingOfBrian / gist:910457
Created April 8, 2011 18:42
Why The Bits
typedef enum {
BKSlideDirectionRight = 1 << 0,
BKSlideDirectionLeft = 1 << 1,
BKSlideDirectionUp = 1 << 2,
BKSlideDirectionDown = 1 << 3,
BKSlideDirectionVertical = BKSlideDirectionUp | BKSlideDirectionDown,
BKSlideDirectionHorizontal = BKSlideDirectionLeft | BKSlideDirectionRight
} BKSlideDirection;
@KingOfBrian
KingOfBrian / gist:8d2c6d85cb4079aabde6
Last active January 27, 2016 19:11
Swift Regex matches
import Foundation
operator infix =~ {}
func =~ (input: String, pattern: String) -> String[]? {
let regex = NSRegularExpression(pattern: pattern, options: .CaseInsensitive, error: nil)
let results = regex.matchesInString(input,
options: nil,
range: NSMakeRange(0, countElements(input))
let strA: String? = check ? "hrm" : nil
print(strA) // .None
let str: String = "hrm"
let strB: String? = check ? str : nil
print(strB) // .Some("Awesome Idea.")
@KingOfBrian
KingOfBrian / is_this_interesting.noidea
Last active September 28, 2016 02:28
List of last verb * -> noun punctuation from Debate
welcome you to the first presidential debate
sponsored by the Commission on Presidential Debates
drafted tonight's format
agreed to by the campaigns
divided into six segments
explore three topic areas tonight
have an open discussion
shared with the commission or the campaigns
we welcome the candidates
cover all the issues of this campaign tonight
@KingOfBrian
KingOfBrian / gist:9739d45c20b6bc8daea4a288c3e35bef
Created December 5, 2016 00:44
Specialization incorrectly uses the default implementation
protocol Factory {
associatedtype Value = Self
static func make() -> Value
}
extension Factory {
static func make() -> Value {
fatalError("In default static implementation")
}
}
@KingOfBrian
KingOfBrian / Computr.swift
Created December 12, 2016 16:50
Help Computr
import Foundation
struct Computr {
typealias Integer = Int
typealias Address = UnsafeMutablePointer<Integer>
var ic: Address = Address.allocate(capacity: 1)
var eax: Integer = 0
var memory = Address.allocate(capacity: 10)
mutating func addr(at index: Int) -> Address {
@KingOfBrian
KingOfBrian / 1_Error
Last active March 11, 2017 19:25
Local Test Failures
Some errors are masked a bit. This one is pretty clear:
********************
FAIL: Swift(macosx-x86_64) :: attr/open.swift (2514 of 2903)
******************** TEST 'Swift(macosx-x86_64) :: attr/open.swift' FAILED ********************
Script:
--
rm -rf /Users/bking/sandbox/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/attr/Output/open.swift.tmp && mkdir -p /Users/bking/sandbox/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/attr/Output/open.swift.tmp
xcrun --toolchain default --sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk swiftc -target x86_64-apple-macosx10.9 -module-cache-path '/var/folders/33/wl32_mc90t58zkt8sn1sm_sc0000gn/T/swift-testsuite-clang-module-cachecpuIWO' -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/../../../Developer/Library/Frameworks -Xlinker -rpath -Xlinker /Applications/Xcode-beta.app/Contents/Developer/Plat