View .zshrc
function __history { | |
[ -n "$1" ] && history 1 | grep -i $1 || history 1 | |
} | |
alias history='__history' |
View MKMapView+FitCoords.swift
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 | |
} | |
} |
View OptionalType+Exts.swift
public protocol OptionalType { | |
associatedtype Wrapped | |
var value: Wrapped? { get } | |
} | |
extension Optional: OptionalType { | |
public var value: Wrapped? { | |
return self | |
} |
View Cart.swift
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] |
View RxArray.swift
import Foundation | |
import RxSwift | |
struct RxArray<T: Hashable> { | |
private let storage: BehaviorRelay<[T]> | |
private let lock = NSRecursiveLock() | |
var items: Observable<[T]> { | |
return storage.asObservable() | |
} | |
View UIImage+QR.swift
extension UIImage { | |
func parseQR() -> [String] { | |
guard let image = CIImage(image: self) else { | |
return [] | |
} | |
let detector = CIDetector(ofType: CIDetectorTypeQRCode, | |
context: nil, | |
options: [CIDetectorAccuracy: CIDetectorAccuracyHigh]) |
View IsraeliID.Validator.js
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) => { |
View MKMultiPoint+Ext.swift
public extension MKMultiPoint { | |
var coordinates: [CLLocationCoordinate2D] { | |
var coords = [CLLocationCoordinate2D](repeating: kCLLocationCoordinate2DInvalid, | |
count: pointCount) | |
getCoordinates(&coords, range: NSRange(location: 0, length: pointCount)) | |
return coords | |
} | |
} |
View Combine+WithLatestFrom.swift
// | |
// Combine+WithLatestFrom.swift | |
// | |
// Created by Shai Mishali on 29/08/2019. | |
// Copyright © 2019 Shai Mishali. All rights reserved. | |
// | |
import Combine | |
// MARK: - Operator methods |