This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
import kotlinx.coroutines.channels.* | |
import kotlinx.coroutines.flow.* | |
fun <T> Flow<T>.chunked(size: Int): Flow<List<T>> = flow { | |
val elements = ArrayList<T>(size) | |
collect { | |
elements.add(it) | |
if (elements.size == size) { | |
emit(elements.toList()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
import kotlinx.coroutines.channels.* | |
import kotlinx.coroutines.flow.* | |
suspend fun <T> Flow<T>.collectInParallel( | |
concurrency: Int, | |
collector: suspend (T) -> Unit | |
) = coroutineScope { | |
val channel: Channel<T> = Channel() | |
repeat(concurrency) { launch { for (e in channel) collector(e) } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.louiscad.splitties.eap.bottomsheet | |
import android.app.Activity | |
import android.view.ViewGroup | |
import androidx.activity.compose.BackHandler | |
import androidx.compose.material.ExperimentalMaterialApi | |
import androidx.compose.material.ModalBottomSheetLayout | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.DisposableEffect | |
import androidx.compose.runtime.getValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@file:Suppress("experimental_is_not_enabled") | |
@file:OptIn(ExperimentalTime::class) | |
import kotlin.math.sqrt | |
import kotlin.time.Duration | |
import kotlin.time.DurationUnit | |
import kotlin.time.ExperimentalTime | |
//// Metrics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.w3c.dom.Document | |
import org.w3c.dom.Text | |
import java.io.StringWriter | |
import javax.xml.transform.OutputKeys | |
import javax.xml.transform.TransformerFactory | |
import javax.xml.transform.dom.DOMSource | |
import javax.xml.transform.stream.StreamResult | |
fun Document.toText(): String { | |
val domSource = DOMSource(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns the line and the column of [index] in the given CharSequence. | |
*/ | |
fun CharSequence.getLineAndColumn(index: Int): LocationInText { | |
if (index !in 0..lastIndex) { | |
throw IndexOutOfBoundsException(index) | |
} | |
var lineNumber = 1 | |
var columnNumber = 1 | |
forEachIndexed { currentIndex, c -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Serializable | |
import kotlin.reflect.KProperty | |
interface MutableLazy<T> : Lazy<T> { | |
override var value: T | |
} | |
fun <T> mutableLazyOf(value: T): MutableLazy<T> = InitializedLazyImpl(value) | |
fun <T> mutableLazy(initializer: () -> T): MutableLazy<T> = SynchronizedLazyImpl(initializer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package i_love_companion_objects | |
suspend fun main() { | |
// Discoverability is easy with the companion object | |
// (although autocomplete could use some performance improvements...) | |
doStuff(SomeInterface.createWithDefaults()) | |
val someInstance: SomeInterface = SomeInterface.create( | |
parameterOne = 0, | |
parameterTwo = 1 | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.lifecycle.LiveData | |
import androidx.lifecycle.Observer | |
import androidx.lifecycle.liveData | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.ExperimentalCoroutinesApi | |
import kotlinx.coroutines.channels.awaitClose | |
import kotlinx.coroutines.flow.* | |
import kotlin.time.Duration | |
import kotlin.time.ExperimentalTime | |
import kotlin.time.seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2019 Louis Cognault Ayeva Derman. Use of this source code is governed by the Apache 2.0 license. | |
*/ | |
import android.location.Location | |
import com.google.android.gms.location.LocationCallback | |
import com.google.android.gms.location.LocationRequest | |
import com.google.android.gms.location.LocationResult | |
import com.google.android.gms.location.LocationServices | |
import kotlinx.coroutines.CancellationException |
NewerOlder