Skip to content

Instantly share code, notes, and snippets.

View touchopia's full-sized avatar

Phil Wright touchopia

  • Touchopia LLC
  • West Jordan, Utah
View GitHub Profile
import UIKit
// Snapshot utilities
extension UIView {
func snapshotView(view: UIView, afterUpdates: Bool) -> UIView {
let snapshot = view.snapshotViewAfterScreenUpdates(afterUpdates)
self.addSubview(snapshot)
snapshot.frame = convertRect(view.bounds, fromView: view)
return snapshot
@touchopia
touchopia / UISwiftRestDemo
Created December 30, 2015 15:47 — forked from cmoulton/UISwiftRestDemo
Quick & dirty REST API calls with Swift. See http://grokswift.com/simple-rest-with-swift/
// MARK: Using NSURLSession
// Get first post
let postEndpoint: String = "http://jsonplaceholder.typicode.com/posts/1"
guard let url = NSURL(string: postEndpoint) else {
print("Error: cannot create URL")
return
}
let urlRequest = NSURLRequest(URL: url)
public typealias URLSessionOperationCompletion = (data: NSData?, response: NSHTTPURLResponse?, error: NSError?) -> Void
public class URLSessionOperation: Operation {
private var task: NSURLSessionDataTask?
private var completionHandler: URLSessionOperationCompletion?
/**
Returns an instance of `URLSessionOperation`
@touchopia
touchopia / Fetchable.swift
Created September 30, 2015 17:27 — forked from capttaco/Fetchable.swift
A utility protocol for custom NSManagedObjects that makes querying contexts simpler and more convenient. Requires Swift 2.
import CoreData
protocol Fetchable
{
typealias FetchableType: NSManagedObject
static func entityName() -> String
static func objectsInContext(context: NSManagedObjectContext, predicate: NSPredicate?, sortedBy: String?, ascending: Bool) throws -> [FetchableType]
static func singleObjectInContext(context: NSManagedObjectContext, predicate: NSPredicate?, sortedBy: String?, ascending: Bool) throws -> FetchableType?
static func objectCountInContext(context: NSManagedObjectContext, predicate: NSPredicate?) -> Int
@touchopia
touchopia / IPSecDemo.m
Last active November 5, 2015 19:12 — forked from zqqf16/IPSecDemo.m
Start IPSec programmatically in iOS 8
- (void)viewDidLoad
{
[super viewDidLoad];
// init VPN manager
self.vpnManager = [NEVPNManager sharedManager];
// load config from perference
[_vpnManager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
@touchopia
touchopia / rot13.swift
Last active August 29, 2015 14:24 — forked from shepting/rot13.swift
// Playground - noun: a place where people can play
let lettersArray = Array("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
func rot13(input: String) -> String {
return reduce(input, "") { result, letter in
if let i = find(lettersArray, letter) {
return result + lettersArray[i + 13]
} else {
return result + letter
@touchopia
touchopia / ROT13.swift
Last active December 14, 2015 14:50 — forked from jgallagher/ROT13.swift
//: ROT13 Swift 1.2 - by jgallagher
var rot13key = [Character:Character]()
let uppercase = Array("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
let lowercase = Array("abcdefghijklmnopqrstuvwxyz")
for var i = 0; i < 26; i++ {
rot13key[uppercase[i]] = uppercase[(i + 13) % 26]
rot13key[lowercase[i]] = lowercase[(i + 13) % 26]
-Weverything -Wcast-align -Wmissing-declarations -Wmissing-prototypes -Woverlength-strings -Wshadow -Wundeclared-selector -Wunreachable-code -Wformat=2 -Woverriding-method-mismatch -Wno-objc-missing-property-synthesis -Wno-unused-parameter -Wno-covered-switch-default -Wno-direct-ivar-access -Wno-assign-enum -Wno-float-equal -Wno-switch-enum -Wno-implicit-retain-self -Wno-vla -Wno-pedantic -Wno-explicit-ownership-type -Wno-bad-function-cast -Wno-documentation-unknown-command -Wno-packed
@touchopia
touchopia / .bowerrc
Last active August 29, 2015 14:17 — forked from ericlbarnes/.bowerrc
{
"directory": "vendor/bower_components"
}
<?php
function upload_user_file( $file = array() ) {
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
$file_return = wp_handle_upload( $file, array('test_form' => false ) );
if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
return false;
} else {