Skip to content

Instantly share code, notes, and snippets.

View hrach's full-sized avatar

Jan Škrášek hrach

View GitHub Profile
@hrach
hrach / 1-Destinations.kt
Created October 2, 2022 15:02
Navigation Compose Typed article
import com.kiwi.navigationcompose.typed.Destination
import kotlinx.serialization.Serializable
sealed interface Destinations : Destination {
@Serializable
object BookingList: Destinations
@Serializable
data class BookingDetail(
val bookingId: Long,
@hrach
hrach / SavedMutableStateFlow.kt
Created November 1, 2021 13:04
savedMutableStateFlow
fun <T> ViewModel<*>.savedMutableStateFlow(
initialValue: T,
key: String? = null,
): ReadOnlyProperty<ViewModel<*>, MutableStateFlow<T>> {
var mutableStateFlow: MutableStateFlow<T>? = null
return ReadOnlyProperty { _, property ->
if (mutableStateFlow != null) {
return@ReadOnlyProperty mutableStateFlow!!
}
@hrach
hrach / await.kt
Created July 30, 2021 22:08
Difference between MutableSharedFlow() & Channel()
class Foo1 {
private val unpause = MutableSharedFlow<Unit>()
suspend fun await() {
delay(1000)
unpause.first()
}
fun unpause() {
unpause.tryEmit(Unit)
}
}
@hrach
hrach / share.kt
Last active December 4, 2019 10:42
Flow<T>.share() operator - caches the latest value
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.flow.*
import java.util.concurrent.atomic.AtomicInteger
fun <T> Flow<T>.share(): Flow<T> {
val channel = ConflatedBroadcastChannel<T>()
val counter = AtomicInteger()
var job: Job? = null
return channel
@hrach
hrach / channel.kt
Last active May 24, 2021 08:52
Kotlin Channels Debounce & Throttle
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.consumeEach
import kotlinx.coroutines.experimental.channels.produce
import kotlin.coroutines.experimental.CoroutineContext
fun <E> ReceiveChannel<E>.debounce(
wait: Long = 50,
context: CoroutineContext = DefaultDispatcher
): ReceiveChannel<E> = produce(context) {
[user]
useconfigonly = true
email = ...
name = ...
[core]
excludesfile = ~/.gitignore_global
fscache = true
editor = 'C:/Soft_x86/NPP/notepad++.exe' -multiInst -notabbar -nosession -noPlugin
autocrlf = Input
[color]
@hrach
hrach / AdminerColors.php
Last active April 5, 2017 17:06
Adminer coloring for easy prod/dev recognition
<?php
class AdminerColors
{
function head()
{
static $colors = [
'alpha-adminer.example.com' => '#3C8DBC',
'prod-adminer.example.com' => '#DD4B39',
];
@hrach
hrach / style.css
Last active November 28, 2016 11:46
Custom Style for latest Build Monitor for Jenkins
.build-monitor header .details {
display: none;
}
.build-monitor .slots {
position: absolute;
left: 0;
right: 0;
top: 0;
-webkit-flex: none;
flex: none;
@hrach
hrach / add_pull_request_to_issue_github.sh
Created June 6, 2016 19:25 — forked from JanTvrdik/add_pull_request_to_issue_github.sh
Add pull request to existing issue on github
#!/bin/bash
current_branch="$(git symbolic-ref HEAD 2>/dev/null)" || current_branch="(unknown)"
current_branch=${current_branch##refs/heads/}
github_username="JanTvrdik"
github_token="..."
if [[ $current_branch = "(unknown)" ]]
then
@hrach
hrach / style.css
Created February 26, 2016 11:44
Custom style for CircleCI
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("circleci.com") {
.app-dominant {
background: #FFF;
}
.card {
border: 2px solid #ccc;
border-radius: 4px;
}