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
func countPairs(numbers: [Int], k: Int) -> Int { | |
struct Pair: Equatable, Hashable { | |
let lhs: Int | |
let rhs: Int | |
func isValid(k: Int) -> Bool { | |
return lhs + k == rhs | |
} | |
static func ==(lhs: Pair, rhs: Pair) -> Bool { |
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 snakeCased() -> String? { | |
let pattern = "([a-z0-9])([A-Z])" | |
let regex = try? NSRegularExpression(pattern: pattern, options: []) | |
let range = NSRange(location: 0, length: count) | |
return regex?.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "$1_$2").lowercased() | |
} | |
} |
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
func initializeDatabase() { | |
let request = NSMutableURLRequest(url: NSURL(string: "\(apiURL)/statistics/")! as URL, | |
cachePolicy: .useProtocolCachePolicy, | |
timeoutInterval: 10.0) | |
request.httpMethod = "POST" | |
request.allHTTPHeaderFields = headers | |
let session = URLSession.shared |
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 UIKit | |
class ViewController: UIViewController { | |
fileprivate let databaseURL = "postgres://nwritrny:[email protected]:5432/nwritrny" | |
fileprivate let apiURL = "http://api.rutetiderframework.com" | |
@IBAction func subscribeAction(_ sender: Any) { | |
let headers = ["content-type": "application/x-www-form-urlencoded"] | |
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
// | |
// ContainerViewController.swift | |
// | |
// Created by Dmitriy Shulzhenko on 1/15/17. | |
// Copyright © 2017 Dmitriy Shulzhenko. All rights reserved. | |
// | |
import UIKit | |
class ContainerViewController: UIViewController { |
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
// | |
// PersistentStorageController.swift | |
// | |
// Created by Dmitriy Shulzhenko on 1/11/17. | |
// Copyright © 2017 Dmitriy Shulzhenko. All rights reserved. | |
// | |
import CoreData | |
class PersistentStorageController: NSObject { |