Skip to content

Instantly share code, notes, and snippets.

View radityagumay's full-sized avatar
🏠
Working from home

raditya gumay radityagumay

🏠
Working from home
View GitHub Profile
@radityagumay
radityagumay / proguard-aftertask.gradle
Created July 20, 2021 23:19
Delete certain proguard rule
```groovy
afterEvaluate {
// All proguard tasks shall depend on our filter task
def proguardTasks = tasks.findAll { task ->
task.name.startsWith('transformClassesAndResourcesWithProguardFor') }
proguardTasks.each { task -> task.dependsOn filterConsumerRules }
}
// Let define our custom task that filters some unwanted
// consumer proguard rules
@radityagumay
radityagumay / DataStoreFactory.kt
Last active March 30, 2021 00:05
Singleton Class to Manage DataStore
internal object DataStoreFactory {
private val mapToDataStore = ConcurrentHashMap<String, DataStore<Preferences>>()
fun create(
name: String,
context: Context
): DataStore<Preferences> {
if (mapToDataStore.containsKey(name).not()) {
mapToDataStore[name] = context.getDataStore(
/**
* Implementation Detail
*/
interface FooPresenterContract {
interface Presenter {
fun doWork()
}
interface View {
fun inflated(message: String)
class FooPresenterTest {
private val view = mock<FooPresenterContract.View>()
private val presenter: FooPresenterContract.Presenter = FooPresenter(view)
@Test
fun testDoWork() {
presenter.doWork()
verify(view).inflated("it was success!")
@radityagumay
radityagumay / NetworkBuilder.swift
Created September 10, 2020 15:57
Network Builder in Swift based on Android Retrofit Builder Pattern
protocol Dao {
func insert(key: String, value: Any) -> Bool
func find(key: String) -> Any?
}
protocol StoreAdapterFactory {
func create() -> Dao
}
class StoreMemoryAdapter : Dao {
@radityagumay
radityagumay / ContactBuilder.swift
Last active September 10, 2020 14:24
A builder pattern in swift which follow Head First Design Pattern
class Contact {
private(set) lazy var name: String
private(set) lazy var phoneNumber: String
private(set) lazy var address: String
private(set) lazy var gender: String
private init(
name: String,
phoneNumber: String,
address: String,
fun main() {
val les = Executors.newFixedThreadPool(5)
for (i in 0..9) {
val worker: Runnable = WorkerThread("" + i)
les.execute(worker)
}
les.shutdown()
while (!les.isTerminated) { }
println("Finished all threads")
}
{
"success": {
"total": 1
},
"contents": {
"quotes": [
{
"quote": "I came from a real tough neighborhood. Once a guy pulled a knife on me. I knew he wasn't a professional, the knife had butter on it.",
"length": "132",
"author": "Rodney Dangerfield",
@radityagumay
radityagumay / compose.kt
Last active January 3, 2018 13:56
RxCompose
override fun doSomeWork() {
val d = Observable.create(ObservableOnSubscribe<String> { e ->
for (i in 0 until 10) {
val number = Math.pow(Random().nextInt(100).toDouble(), Random().nextInt(100).toDouble())
e.onNext(number.toString())
}
e.onComplete()
}).compose(loading { isShow ->
if (isShow) {
view.showLoading()
interface Universal<in T> {
fun addAll(items: Collection<T>)
fun add(item: T)
fun update(item: T)
fun updateRange(vararg items: T)
fun remove(item: T, position: Int)