Skip to content

Instantly share code, notes, and snippets.

View thomashorta's full-sized avatar

Thomas Horta thomashorta

View GitHub Profile
thomashorta / .aliases
Last active December 27, 2023 23:13
Base alias file
# vars
# cd aliases
alias cd-proj='cd $projects_dir'
alias cd-ex='cd $example_dir'
alias cd-ex-android='cd $example_dir_android'
thomashorta / RunSuspendCatching.kt
Created September 21, 2022 02:18
runCatching alternative for suspend functions for proper structured concurrency.
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.TimeoutCancellationException
* Very similar to [runCatching] but it's better suited for use inside suspend functions, as it
* properly propagates [CancellationException], which are required for correct structured
* concurrency in Coroutines.
* Calls the specified function [block] with `this` value as its receiver and returns its
* encapsulated result if invocation was successful, catching any [Throwable] exception that was
thomashorta / ViewModelSlice.kt
Created September 12, 2023 16:08
Idea for a ViewModelSlice class that has a Coroutine Scope which is the same as the ViewModel it's "attached" to
open class ViewModelSlice {
protected lateinit var viewModelScope: CoroutineScope
private set
fun init(viewModel: ViewModel) {
viewModelScope = viewModel.viewModelScope
protected open fun afterInit() {}
thomashorta / FadingEdgesModifier.kt
Last active December 29, 2023 03:58
FadingEdgesModifier class which add fading edges Modifiers to be used with verticalScroll and horizontalScroll Modifiers.
* Written by Thomás Horta, 2023-12-21.
import androidx.compose.ui.Modifier