Skip to content

Instantly share code, notes, and snippets.

@tuannha95
tuannha95 / RxSearchObservable.java
Created August 18, 2021 06:59 — forked from snijsure/RxSearchObservable.java
Implement search using RxJava
public class RxSearchObservable {
public static Observable<String> fromView(SearchView searchView) {
final PublishSubject<String> subject = PublishSubject.create();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
subject.onComplete();
@tuannha95
tuannha95 / README.md
Last active July 11, 2022 19:28
Reset Parallels' trial
@tuannha95
tuannha95 / git-ssh-error-fix.sh
Created April 16, 2021 08:03 — forked from Tamal/git-ssh-error-fix.sh
Solution for 'ssh: connect to host github.com port 22: Connection timed out' error
$ git clone git@github.com:xxxxx/xxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
$ # This should also timeout
$ ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed out
$ # but this might work
fun isVietnamesePhoneNumber(): Boolean {
phoneNumber.value?.let {
val pattern = "(03|07|08|09|01[2|6|8|9])+([0-9]{8})\\b".toRegex()
return pattern.matches(it)
}
return false
}
package com.gunaya.demo.demomeow.presentation.base
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.gunaya.demo.demomeow.utils.EventWrapper
import com.gunaya.demo.demomeow.utils.SingleLiveEvent
import com.gunaya.demo.demomeow.utils.UseCaseResult
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
@tuannha95
tuannha95 / debounce.kt
Created July 29, 2020 04:15 — forked from faruktoptas/debounce.kt
Kotlin coroutine debounce for EditText
fun <T> debounce(
waitMs: Long = 300L,
scope: CoroutineScope,
destinationFunction: (T) -> Unit
): (T) -> Unit {
var debounceJob: Job? = null
return { param: T ->
debounceJob?.cancel()
debounceJob = scope.launch {
delay(waitMs)
@tuannha95
tuannha95 / Preferences.kt
Created October 8, 2019 04:52 — forked from wispborne/Preferences.kt
Android SharedPreferences helper class for Kotlin. Easy-to-use delegated properties, automatic database creation, and listening for property changes.
import android.content.Context
import android.content.SharedPreferences
import kotlin.reflect.KProperty
/**
* Represents a single [SharedPreferences] file.
*
* Usage:
*
* ```kotlin
package com.thunderclouddev.changelogs.ui
import android.content.Context
import android.os.Bundle
import android.support.annotation.LayoutRes
import android.support.annotation.StyleRes
import android.support.v7.app.AppCompatActivity
import com.thunderclouddev.changelogs.BaseApplication
import com.thunderclouddev.changelogs.R
import com.thunderclouddev.changelogs.configuration.LanguagePreference