Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian King KingOfBrian

  • Boston Massachusetts
View GitHub Profile
View Computr.swift
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 / gist:9739d45c20b6bc8daea4a288c3e35bef
Created Dec 5, 2016
Specialization incorrectly uses the default implementation
View gist:9739d45c20b6bc8daea4a288c3e35bef
protocol Factory {
associatedtype Value = Self
static func make() -> Value
}
extension Factory {
static func make() -> Value {
fatalError("In default static implementation")
}
}
@KingOfBrian
KingOfBrian / is_this_interesting.noidea
Last active Sep 28, 2016
List of last verb * -> noun punctuation from Debate
View is_this_interesting.noidea
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
View wat2.swift
let strA: String? = check ? "hrm" : nil
print(strA) // .None
let str: String = "hrm"
let strB: String? = check ? str : nil
print(strB) // .Some("Awesome Idea.")
View PublicationCenter.swift
//
// PublicationCenter.swift
//
// Created by Brian King on 5/17/16.
// Copyright © 2016 Raizlabs. All rights reserved.
//
import Foundation
/// PublicationCenter is an NSNotificationCenter style object that
@KingOfBrian
KingOfBrian / xcassetgen.swift
Last active Aug 29, 2015
Code Generation of .xcasset resources
View xcassetgen.swift
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:
View gist:8d2c6d85cb4079aabde6
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))
View gist:5502914a7a85fbe7ea67
import Foundation
class FooFun {
@objc
func bat() {
println("bat")
}
}
class Foo :NSObject {
View gist:776887f4876269402351
import Foundation
class Foo {
func bar() {
println("Swift Hello, World!")
}
@objc
func baz() {
println("baz")
}
View gist:910457
typedef enum {
BKSlideDirectionRight = 1 << 0,
BKSlideDirectionLeft = 1 << 1,
BKSlideDirectionUp = 1 << 2,
BKSlideDirectionDown = 1 << 3,
BKSlideDirectionVertical = BKSlideDirectionUp | BKSlideDirectionDown,
BKSlideDirectionHorizontal = BKSlideDirectionLeft | BKSlideDirectionRight
} BKSlideDirection;