Skip to content

Instantly share code, notes, and snippets.

View KingOfBrian's full-sized avatar

Brian King KingOfBrian

  • Boston Massachusetts
View GitHub Profile
//
// KSDIdlingWindow.h
//
// Created by Brian King on 4/13/10.
// Copyright 2010 King Software Designs. All rights reserved.
//
// Based off:
// http://stackoverflow.com/questions/273450/iphone-detecting-user-inactivity-idle-time-since-last-screen-touch
//
//
// 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;
import Foundation
class Foo {
func bar() {
println("Swift Hello, World!")
}
@objc
func baz() {
println("baz")
}
@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 {
@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 / 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 / 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
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