I hereby claim:
- I am lduncandroid on github.
- I am lduncandroid (https://keybase.io/lduncandroid) on keybase.
- I have a public key ASAOQZsKTkEH14w2y882fSvi50PhMuHeELEbx_-t4tTQdwo
To claim this, I am signing this object:
import kotlin.random.Random | |
import kotlin.random.nextInt | |
// https://stackoverflow.com/posts/69076855/revisions @aSemy | |
val randomInts = generateSequence { | |
// this lambda is the source of the sequence's values | |
Random.nextInt(1..69) | |
} | |
// make the values distinct, so there's no repeated ints | |
.distinct() |
[ | |
{ | |
"title": "Amandine", | |
"image": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e3/Amandine_cake.jpg/200px-Amandine_cake.jpg", | |
"desc": "Chocolate layered cake filled with chocolate, caramel and fondant cream" | |
}, | |
{ | |
"title": "Angel cake", | |
"image": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/Homemade_Angel_Slice_Cake_Stock_Photo_%2848754448236%29.jpg/200px-Homemade_Angel_Slice_Cake_Stock_Photo_%2848754448236%29.jpg", | |
"desc": "Sponge cake, cream, food colouring" |
import com.squareup.okhttp.Interceptor | |
import com.squareup.okhttp.MediaType | |
import com.squareup.okhttp.Response | |
import com.squareup.okhttp.ResponseBody | |
import okio.BufferedSource | |
import okio.GzipSource | |
import okio.Okio | |
class ResponseBodyLogger : Interceptor { | |
override fun intercept(chain: Interceptor.Chain): Response { |
fun <T> Iterable<T>.countPairs() = groupingBy { it } | |
.eachCount() | |
.values | |
.sumOf { it.div(2) } | |
fun <T> Sequence<T>.countPairs() = groupBy { it } | |
.mapValues { it.value.size } | |
.values | |
.sumOf {it.div(2)} |
class LRUCache(capacity: Int) { | |
private val internalCache: LinkedHashMap<Int, Int> = | |
object : LinkedHashMap<Int, Int>(initialCapacity = capacity, loadFactor = 0.75f, accessOrder = true) { | |
override fun removeEldestEntry(eldest: MutableMap.MutableEntry<Int, Int>?): Boolean { | |
return size > capacity | |
} | |
} | |
fun get(key: Int) = internalCache.getOrDefault(key, -1) |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.flow.* | |
import kotlinx.coroutines.runBlocking | |
// Following the RxJava implementation here: https://blog.mindorks.com/implement-caching-in-android-using-rxjava-operators | |
data class Data(val source: String) | |
class MemoryDataSource { |
I hereby claim:
To claim this, I am signing this object:
package com.beflukey.shootproofdownloader | |
import org.openqa.selenium.By | |
import org.openqa.selenium.chrome.ChromeDriver | |
import org.openqa.selenium.support.ui.ExpectedConditions.presenceOfAllElementsLocatedBy | |
import org.openqa.selenium.support.ui.WebDriverWait | |
import java.io.* | |
import java.net.URL | |
import java.time.Duration |
abstract class DataBoundAdapter<T, V : ViewDataBinding>( | |
diffCallback: DiffUtil.ItemCallback<T> | |
) : ListAdapter<T, DataBoundViewHolder<V>>(diffCallback) { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DataBoundViewHolder<V> { | |
val binding = createBinding(parent) | |
return DataBoundViewHolder(binding) | |
} | |
protected abstract fun createBinding(parent: ViewGroup): V |