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 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 | |
} | |
} |
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
ssh-add -K ~/.ssh/id_rsa | |
http://stackoverflow.com/questions/22021378/source-tree-ssh-public-key-denied |
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
find . -path ./Pods -prune -o -name "*.swift" -print0 ! -name "/Pods" | xargs -0 wc -l |
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
//: 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. |
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
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) |
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 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) | |
} |
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
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) |
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
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) | |
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
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]) | |
} |
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 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) { |