Skip to content

Instantly share code, notes, and snippets.

@sandeeplearner
sandeeplearner / ruby
Last active August 17, 2020 21:24
Capture Standard output using Open3
#!/usr/bin/ruby
#Genious idea
#shamelessly copied from https://stackoverflow.com/questions/690151/getting-output-of-system-calls-in-ruby
def syscall(*cmd)
begin
stdout, stderr, status = Open3.capture3(*cmd)
status.success? && stdout.slice!(0..-(1 + $/.size)) # strip trailing eol
rescue
end
@sandeeplearner
sandeeplearner / ruby
Created August 17, 2020 20:24
Ruby script to check and create new git repo
#!/usr/bin/ruby
require 'open3'
require 'fileutils'
class ProtoConverter
@tag_to_be_checkout = nil
def initialize(tag_to_checkout)
@tag_to_be_checkout = tag_to_checkout
end
@sandeeplearner
sandeeplearner / .swift
Created May 12, 2020 22:07
Variable declaration with associatedtype protocol type
let anyVehicleViewController: ViewControllerProtocol
@sandeeplearner
sandeeplearner / .swift
Created May 12, 2020 21:57
Instantiate viewController
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let plane = PlaneViewController(with: PlaneViewModel())
let car = CarViewController(with: CarViewModel())
}
}
@sandeeplearner
sandeeplearner / .swift
Created May 12, 2020 21:54
sample classes with protocol confirmation
class CarViewController: UIViewController, ViewControllerProtocol {
var viewModel: CarViewModel!
typealias viewModelType = CarViewModel
}
class PlaneViewController: UIViewController, ViewControllerProtocol {
var viewModel: PlaneViewModel!
typealias viewModelType = PlaneViewModel
}
@sandeeplearner
sandeeplearner / .swift
Last active May 12, 2020 22:03
Protocol with associated type
protocol ViewControllerProtocol: UIViewController {
associatedtype viewModelType
var viewModel: viewModelType! { get set }
init(with viewModel: viewModelType)
}
extension ViewControllerProtocol {
init(with viewModel: viewModelType) {
self.init(nibName: nil, bundle: nil)
@sandeeplearner
sandeeplearner / .swift
Created May 12, 2020 21:21
Duplicate code
private let viewModel:CarViewModel
required init(with viewModel: CarViewModel) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}
@sandeeplearner
sandeeplearner / viewControllerWithViewModel.swift
Created May 12, 2020 21:13
ViewController with ViewModel
class CarViewController: UIViewController {
private let viewModel:CarViewModel
required init(with viewModel: CarViewModel) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
@sandeeplearner
sandeeplearner / .swift
Created May 11, 2020 21:58
Dynamic polymorphism
class ViewControllerV2: UIViewController {
var passedClass: Description!
override func viewDidLoad() {
super.viewDidLoad()
debugPrint(passedClass.discribe())
}
}
@sandeeplearner
sandeeplearner / .swift
Created May 11, 2020 21:54
Description variable declaration
var passedClass: Description!