Skip to content

Instantly share code, notes, and snippets.

View RoshanNindrai's full-sized avatar
🌉

Roshan Nindrai RoshanNindrai

🌉
View GitHub Profile
@RoshanNindrai
RoshanNindrai / List.swift
Last active May 21, 2017 23:10
This is an exercise to implement List using swift mutable pointers
// List implementation using UnsafeMutablePointer.
final class InternalList<T> {
var count: Int
var size: Int
var ptr: UnsafeMutablePointer<T>?
init(count: Int, ptrs: UnsafeMutablePointer<T>? = nil) {
self.count = count
size = count
// 1. QuickSort
public extension Array {
mutating func quickSort(_ compare: ((Element, Element) -> Bool)) {
for index in 0..<count {
var min = index
for subsequent in (index + 1)..<count {
if (!compare(self[min], self[subsequent])) {
@RoshanNindrai
RoshanNindrai / parallel.swift
Last active August 5, 2019 15:34
Parallel Map, Filter Implementation
import Foundation
public extension Array {
func pmap<T>(transformer: @escaping (Element) -> T) -> [T] {
var result: [Int: [T]] = [:]
guard !self.isEmpty else {
return []
}
/// Manager class responsible of retriving data
final class DataManager {
/// Memory Cache responsible for maintaining data in memory
var memory = MemoryCache()
/// Disc Cache responsible for maintaining data in memory
var disc = DiscCache()
/// To get value from persistence for a specific key, data is first checked in memory,
/// followed by disc. If data isnot found `nil` is returned
func get(_ key: key) -> Value? {
if let value = memory.get(key) { return value }
public protocol ComposableCache {
associatedtype Key
associatedtype Value
var getC: (Key) -> Value? { get set }
var setC: (Key, Value) -> Void { get set }
init(getC: @escaping (Key) -> Value?, setC: @escaping ((Key, Value) -> Void))
extension ComposableCache {
func get(_ key: Key) -> Value? {
return getC(key)
}
func set(_ key: Key, _ value: Value) {
setC(key, value)
}
struct MemoryComposableCache<K, V>: ComposableCache {
var getC: (K) -> V?
var setC: (K, V) -> Void
typealias Key = K
typealias Value = V
}
struct DiscComposableCache<K, V>: ComposableCache {
var getC: (K) -> V?
var setC: (K, V) -> Void
public protocol ComposableCache {
associatedtype Key
associatedtype Value
var getC: (Key) -> Value? { get set }
var setC: (Key, Value) -> Void { get set }
init(getC: @escaping (Key) -> Value?, setC: @escaping ((Key, Value) -> Void))
#!/usr/bin/env python
import subprocess
import sys, os
from multiprocessing import Pool
def pre_req(workspace_path):
if '.xcworkspace' in workspace_path and os.path.exists(workspace_path):
device_ids = list_device_ids()
run_xcuitest(workspace_path, device_ids)
@RoshanNindrai
RoshanNindrai / Morse.swift
Last active October 1, 2018 16:25
Basic Morse Code translator - letters
//
// Morse.swift
// Morse
//
// Created by Roshan Nindrai on 9/30/18.
// Copyright © 2018 Roshan Nindrai. All rights reserved.
//
import Foundation