Skip to content

Instantly share code, notes, and snippets.

View hamsternik's full-sized avatar

Niki Khomitsevych hamsternik

View GitHub Profile
@hamsternik
hamsternik / arr_remove_element_ext.swift
Created May 19, 2017 19:46
Array Removing Extension
import Cocoa
extension Array where Element: Equatable {
mutating func remove(_ element: Element) {
if let index = self.index(of: element) {
self.remove(at: index)
}
}
@hamsternik
hamsternik / methodNames.swift
Last active March 21, 2018 15:47 — forked from kristopherjohnson/methodNames.swift
Get method names for an Objective-C class in Swift
// - Playgorund code here
// - This code generates all (private/public) method titles which stored within EAAccessoryManager class
import Foundation
import ExternalAccessory
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
import UIKit
import CoreBluetooth
enum BluetoothState: CustomStringConvertible {
case off, on, unknown
init(bluetoothState: CBManagerState) {
switch bluetoothState {
case .poweredOff: self = .off
case .poweredOn: self = .on
import Foundation
import PromiseKit
// MARK: - URLSession Data Promise
extension URLSession {
func dataPromise(with request: URLRequest) -> Promise<Data> {
return Promise { resolver in
let dataTask = self.dataTask(with: request) { (data, response, error) in
@hamsternik
hamsternik / UIColor+HexRepresentation.swift
Created September 26, 2018 15:28
Convenience initializers converted HEX String to the UIColor instance
import UIKit
extension UIColor {
convenience public init(hexRGB: CUnsignedLongLong) {
let red: CGFloat = CGFloat((hexRGB & 0xFF0000) >> 16) / CGFloat(255)
let green: CGFloat = CGFloat((hexRGB & 0xFF00) >> 8) / CGFloat(255)
let blue: CGFloat = CGFloat(hexRGB & 0xFF) / CGFloat(255)
self.init(red:red, green:green, blue:blue, alpha:1.0)
@hamsternik
hamsternik / UIRoundedImageView.swift
Created October 14, 2018 14:23
Extended UIImageView class which customized initial shape from rectangle to the oval
import UIKit
@IBDesignable
class UIRoundedImageView: UIImageView {
@IBInspectable var isRoundedCorners: Bool = false {
didSet { setNeedsLayout() }
}
override func layoutSubviews() {
import Foundation
public protocol EnumerableEnum: RawRepresentable where RawValue == Int {
static var firstIndex: Int { get }
}
public extension EnumerableEnum {
import Foundation
/// One-parameter currying from two arguments function
typealias EscapingClosure<A, B> = (A) -> B
func curry<A, B, C>(_ f: @escaping (A, B) -> C) -> EscapingClosure<A, (B) -> C> {
return { (a: A) -> ((_ b: B) -> C) in
return { (b: B) -> C in f(a, b) }
}
}
// MARK: - Throttler
public class Throttler {
private let queue: DispatchQueue = DispatchQueue.global(qos: .background)
private var job: DispatchWorkItem = DispatchWorkItem(block: {})
private var previousRun: Date = Date.distantPast
private var maxInterval: Double
init(seconds: Double) {
self.maxInterval = seconds
}
#{Re-map default prefix: 'C-b' to 'C-a'}
unbind C-b
set -g prefix C-a
bind C-a send-prefix
### Main Options
###########################################################################
#{Scroll History}
set -g history-limit 50000