Skip to content

Instantly share code, notes, and snippets.

View thomashorta's full-sized avatar

Thomas Horta thomashorta

View GitHub Profile
@thomashorta
thomashorta / .aliases
Last active December 27, 2023 23:13
Base alias file
# vars
projects_dir=$HOME/Projects
example_dir=$projects_dir/example
example_dir_android=$example_dir/example-android
# cd aliases
alias cd-proj='cd $projects_dir'
alias cd-ex='cd $example_dir'
alias cd-ex-android='cd $example_dir_android'
@thomashorta
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
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
afterInit()
}
protected open fun afterInit() {}
@thomashorta
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.foundation.ScrollState
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.verticalScroll
import androidx.compose.ui.Modifier