Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Shai Mishali freak4pc

🎯
Focusing
Block or report user

Report or block freak4pc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@freak4pc
freak4pc / Combine+WithLatestFrom.swift
Last active Sep 13, 2019
withLatestFrom for Apple's Combine
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
@freak4pc
freak4pc / RxArray.swift
Created Oct 5, 2018
RxArray - A basic Reactive RxSwift array
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()
}
@freak4pc
freak4pc / Cart.swift
Last active Sep 7, 2018
Simple (Naive) Rx Cart
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]
@freak4pc
freak4pc / UIImage+QR.swift
Created Aug 26, 2018
Detect text messages from QR code
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])
@freak4pc
freak4pc / OptionalType+Exts.swift
Last active Jul 16, 2017
Optional Unwrapping with Closures
View OptionalType+Exts.swift
public protocol OptionalType {
associatedtype Wrapped
var value: Wrapped? { get }
}
extension Optional: OptionalType {
public var value: Wrapped? {
return self
}
@freak4pc
freak4pc / MKMapView+FitCoords.swift
Created Feb 12, 2017
Display list of coordinates / annotation correctly inside a map
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
}
}
@freak4pc
freak4pc / MKMultiPoint+Ext.swift
Last active Jul 31, 2019
Get a list of coordinates from a MKPolyline / MKRoute
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
}
}
@freak4pc
freak4pc / IsraeliID.Validator.js
Last active Aug 29, 2019
Israeli ID Validator (Javascript)
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) => {
@freak4pc
freak4pc / .zshrc
Created May 20, 2015
History that accepts a grep filter inline as an argument
View .zshrc
function __history {
[ -n "$1" ] && history 1 | grep -i $1 || history 1
}
alias history='__history'
You can’t perform that action at this time.