Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile
Host e
HostName 54.208.83.100
User ubuntu
IdentityFile ~/.ssh/your-key-pair.pem
class MasterViewController: UIViewController, UINavigationControllerDelegate {
init() {
super.init(nibName: nil, bundle: nil)
}
}
extension MasterViewController: UITableViewDataSource {
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
@nathanborror
nathanborror / ViewController.swift
Last active August 29, 2015 14:05
Programatic example of UISearchDisplayController
//
// ViewController.swift
// Example
//
// Created by Nathan Borror on 8/28/14.
// Copyright (c) 2014 Nathan Borror. All rights reserved.
//
import UIKit

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.

Auto-Layout

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

class Layout {

    let views: [String:UIView]
    let superview: UIView
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)
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
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) {
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],
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
}