Skip to content

Instantly share code, notes, and snippets.

View bduyng's full-sized avatar

Duy Bao Nguyen bduyng

View GitHub Profile
@bduyng
bduyng / String+fromNow.swift
Created March 16, 2016 09:58
Extension of String to convert timestamp string into "from now" version
extension String {
func fromNow() -> String {
guard Double(self) != nil else {
return "Invalid Date"
}
let from = NSDate(timeIntervalSince1970: Double(self)!)
let now = NSDate()
let cal = NSCalendar.currentCalendar()
@bduyng
bduyng / UIColor+Hex.swift
Last active March 16, 2016 09:54
Extension of UIColor that support HEX color which also included alpha value
extension UIColor {
class func hex(string: String) -> UIColor {
var hex = string.hasPrefix("#")
? String(string.characters.dropFirst())
: string
guard hex.characters.count == 3 || hex.characters.count == 6 || hex.characters.count == 8
else { return UIColor.whiteColor().colorWithAlphaComponent(0.0) }
if hex.characters.count == 3 {