Skip to content

Instantly share code, notes, and snippets.

View MihaelIsaev's full-sized avatar
⌨️
developing Swift for Web

Mikhail Isaev aka iMike MihaelIsaev

⌨️
developing Swift for Web
View GitHub Profile
Если пробег до 200 то шкала от 0 до 200 это  100%. 
Если пробег свыше 200 то то шкала 300. 
Если свыше 300 то шкала 500. 
Если с выше 500 то шкала всегда зелёная. И значение пробега.

это есть

Принажатыми сюда в работе от автопрайса должен быть возврат в заявку( сейчас переходит на стартовую страницу так будет в программе полной )
@MihaelIsaev
MihaelIsaev / Bindings.swift
Created June 14, 2019 02:51 — forked from AliSoftware/Bindings.swift
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
// This is a re-implementation of the @Binding and @State property wrappers from SwiftUI
// The only purpose of this code is to implement those wrappers myself just to understand how they work internally and why they are needed
// Re-implementing them myself has helped me understand the whole thing better
//: # A Binding is just something that encapsulates getter+setter to a property
@propertyDelegate
struct XBinding<Value> {
var value: Value {
get { return getValue() }
@MihaelIsaev
MihaelIsaev / ImageMagick.swift
Created February 9, 2019 17:22
Little ImageMagick wrapper for Vapor Swift
//
// ImageMagick.swift
// App
//
// Created by Mihael Isaev on 01.08.2018.
//
import Foundation
import Vapor
import Core
import Foundation
extension TimeZone {
func GMTOffset() -> String {
var offsetSeconds = secondsFromGMT()
var offsetString = "+00:00"
var offsetSymbol = "+"
var offsetHoursLeadString = "0"
var offsetMinutesLeadString = "0"
if offsetSeconds < 0 {
CodyFire.shared.fillHeaders = {
guard let apiToken = LocalAuthStorage.savedToken else { return [:] }
return ["Authorization": "Bearer \(apiToken)"]
}
@MihaelIsaev
MihaelIsaev / Router+AnyReponseArray.swift
Last active July 22, 2018 20:32
Attempt to handle routes with [AnyResponse] for Vapor3
extension Router {
@discardableResult
func get(_ path: PathComponentsRepresentable..., use closure: @escaping (Request) throws -> [AnyResponse]) -> Route<Responder>
{
return _on(.GET, at: path.convertToPathComponents(), use: closure)
}
@discardableResult
func post(_ path: PathComponentsRepresentable..., use closure: @escaping (Request) throws -> [AnyResponse]) -> Route<Responder>
{
@MihaelIsaev
MihaelIsaev / String+SnakeCase.swift
Created July 22, 2018 19:26
Camel case to snake case in Swift
extension String {
var snakeCased: String {
var newString: String = ""
let upperCase = CharacterSet.uppercaseLetters
for scalar in self.unicodeScalars {
if upperCase.contains(scalar) {
if newString.count > 0 {
newString.append("_")
}
let character = Character(scalar)
@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)
@MihaelIsaev
MihaelIsaev / PostgreSQLQueryCodableExample.swift
Created May 29, 2018 01:13
Vapor3 PostgreSQL extension to decode [[PostgreSQLColumn: PostgreSQLData]] with Codable struct
import PostgreSQL
typealias PostgreSQLQueryRow = [PostgreSQLColumn: PostgreSQLData]
extension Dictionary where Key == PostgreSQLColumn, Value == PostgreSQLData {
func decode<T>(_ key: String) throws -> T where T: PostgreSQLDataConvertible {
guard let v = try firstValue(forColumn: key)?.decode(T.self) else {
throw PostgreSQLError(identifier: "decodingError", reason: "Unable to decode \"\(key)\" column ", source: .capture())
}
return v
@MihaelIsaev
MihaelIsaev / Request+PromiseWrapper.swift
Created April 28, 2018 15:44
Request+Promise extension for Vapor 3. May be handy if you often create promises in your controllers
import Foundation
import Vapor
extension Request {
func promise<T>(_ asyncCode: @escaping (() throws ->(T))) -> Future<T> where T: ResponseEncodable {
let promise = eventLoop.newPromise(T.self)
DispatchQueue.global().async {
do {
promise.succeed(result: try asyncCode())