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
// | |
// Combine+WithLatestFrom.swift | |
// | |
// Created by Shai Mishali on 29/08/2019. | |
// Copyright © 2019 Shai Mishali. All rights reserved. | |
// | |
import Combine | |
// MARK: - Operator methods |
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 | |
import RxSwift | |
struct RxArray<T: Hashable> { | |
private let storage: BehaviorRelay<[T]> | |
private let lock = NSRecursiveLock() | |
var items: Observable<[T]> { | |
return storage.asObservable() | |
} | |
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
struct Cart { | |
private let action = PublishRelay<Action>() | |
public let items: Observable<[Item]> | |
init() { | |
items = action | |
.scan([Item]()) { items, action in | |
switch action { | |
case .add(let item): | |
return items + [item] |
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 UIImage { | |
func parseQR() -> [String] { | |
guard let image = CIImage(image: self) else { | |
return [] | |
} | |
let detector = CIDetector(ofType: CIDetectorTypeQRCode, | |
context: nil, | |
options: [CIDetectorAccuracy: CIDetectorAccuracyHigh]) |
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
public protocol OptionalType { | |
associatedtype Wrapped | |
var value: Wrapped? { get } | |
} | |
extension Optional: OptionalType { | |
public var value: Wrapped? { | |
return self | |
} |
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
public extension MKMapView { | |
public static func visibleRect(for coords: [CLLocationCoordinate2D]) -> MKMapRect { | |
return coords.reduce(MKMapRectNull) { outRect, coord in | |
let point = MKMapPointForCoordinate(coord) | |
let rect = MKMapRectMake(point.x, point.y, 0.1, 0.1) | |
let union = MKMapRectUnion(rect, outRect) | |
return union | |
} | |
} |
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
public extension MKMultiPoint { | |
var coordinates: [CLLocationCoordinate2D] { | |
var coords = [CLLocationCoordinate2D](repeating: kCLLocationCoordinate2DInvalid, | |
count: pointCount) | |
getCoordinates(&coords, range: NSRange(location: 0, length: pointCount)) | |
return coords | |
} | |
} |
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
function isValidIsraeliID(id) { | |
var id = String(id).trim(); | |
if (id.length > 9 || id.length < 5 || isNaN(id)) return false; | |
// Pad string with zeros up to 9 digits | |
id = id.length < 9 ? ("00000000" + id).slice(-9) : id; | |
return Array | |
.from(id, Number) | |
.reduce((counter, digit, i) => { |
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
function __history { | |
[ -n "$1" ] && history 1 | grep -i $1 || history 1 | |
} | |
alias history='__history' |