Skip to content

Instantly share code, notes, and snippets.

@manishkkatoch
manishkkatoch / GPXParser.swift
Last active December 6, 2017 17:19
Parser for .gpx file. communicates using GpxParsing protocol. The caller must implement this protocol to get notified of parse completion. Please use Queue implementation of your choice or see https://gist.github.com/manishkkatoch/0028a637cfc6dc3207d82c104299e08d.
//
// GpxParser.swift
// mockLocation
//
// Created by Manish Katoch on 11/29/17.
// Copyright © 2017 Manish Katoch. All rights reserved.
//
protocol GpxParsing: NSObjectProtocol {
func parser(_ parser: GpxParser, didCompleteParsing locations: Queue<CLLocation>)
@manishkkatoch
manishkkatoch / Queue.swift
Created December 6, 2017 17:18
Queue implementation
//
// Queue.swift
// mockLocation
//
// Created by Manish Katoch on 11/29/17.
// Copyright © 2017 Manish Katoch. All rights reserved.
//
import Foundation
import CoreLocation
@manishkkatoch
manishkkatoch / MockCLLocationManager.swift
Created December 6, 2017 17:42
Mocking CLLocationManager
//
// MockCLLocationManager.swift
//
// Created by Manish Katoch on 11/28/17.
// Copyright © 2017 Manish Katoch. All rights reserved.
//
import Foundation
import CoreLocation
@manishkkatoch
manishkkatoch / CLLocationManager+Swizzle.swift
Created December 6, 2017 17:51
Swizzling CLLocationManager to use MockCLLocationManager
//
// CLLocationManager+Swizzle.swift
// mockLocation
//
// Created by Manich Katoch on 11/30/17.
// Copyright © 2017 mk. All rights reserved.
//
import Foundation
import MapKit
@manishkkatoch
manishkkatoch / ViewController.swift
Created December 6, 2017 18:00
Usage of mocked CLLocationManager
//
// ViewController.swift
// mockLocation
//
// Created by Manich Katoch on 11/28/17.
// Copyright © 2017 mk. All rights reserved.
//
import UIKit
import MapKit
@manishkkatoch
manishkkatoch / PropertyExists.scala
Last active January 1, 2019 16:54
PropertyExists trait
@implicitNotFound(msg = "${PName} not found in ${T}")
trait PropertyExists[T, PName, PType]
object PropertyExists {
def apply[T, PType](column: Witness)(
implicit exists: PropertyExists[T, column.T, PType]): PropertyExists[T, column.T, PType] =
exists
implicit def implicitProvider[T, H <: HList, PName, PType](
implicit
object syntax {
implicit class RichDataSet[A](dataSet: Dataset[A]) {
val enriched = this
def apply[K](column: Witness.Lt[Symbol])(implicit
exists: PropertyExists[A, column.T, K]): Column =
new Column(column.value.name)
@manishkkatoch
manishkkatoch / JoinDataSet.scala
Created January 1, 2019 17:09
Sugar class for providing basic join language
class JoinDataSet[L, R](lhs: Dataset[L], rhs: Dataset[R], joinType: String)
object JoinDataSet {
def apply[L, R](lhs: Dataset[L], rhs: Dataset[R], joinType: String) = new JoinDataSet(lhs, rhs, joinType)
def leftJoin[L, R](lhs: Dataset[L], rhs: Dataset[R]) = JoinDataSet(lhs, rhs, "leftOuter")
def rightJoin[L, R](lhs: Dataset[L], rhs: Dataset[R]) = JoinDataSet(lhs, rhs, "rightOuter")
def fullOuterJoin[L, R](lhs: Dataset[L], rhs: Dataset[R]) = JoinDataSet(lhs, rhs, "fullOuter")
}
class JoinDataSet[L, R](lhs: Dataset[L], rhs: Dataset[R], joinType: String) {
def withKey[K](column: Witness.Lt[Symbol])(implicit
lhsExists: PropertyExists[L, column.T, K],
rhsExists: PropertyExists[R, column.T, K]): DataFrame =
doJoin(Seq(column.value.name))
private def doJoin(columns: Seq[String]) = lhs.join(rhs, columns, joinType)
}
class JoinDataSet[L, R](lhs: Dataset[L], rhs: Dataset[R], joinType: String) {
object on extends SingletonProductArgs {
def applyProduct[V <: HList, K](columns: V)(implicit
i0: ToTraversable.Aux[V, List, Symbol],
lhsExists: PropertiesExists[L, V, K],
rhsExists: PropertiesExists[R, V, K]): DataFrame =
doJoin(columns.toList[Symbol].map(_.name))
}