This file contains 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
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
let urlPath = "http://telize.com/geoip" | |
let url = NSURL(string: urlPath) | |
let session = NSURLSession.sharedSession() | |
let task = session.dataTaskWithURL(url!, completionHandler: {data, response, error -> Void in | |
This file contains 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
extension String { | |
func toDate(format: String) -> NSDate? { | |
let dateFormatter = NSDateFormatter() | |
dateFormatter.dateFormat = format | |
return dateFormatter.dateFromString(self) | |
} | |
} | |
extension NSDate { | |
func toString(format: String) -> String { |
This file contains 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
extension Array { | |
func forEach(f: (element: T) -> Void) { | |
for e in self { | |
f(element: e) | |
} | |
} | |
} |
This file contains 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
// | |
// SRCopyableLabel.swift | |
// | |
// Created by Stephen Radford on 08/09/2015. | |
// Copyright (c) 2015 Cocoon Development Ltd. All rights reserved. | |
// | |
import UIKit | |
class SRCopyableLabel: UILabel { |
This file contains 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 RxSwift // Version 3.2.0 | |
import RxCocoa // Version 3.2.0 | |
func keyboardHeight() -> Observable<CGFloat> { | |
return Observable | |
.from([ | |
NotificationCenter.default.rx.notification(NSNotification.Name.UIKeyboardWillShow) | |
.map { notification -> CGFloat in | |
(notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.height ?? 0 | |
}, |
This file contains 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
// Adapted from Stack Overflow answer by David Crow http://stackoverflow.com/a/43235 | |
// Question: Algorithm to randomly generate an aesthetically-pleasing color palette by Brian Gianforcaro | |
// Method randomly generates a pastel color, and optionally mixes it with another color | |
func generateRandomPastelColor(withMixedColor mixColor: UIColor?) -> UIColor { | |
// Randomly generate number in closure | |
let randomColorGenerator = { ()-> CGFloat in | |
CGFloat(arc4random() % 256 ) / 256 | |
} | |
var red: CGFloat = randomColorGenerator() |
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
This file contains 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
mr Marathi | |
bs Bosnian | |
ee_TG Ewe (Togo) | |
ms Malay | |
kam_KE Kamba (Kenya) | |
mt Maltese | |
ha Hausa | |
es_HN Spanish (Honduras) | |
ml_IN Malayalam (India) | |
ro_MD Romanian (Moldova) |
This file contains 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
# Convert the .cer file into a .pem file: | |
$ openssl x509 -in aps_development.cer -inform der -out PushChatCert.pem | |
# Convert the private key’s .p12 file into a .pem file: | |
$ openssl pkcs12 -nocerts -in PushChatKey.p12 -out PushChatKey.pem | |
# Finally, combine the certificate and key into a single .pem file | |
$ cat PushChatCert.pem PushChatKey.pem > ck.pem | |
# At this point it’s a good idea to test whether the certificate works. |
This file contains 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
final class PublicKeyPinner { | |
/// Stored public key hashes | |
private let hashes: [String] | |
public init(hashes: [String]) { | |
self.hashes = hashes | |
} | |
/// ASN1 header for our public key to re-create the subject public key info | |
private let rsa2048Asn1Header: [UInt8] = [ |
OlderNewer