Skip to content

Instantly share code, notes, and snippets.

<html>
<body>
<h2>Privacy Policy</h2>
<p>Iveta Jurčíková and Benjamín Varga built the L.I.F.T. app as a free app. This SERVICE is provided by Iveta Jurčíková and Benjamín Varga at no cost and is intended
for use as is.</p>
<p>This page is used to inform website visitors regarding our policies with the collection, use, and
disclosure of Personal Information if anyone decided to use our Service.</p>
<p>If you choose to use our Service, then you agree to the collection and use of information in
relation with this policy. The Personal Information that we collect are used for providing and
improving the Service. We will not use or share your information with anyone except as described
val reducer = BiFunction { previousState: CountryListViewState, result: CountryListResult ->
when (result) {
is LoadCountriesResult ->
when (result) {
is LoadCountriesResult.Success -> {
previousState.copy(
isLoading = false,
isRefreshing = false,
countries = result.countries
)
data class CountryListViewState(
val isLoading = false,
val countries = emptyList(),
val isRefreshing = true,
val error = `UnknownHostException…`)
class MyProfileViewModel {
val progress = MutableLiveData()
val myProfile = MutableLiveData()
override fun loadProfile() {
progress.value = true
subscriptions.add(
myProfileInteractor.getLoggedUser().subscribe(
@ywett02
ywett02 / progress_request_body.kt
Last active February 2, 2019 10:15
File upload with progress
import okhttp3.MediaType
import okhttp3.RequestBody
import okio.BufferedSink
import okio.Okio
import java.io.File
import kotlin.math.roundToInt
class ProgressByteArrayRequestBody(
private val contentType: MediaType,
private val array: ByteArray,
@ywett02
ywett02 / debounce.kt
Created January 28, 2019 13:07
Simple debounce extension for LiveData
import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MediatorLiveData
import android.os.Handler
import android.os.Looper
fun <T> LiveData<T>.debounce(duration: Long = 1000L) = MediatorLiveData<T>().also { mld ->
val source = this
val handler = Handler(Looper.getMainLooper())
val runnable = Runnable {
package com.livepenalty.android
import com.livepenalty.android.CommitRange.BiDirectional
import com.livepenalty.android.CommitRange.UniDirectional
import com.livepenalty.android.ConventionalCommit.chore
import com.livepenalty.android.ConventionalCommit.docs
import com.livepenalty.android.ConventionalCommit.feat
import com.livepenalty.android.ConventionalCommit.fix
import com.livepenalty.android.ConventionalCommit.other
import com.livepenalty.android.ConventionalCommit.refactor
import kotlin.contracts.contract
sealed class Either<out E, out V> {
data class Error<out E>(val error: E) : Either<E, Nothing>()
data class Value<out V>(val value: V) : Either<Nothing, V>()
}
typealias Left<T> = Either.Error<T>
typealias Right<T> = Either.Value<T>
@ywett02
ywett02 / CoroutineTesting.kt
Last active December 12, 2023 08:36
Coroutine testing - examples using StandardTestDispatcher, UnconfinedTestDispatcher, TestsScope, and runTest [inspired by Kotlin Coroutines Deep Dive book]
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
fun main() {
println("--- StandardTestDispatcher: 1. example ---")