Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>

Intents you define and upload to Amazon

{
  "intents": [
    {
      "intent": "GetVolume",
      "slots": [
        {
          "name": "Room",
import (
"bytes"
"encoding/json"
)
// ToModel converts a string map to a given model
func ToModel(obj map[string]string, model interface{}) error {
j, _ := json.Marshal(obj)
d := json.NewDecoder(bytes.NewReader(j))
return d.Decode(model)
enum HTTPRouter: URLRequestConvertible {
static let baseURL = "http://YOUR_HOST_URL"
case Upload(field: String, filename: String, mimeType: String, data: NSData)
var method: Alamofire.Method {
switch self {
case Upload:
return .POST
}
import UIKit
typealias Session = (NSDate, [Int])
let data = [
["created": NSDate(timeIntervalSince1970: 1422600001), "reps": 0],
["created": NSDate(timeIntervalSince1970: 1422600002), "reps": 1],
["created": NSDate(timeIntervalSince1970: 1422600003), "reps": 1],
["created": NSDate(timeIntervalSince1970: 1422700000), "reps": 0],
["created": NSDate(timeIntervalSince1970: 1422700000), "reps": 0],
import UIKit
let words = ["Cat", "Chicken", "Fish", "Dog", "Mouse", "Pig", "Monkey"]
typealias Entry = (Character, [String])
func distinct<T: Equatable>(source: [T]) -> [T] {
var unique = [T]()
for item in source {
if !contains(unique, item) {
func subscribe() {
let subscription = CKSubscription(recordType: "Item", predicate: NSPredicate(value: true), subscriptionID: "items", options: .FiresOnRecordUpdate | .FiresOnRecordCreation)
subscription.notificationInfo = CKNotificationInfo()
subscription.notificationInfo.alertBody = "New item added"
self.db.saveSubscription(subscription) { (subscription, error) -> Void in
if error != nil {
println(error.localizedDescription)
}
}
}
import UIKit
struct Styles {
// MARK: Global styles
static let margin:CGFloat = 8.0
static let padding:CGFloat = 8.0
static let tint = UIColor(red: 0.0, green: 0.48, blue: 1.0, alpha: 1.0)

Auto-Layout

Very simple convenience class to make working with Auto-Layout easier.

class Layout {

    let views: [String:UIView]
    let superview: UIView

Remote Virtual Interface

Taken directly from: https://developer.apple.com/library/mac/qa/qa1176/_index.html#//apple_ref/doc/uid/DTS10001707-CH1-SECRVI

iOS 5 added a remote virtual interface (RVI) facility that lets you use OS X packet trace programs to capture traces from an iOS device. The basic strategy is:

  1. Connect your iOS device to your Mac via USB.
  2. Set up an RVI for that device. This creates a virtual network interface on your Mac that represents the iOS device's networking stack.
  3. Run your OS X packet trace program, and point it at the RVI created in the previous step.
  4. To set up an RVI, you should run the rvictl tool as shown below.