Skip to content

Instantly share code, notes, and snippets.

View faruktoptas's full-sized avatar
🐝
I may be slow to respond.

Faruk Toptaş faruktoptas

🐝
I may be slow to respond.
View GitHub Profile
@faruktoptas
faruktoptas / debounce.kt
Created March 5, 2020 06:28
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)
object MrzValidator {
private val COEFFICIENTS = listOf(7, 3, 1)
private const val EMPTY = '<'
/**
* Samples:
* - Document number: isValid("D123456785", 0, 9) actual document number is "D12345678" check character is "5"
* - Date: isValid("7903063", 0, 6)) actual date is "790306" check character is "3"
*/
import android.databinding.DataBindingUtil
import android.databinding.ViewDataBinding
import android.support.annotation.IdRes
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
abstract class BaseBindingListAdapter<T, in DB : ViewDataBinding> : RecyclerView.Adapter<BaseBindingListAdapter<T, DB>.BaseViewHolder>() {
# Add curl
apk add curl
# Response time
curl -o /dev/null -s -w 'Total: %{time_total}s\n' https://www.google.com
@faruktoptas
faruktoptas / RetrofitTest.kt
Created February 2, 2023 19:03
Test Retrofit with mock web server
// testImplementation "com.squareup.okhttp3:mockwebserver:4.7.2"
class RetrofitTest {
@get:Rule
private val server = MockWebServer().apply { dispatcher = MockDispatcher() }
private lateinit var api: Api
@Before
fun setup() {