Skip to content

Instantly share code, notes, and snippets.

View KingOfBrian's full-sized avatar

Brian King KingOfBrian

  • Boston Massachusetts
View GitHub Profile
@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 / 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 / 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
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 / PublicationCenter.swift
Last active February 4, 2022 11:49
PublicationCenter
//
// 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 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:
@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))
@KingOfBrian
KingOfBrian / gist:5502914a7a85fbe7ea67
Created June 13, 2014 16:39
Swift NSObject subclass
import Foundation
class FooFun {
@objc
func bat() {
println("bat")
}
}
class Foo :NSObject {
import Foundation
class Foo {
func bar() {
println("Swift Hello, World!")
}
@objc
func baz() {
println("baz")
}
@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;