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
//
// TableViewController.swift
// RSSParser
//
// Created by mihael on 14/04/15.
// Copyright (c) 2015 Mihael Isaev inc. All rights reserved.
//
import UIKit
@MihaelIsaev
MihaelIsaev / CameraViewController.swift
Created April 16, 2015 19:30
This is the example of camera view for iOS written in Swift
import UIKit
import AVFoundation
class ViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
@IBOutlet weak var myView: UIView!
var session: AVCaptureSession?
var device: AVCaptureDevice?
var input: AVCaptureDeviceInput?
@MihaelIsaev
MihaelIsaev / HMAC.swift
Last active December 4, 2019 04:51
Easy to use Swift implementation of CommonCrypto HMAC. You can easily hash your String to: md5, sha1, sha224, sha256, sha384, sha512 with pure Swift.
//
// HMAC.swift
//
// Created by Mihael Isaev on 21.04.15.
// Copyright (c) 2014 Mihael Isaev inc. All rights reserved.
//
// ***********************************************************
//
// How to import CommonCrypto in Swift project without Obj-c briging header
//
@MihaelIsaev
MihaelIsaev / CountryCodes.json
Last active August 29, 2015 14:20 — forked from aynurin/CountryCodes.json
Remove spaces
{
"countries":[
{
"name":"Afghanistan",
"phoneCode":"93",
"iso":"AF"
},
{
"name":"Albania",
"phoneCode":"355",
@MihaelIsaev
MihaelIsaev / OffsetStringFromGMT.swift
Created May 3, 2015 14:49
iOS Swift extension to get GMT time offset string
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)
@MihaelIsaev
MihaelIsaev / throttle-SourceKitService
Created February 13, 2017 16:15 — forked from pyrtsa/throttle-SourceKitService
Script to keep SourceKitService from eating up all OS resources
#!/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`
@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())
@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 / 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 / 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)