This file contains hidden or 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 Optional where Wrapped == Date { | |
mutating func updateOrSet(newDate: Date?, comparedBy: (Date, Date) -> Bool) { | |
if let currentDate = self, let nDate = newDate { | |
self = comparedBy(currentDate, nDate) ? currentDate : nDate | |
} | |
else { | |
self = newDate | |
} | |
} |
This file contains hidden or 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
on run {input, parameters} | |
set output to "http://translate.google.com/translate_t?sl=auto&tl=uk&text=" & urldecode(input as string) | |
return output | |
end run | |
on urldecode(x) | |
set cmd to "'require \"cgi\"; puts CGI.escape(STDIN.read.chomp)'" | |
do shell script "echo " & quoted form of x & " | ruby -e " & cmd | |
end urldecode |
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"net/http" | |
"strings" | |
"io/ioutil" | |
"github.com/gin-gonic/gin" |
This file contains hidden or 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 Array where Element: ComparisonProtocol { | |
func unique() -> [Element] { | |
var uniqVals2: Set<String> = [] | |
return self.filter { | |
guard let comparisonAttribute = $0.comparisonAttribute else { return false } | |
if uniqVals2.contains(comparisonAttribute) == false { | |
uniqVals2.insert(comparisonAttribute) | |
return true | |
} |
This file contains hidden or 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 Array { | |
func shuffled() -> [Element] { | |
return shuffle(self) | |
} | |
func shuffle(array: [Element]) -> [Element] { | |
guard array.count > 1 else { return array } | |
var list = array | |
let randomIndex = Int(arc4random_uniform(UInt32(array.count))) |
This file contains hidden or 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 UIView { | |
override public func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { | |
if let touch = touches.first { | |
self.alpha = 1 - touch.force / touch.maximumPossibleForce | |
if touch.force == touch.maximumPossibleForce { | |
self.removeFromSuperview() | |
} | |
} | |
} |