Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aprofromindia
aprofromindia / store.ts
Last active August 4, 2021 13:29
Typescript Redux Store bypassing Singleton pattern for testing React Container Components.
import { configureStore } from '@reduxjs/toolkit';
import user from './user';
export default function getStore() {
return configureStore({
reducer: {
user,
},
});
}
@aprofromindia
aprofromindia / demo.json
Created July 6, 2020 11:16
Demo Json gist
{
"_index": "catalogue-production-2020-06-23-all",
"_type": "_doc",
"_id": "Stern--eBCVu6XGP6CW99YQ_ux_Q",
"_score": 22.804287,
"_source": {
"id": "Stern--eBCVu6XGP6CW99YQ_ux_Q",
"type": "podcast_episode",
"mediatype": "audio",
"title": "Das haben sie hinterlassen",
@aprofromindia
aprofromindia / CoroutineTestRule.kt
Last active December 31, 2019 23:24 — forked from AniketSK/CoroutineTestRule.kt
A test rule to allow testing coroutines that use the main dispatcher. Without this you'd run into "java.lang.IllegalStateException: Module with the Main dispatcher had failed to initialize. For tests Dispatchers.setMain from kotlinx-coroutines-test module can be used"
package com.aniketkadam.sharevideoshortcut
import org.junit.rules.TestWatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.runner.Description
@aprofromindia
aprofromindia / ObserverProtocol.swift
Created December 20, 2019 12:24
Observable, Subscriber Protocols and Extensions in Swift
//
// ObserverProtocols.swift
//
// Created by Apro on 18/12/19.
//
import Foundation
protocol Subscriber: class, Hashable {
associatedtype State
@aprofromindia
aprofromindia / ImageTextField.swift
Created December 19, 2019 08:51
UITextField with Left and Right Image
//
// ImageTextField.swift
// Created by Apro on 17/12/19.
//
import UIKit
@IBDesignable
class ImageTextField: UITextField {
@IBInspectable var leftIcon: UIImage?
@aprofromindia
aprofromindia / Optional+String.swift
Created December 13, 2019 14:06
Optional String conversion gists
//
// Optional+String.swift
//
// Created by Apro on 13/12/19.
//
import Foundation
extension Optional where Wrapped: Numeric & LosslessStringConvertible {
func stringOrEmpty() -> String {
@aprofromindia
aprofromindia / ButtonSwitch.swift
Created December 12, 2019 11:24
Swift UIButtonSwitch, toggles selected state upon touch
import UIKit
class ButtonSwitch: UIButton {
override func sendAction(_ action: Selector, to target: Any?, for event: UIEvent?) {
if allControlEvents == .touchUpInside {
isSelected.toggle()
}
super.sendAction(action, to: target, for: event)
}
}
@aprofromindia
aprofromindia / UIColor+RGB.swift
Created December 6, 2019 15:49
UIColor RGB gist
//
// UIColor+RGB.swift
//
// Created by Apro on 06/12/19.
//
import UIKit
extension UIColor {
convenience init(red: Int, green: Int, blue: Int) {
@aprofromindia
aprofromindia / JSONDecoder+File.swift
Last active December 12, 2019 23:11
Swift JSONDecoder decode file
//
// Created by Apro on 06/12/19.
//
import UIKit
extension JSONDecoder {
private static let fileType = "json"
func decodeFile<T: Codable>(name: String, completion: @escaping (Result<T, Error>) -> Void) {
@aprofromindia
aprofromindia / UIViewController+Storyboard.swift
Last active December 20, 2019 12:55
UIViewController instantiate ViewController from Storyboard with same name
//
// Created by Apro on 04/12/19.
//
import UIKit
extension UIViewController {
func instantiateVC<VC: UIViewController>(storyboardId: String? = nil) -> VC {
return storyboard?.instantiateViewController(withIdentifier: storyboardId ?? String(describing: VC.self)) as! VC
}