Skip to content

Instantly share code, notes, and snippets.

View Xopoko's full-sized avatar

Maksim Kudriavtsev Xopoko

  • Cyprus
View GitHub Profile
@Sherlouk
Sherlouk / DebugDevice.swift
Last active June 6, 2024 19:38
Debug Profiles - Securely debugging in production
//
// DebugDevice.swift
//
// Copyright 2022 • Sidetrack Tech Limited
//
import Foundation
// This must be called on the main-thread.
var isDebugProfileInstalled: Bool {
@ole
ole / UIAlertController+TextField.swift
Last active September 13, 2022 14:20
A UIAlertController with a text field and the ability to perform validation on the text the user has entered while the alert is on screen. The OK button is only enabled when the entered text passes validation. More info: https://oleb.net/2018/uialertcontroller-textfield/
import UIKit
/// A validation rule for text input.
public enum TextValidationRule {
/// Any input is valid, including an empty string.
case noRestriction
/// The input must not be empty.
case nonEmpty
/// The enitre input must match a regular expression. A matching substring is not enough.
case regularExpression(NSRegularExpression)
@MihaelIsaev
MihaelIsaev / Vapor3HTTPClientRequestProxy.swift
Created June 26, 2018 02:49
Example of http request through proxy for Vapor 3
public func boot(_ app: Application) throws {
let config = URLSessionConfiguration.default
config.requestCachePolicy = URLRequest.CachePolicy.reloadIgnoringLocalCacheData
config.connectionProxyDictionary = [AnyHashable: Any]()
config.connectionProxyDictionary?[kCFNetworkProxiesHTTPEnable as String] = 1
config.connectionProxyDictionary?[kCFNetworkProxiesHTTPProxy as String] = "proxy-server.com"
config.connectionProxyDictionary?[kCFNetworkProxiesHTTPPort as String] = 8080
let session = URLSession.init(configuration: config)
@lattner
lattner / TaskConcurrencyManifesto.md
Last active July 21, 2024 05:08
Swift Concurrency Manifesto
@youmee
youmee / PluralForm.swift
Last active January 16, 2020 14:20
Swift Russian Plural Form Function
/*
pluralForm(28, forms: ["год", "года", "лет"])
output: "лет"
*/
func pluralForm(number: Int, forms: [String]) -> String {
return number % 10 == 1 && number % 100 != 11 ? forms[0] :
(number % 10 >= 2 && number % 10 <= 4 && (number % 100 < 10 || number % 100 >= 20) ? forms[1] : forms[2])
}