Skip to content

Instantly share code, notes, and snippets.

View dmsl1805's full-sized avatar
🏎️

Dmitriy Shulzhenko dmsl1805

🏎️
View GitHub Profile
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 {
@dmsl1805
dmsl1805 / SnakeCase.swift
Last active September 25, 2024 23:14 — forked from ivanbruel/SnakeCase.swift
Camel case to snake case in Swift
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()
}
}
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
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"]
@dmsl1805
dmsl1805 / ContainerViewController.swift
Last active April 21, 2017 06:16
ContainerViewController
//
// ContainerViewController.swift
//
// Created by Dmitriy Shulzhenko on 1/15/17.
// Copyright © 2017 Dmitriy Shulzhenko. All rights reserved.
//
import UIKit
class ContainerViewController: UIViewController {
@dmsl1805
dmsl1805 / PersistentStorageController.swift
Created January 12, 2017 08:50
PersistentStorageController for core data
//
// PersistentStorageController.swift
//
// Created by Dmitriy Shulzhenko on 1/11/17.
// Copyright © 2017 Dmitriy Shulzhenko. All rights reserved.
//
import CoreData
class PersistentStorageController: NSObject {