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 / DataSource.kt
Last active November 11, 2017 12:42
Fragment Navigation Pattern
interface DataSourceBase
class DataSource {
companion object {
private var sInstance: DataSource? = null
private var LOCK = Any()
fun getInstance(): DataSource? {
synchronized(LOCK) {
if (sInstance == null) {
class FooFragment : BaseFragment<FooPresenter.View, FooPresenter>() {
companion object {
fun newInstance(data: Bar): FooFragment {
val fragment = FooFragment()
val bundle = Bundle()
bundle.putParcelable("bar", data)
fragment.arguments = bundle
return fragment
}
}
class FooPresenter(private val dataSource: DataSource?) : BasePresenter<FooPresenter.View> {
fun push(data: Bar){
dataSource?.push("someKey", data)
}
fun peek() : Bar {
return dataSource?.peek<Bar>("someKey")
}
}
override fun setupView(view: View?) {
safeWith(arguments) { arguments ->
safeWitCouple(zoo, arguments.getParcelable(ZOO), poo, arguments.getParcelable(POO)) { zoo, poo, fromIntent ->
this@Foo.zoo = zoo as World.Zoo
this@Foo.poo = poo as World.Poo
if (fromIntent) {
arguments.remove(ZOO)
arguments.remove(POO)
}
class UniversalAdapter<T, VH : RecyclerView.ViewHolder>(
private val onCreateViewHolder: (ViewGroup?, Int) -> VH,
private val onBindViewHolder: (VH, Int, T) -> Unit,
private val onViewType: ((Int) -> Int)? = null) : RecyclerView.Adapter<VH>(),
Universal<T> {
var items = mutableListOf<T>()
private set
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): VH =
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)
@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()
{
"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",
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")
}
@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,