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
import UIKit | |
class UILabelCopyable: UILabel { | |
override func copy(_ sender: Any?) { | |
UIPasteboard.general.string = text | |
} | |
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { |
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 Array { | |
func filter<T: Equatable>(where keyPath: KeyPath<Element, T>, equals compareValue: T) -> [Element] { | |
return filter { $0[keyPath: keyPath] == compareValue } | |
} | |
} |
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 Array { | |
func sorted<T: Comparable>(by keyPath: KeyPath<Element, T>, ordered areInIncreasingOrder: (T, T) -> Bool = (<) ) -> Array<Element> { | |
return self.sorted(by: { | |
areInIncreasingOrder($0[keyPath: keyPath], $1[keyPath: keyPath]) | |
}) | |
} | |
} |
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
import Foundation | |
internal extension Sequence { | |
func grouped<T>(by keyPath: KeyPath<Element, T>) -> [T: [Element]] { | |
var groups = [T: [Element]]() | |
for element in self { | |
let key = element[keyPath: keyPath] | |
if !groups.keys.contains(key) { | |
groups[key] = [Element]() | |
} |
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
#!/bin/bash | |
IP=$(dig +short $1 | sed -n 1p) | |
whois -h whois.ripe.net -- "-T route ${IP}" |
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
import UIKit | |
extension UIFont { | |
/// Returns the font in the specified size and weight. Default weight is `regular` | |
open class func font(ofSize fontSize: CGFloat, weight: FontWeight = .regular) -> UIFont { | |
let fontName = "UniversNextPro-\(weight.rawValue)" | |
guard let font = UIFont(name: fontName, size: fontSize) else { | |
fatalError("\(fontName) not found") | |
} | |
return font |
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
import Foundation | |
/// Custom FontWeights to be used with the .font UIFont class functions | |
public enum FontWeight: String { | |
case regular = "Regular" | |
case medium = "Medium" | |
case black = "Black" | |
case light = "Light" | |
case thin = "Thin" | |
case bold = "Bold" |
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
#!/bin/bash | |
set -e | |
SCALEWAY='scw --region="ams1"' | |
ARCH=X64 | |
COMM_TYPE=$ARCH-2GB | |
IMAGE=xenial | |
TRANSFERS=7 | |
TG_TOKEN=<BOT_TOKEN> |
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 Collection { | |
public subscript(safe index: Index) -> Optional<Iterator.Element> { | |
guard self.startIndex..<self.endIndex ~= index else { return nil } | |
return self[index] | |
} | |
} |