This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// init VPN manager | |
self.vpnManager = [NEVPNManager sharedManager]; | |
// load config from perference | |
[_vpnManager loadFromPreferencesWithCompletionHandler:^(NSError *error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"directory": "vendor/bower_components" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 { |
NewerOlder