Skip to content

Instantly share code, notes, and snippets.

View hamsternik's full-sized avatar

Niki Khomitsevych hamsternik

View GitHub Profile
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) }
}
}
import Foundation
public protocol EnumerableEnum: RawRepresentable where RawValue == Int {
static var firstIndex: Int { get }
}
public extension EnumerableEnum {
@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() {
@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)
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
import UIKit
import CoreBluetooth
enum BluetoothState: CustomStringConvertible {
case off, on, unknown
init(bluetoothState: CBManagerState) {
switch bluetoothState {
case .poweredOff: self = .off
case .poweredOn: self = .on
@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
@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 / auth.cpp
Created March 28, 2017 18:30
Small project for the security information class
#include<iostream>
#include<fstream>
#include<sstream>
#include<streambuf>
#include<cstdlib>
#include<string>
#include<vector>
using std::string;
@hamsternik
hamsternik / ModelFromUIModel.swift
Created March 19, 2017 23:14
Transform UIModel object to the Model using protocols
import Foundation
// MARK: Model
protocol ModelType {
init(value: Int)
}
class Model: ModelType {
var value: Int