Skip to content

Instantly share code, notes, and snippets.

View jeksys's full-sized avatar

Eugene Yagrushkin jeksys

View GitHub Profile
@jeksys
jeksys / Swift3Dates.swift
Last active November 15, 2016 22:29 — forked from stinger/Swift3Dates.swift
Swift 3: Working with dates
//: Playground - noun: a place where people can play
// playing with dates
import Foundation
let date = Date()
let myLocale = Locale(identifier: "en_CA")
//: ### Setting an application-wide `TimeZone`
//: Notice how we use if-let in case the abbreviation is wrong. It will fallback to the default timezone in that case.
@jeksys
jeksys / gist:62d6f374ca25dea2cb946876287343fe
Created February 14, 2017 17:44
Count lines of code in SWIFT Xcode project
find . -path ./Pods -prune -o -name "*.swift" -print0 ! -name "/Pods" | xargs -0 wc -l
@jeksys
jeksys / gist:328a69d6dfb80025ca17a5e9a1b28d01
Created February 15, 2017 20:12
FIXED: Source Tree SSH Public Key Denied
ssh-add -K ~/.ssh/id_rsa
http://stackoverflow.com/questions/22021378/source-tree-ssh-public-key-denied
extension UIImageView {
func setImage(from url: URL, withPlaceholder placeholder: UIImage? = nil) {
self.image = placeholder
URLSession.shared.dataTask(with: url) { (data, _, _)
if let data = data {
let image = UIImage(data: data)
DispatchQueue.main.async {
self.image = image
}
}
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()!
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)
// create header with custom view
// create row with custom view
// section animation
class EmptyResult: Mappable {
required init?(map: Map) {}
func mapping(map: Map) {
}
}
class FailableObject<T: Mappable, E: Mappable> : Mappable {
var object: T?
var error: E?
@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!
}
}
@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{