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
{ | |
"countries":[ | |
{ | |
"name":"Afghanistan", | |
"phoneCode":"93", | |
"iso":"AF" | |
}, | |
{ | |
"name":"Albania", | |
"phoneCode":"355", |
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 NSTimeZone { | |
func offsetStringFromGMT() -> String { | |
var offsetSeconds = secondsFromGMT | |
var offsetString = "+00:00" | |
var offsetSymbol = "+" | |
var offsetHoursLeadString = "0" | |
var offsetMinutesLeadString = "0" | |
if offsetSeconds < 0 { | |
offsetSymbol = "-" | |
offsetSeconds = (offsetSeconds * -1) |
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
#!/bin/bash | |
limit="${1-10000000}"; | |
echo "Keeping SourceKitService below $limit KiB of virtual memory." | |
echo "Hit ^C to quit." | |
while true; do | |
sleep 1; | |
p=`pgrep ^SourceKitService$` | |
if [ -n "$p" ]; then | |
vsz=`ps -o vsz -p "$p" | tail -1` |
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 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()) |
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 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 |
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 { | |
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) |
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 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> | |
{ |
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
CodyFire.shared.fillHeaders = { | |
guard let apiToken = LocalAuthStorage.savedToken else { return [:] } | |
return ["Authorization": "Bearer \(apiToken)"] | |
} |
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 Foundation | |
extension TimeZone { | |
func GMTOffset() -> String { | |
var offsetSeconds = secondsFromGMT() | |
var offsetString = "+00:00" | |
var offsetSymbol = "+" | |
var offsetHoursLeadString = "0" | |
var offsetMinutesLeadString = "0" | |
if offsetSeconds < 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
// | |
// ImageMagick.swift | |
// App | |
// | |
// Created by Mihael Isaev on 01.08.2018. | |
// | |
import Foundation | |
import Vapor | |
import Core |
OlderNewer