Skip to content

Instantly share code, notes, and snippets.

View jeksys's full-sized avatar

Eugene Yagrushkin jeksys

View GitHub Profile
@jeksys
jeksys / englishEveryDay.md
Last active February 1, 2018 19:22
English Every day
  • confortable vs convenient
  • One is fun vs One is funny
  • wanna drink some beer, wanna == want to
  • explain to smb
  • Should vs got to (gotta) - should is optinal
  • What is this called
  • Feel good/bad
  • understand vs realize
@jeksys
jeksys / NetworkRequest.swift
Last active January 13, 2018 00:46
network request using failable router
import Alamofire
import AlamofireObjectMapper
class Network: NSObject, URLSessionDelegate {
static let shared = Network()
let baseURL = baseURL
var sessionManager = Alamofire.SessionManager.default
let networkQueue = DispatchQueue.global(qos: .utility)
@jeksys
jeksys / URLRequestRouter.swift
Created January 3, 2018 16:55
URL Request router
import Alamofire
import AlamofireObjectMapper
enum Router: URLRequestConvertible {
static let baseURLString = baseURL + "/requestPath"
case get
func asURLRequest() throws -> URLRequest{
@jeksys
jeksys / printJSONDictionary.swift
Created December 15, 2017 23:14
printJSONDictionary
func printJSONDictionary(payload: [String: Any]){
if let theJSONData = try? JSONSerialization.data(withJSONObject: payload, options: .prettyPrinted),
let theJSONText = String(data: theJSONData, encoding: String.Encoding.ascii){
print("JSON string = \n\(theJSONText)")
}
}
@jeksys
jeksys / EurekaDebugInfo.swift
Created December 15, 2017 21:14
EurekaDebugInfo
extension Form: CustomDebugStringConvertible{
public var debugDescription: String {
return "\(type(of: self)): \(address(o: self)) \n---------\n\(self.allRows)"
}
}
extension Section: CustomDebugStringConvertible{
@jeksys
jeksys / ReplaceWindowsRootViewController.swift
Created December 14, 2017 07:00
ReplaceWindowsRootViewController
extension UIView {
func snapshot() -> UIImage {
UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.main.scale)
drawHierarchy(in: bounds, afterScreenUpdates: true)
let result = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return result!
}
}
class EmptyResult: Mappable {
required init?(map: Map) {}
func mapping(map: Map) {
}
}
class FailableObject<T: Mappable, E: Mappable> : Mappable {
var object: T?
var error: E?
// create header with custom view
// create row with custom view
// section animation
protocol ErrorPresenting {
func presentError(title: String, message: String)
}
extension ErrorPresenting where Self: UIViewController {
func presentError(title: String, message: String) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
let dismissAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(dismissAction)
present(alertController, animated: true)
extension UIImage {
public func imageCenteredInParentWithSize(ratio: CGFloat, backgroundColor: UIColor = UIColor.clear) -> UIImage? {
let width = self.size.width
let height = width * ratio
let frameSize = CGSize(width: width, height: height)
UIGraphicsBeginImageContextWithOptions(frameSize, true, UIScreen.main.scale)
let context = UIGraphicsGetCurrentContext()!