Skip to content

Instantly share code, notes, and snippets.

View buddax2's full-sized avatar

Oleksandr Yakubchyk buddax2

View GitHub Profile
@buddax2
buddax2 / updateOrSetDate.swift
Last active October 21, 2019 10:09
Update or set new date
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
}
}
@buddax2
buddax2 / GoogleTranslate.workflow
Created March 25, 2018 22:37
Google Translate Automator Service
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
@buddax2
buddax2 / preview.go
Created July 31, 2017 12:04
Get url preview
package main
import (
"fmt"
"log"
"os"
"net/http"
"strings"
"io/ioutil"
"github.com/gin-gonic/gin"
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
}
@buddax2
buddax2 / Array_extension_shuffle.swift
Last active April 14, 2016 21:24
Returns shuffled array
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)))
@buddax2
buddax2 / VanishingView.m
Last active March 4, 2016 14:24 — forked from NSExceptional/VanishingView.m
A UIView subclass that fades away more the harder you press on it, and eventually disappears if you press hard enough. iOS 9 only, of course.
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()
}
}
}