Skip to content

Instantly share code, notes, and snippets.

View guuilp's full-sized avatar
😃
Hi!

Guilherme guuilp

😃
Hi!
View GitHub Profile
@elizarov
elizarov / Debounce.kt
Last active August 26, 2019 00:19
Debounce
import kotlinx.coroutines.experimental.DefaultDispatcher
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.consumeEach
import kotlinx.coroutines.experimental.channels.produce
import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.runBlocking
import kotlin.coroutines.experimental.CoroutineContext
fun <T> ReceiveChannel<T>.debounce(
wait: Long = 300,
@rharter
rharter / SharedPreferenceLiveData.kt
Last active March 19, 2023 08:15
Creates LiveData objects that observe a value in SharedPreferences while they have active listeners.
import android.arch.lifecycle.LiveData
import android.content.SharedPreferences
abstract class SharedPreferenceLiveData<T>(val sharedPrefs: SharedPreferences,
val key: String,
val defValue: T) : LiveData<T>() {
private val preferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
if (key == this.key) {
value = getValueFromPreferences(key, defValue)
@alvinthen
alvinthen / opacity.txt
Created July 29, 2016 17:20
Convert opacity values in percentage to hexadecimal
0% - 00
1% - 03
2% - 05
3% - 08
4% - 0A
5% - 0D
6% - 0F
7% - 12
8% - 14
9% - 17