Skip to content

Instantly share code, notes, and snippets.

View RoshanNindrai's full-sized avatar
🌉

Roshan Nindrai RoshanNindrai

🌉
View GitHub Profile
@RoshanNindrai
RoshanNindrai / Pulse.swift
Last active November 6, 2019 04:10
Sample Combine Operator (Purely for learning purposes & This is not thread safe)
import Combine
public extension Publishers {
final class Pulse<Upstream: Publisher>: Publisher {
public typealias Output = Upstream.Output
public typealias Failure = Upstream.Failure
private let interval: Int
private let upstream: Upstream
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
public struct Renderable {
private let handle: () -> Void
public init(_ handle: @escaping () -> Void) {
@RoshanNindrai
RoshanNindrai / Transformable.swift
Created December 4, 2018 16:59
Quick and dirty Swift DTO transformation layer
//
// Transformable.swift
// Transformable
//
// Created by Roshan Nindrai on 10/15/18.
// Copyright © 2018 Roshan Nindrai. All rights reserved.
//
import Foundation
import CoreData
@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
#!/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)
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))
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
extension ComposableCache {
func get(_ key: Key) -> Value? {
return getC(key)
}
func set(_ key: Key, _ value: Value) {
setC(key, 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))
/// 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 }