Skip to content

Instantly share code, notes, and snippets.

View jeksys's full-sized avatar

Eugene Yagrushkin jeksys

View GitHub Profile
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
}
}
@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
@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 / 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 / unwrappedString.swift
Last active November 4, 2016 16:22
unwrapped optional String
private protocol _Optional {
func unwrappedString() -> String
}
extension Optional: _Optional {
fileprivate func unwrappedString() -> String {
switch self {
case .some(let wrapped as _Optional): return wrapped.unwrappedString()
case .some(let wrapped): return String(describing: wrapped)
case .none: return String(describing: self)
@jeksys
jeksys / hexString.swift
Last active September 21, 2016 23:55
hexString
extension NSData {
func hexadecimal() -> String {
var string = ""
var byte: UInt8 = 0
for i in 0 ..< length {
getBytes(&byte, range: NSMakeRange(i, 1))
string += String(format: "%02x", byte)
}
@jeksys
jeksys / optionalUnwrapping.swift
Created September 21, 2016 00:37
optional unwrapping
private protocol _Optional {
func unwrappedString() -> String
}
extension Optional: _Optional {
private func unwrappedString() -> String {
switch self {
case .Some(let wrapped as _Optional): return wrapped.unwrappedString()
case .Some(let wrapped): return String(wrapped)
case .None: return String(self)
@jeksys
jeksys / NSDateFormatter cheat sheet
Created March 12, 2016 04:05 — forked from romaonthego/NSDateFormatter cheat sheet
Date Formats for NSDateFormatter
a: AM/PM
A: 0~86399999 (Millisecond of Day)
c/cc: 1~7 (Day of Week)
ccc: Sun/Mon/Tue/Wed/Thu/Fri/Sat
cccc: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
d: 1~31 (0 padded Day of Month)
D: 1~366 (0 padded Day of Year)
@jeksys
jeksys / xorcrypto.swift
Last active August 29, 2015 14:15
xorcrypto
let text = [UInt8]("hello!!!".utf8)
let cipher = [UInt8]("good".utf8)
var encrypted = [UInt8]()
// encrypt bytes
for t in enumerate(text) {
encrypted.append(t.element ^ cipher[t.index%cipher.count])
}
@jeksys
jeksys / UIColorHex.swift
Created February 9, 2015 01:35
UIColorHex.swift
extension UIColor {
convenience init(red: Int, green: Int, blue: Int) {
assert(red >= 0 && red <= 255, "Invalid red component")
assert(green >= 0 && green <= 255, "Invalid green component")
assert(blue >= 0 && blue <= 255, "Invalid blue component")
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
}
convenience init(netHex:Int) {