Skip to content

Instantly share code, notes, and snippets.

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.VectorConverter
import androidx.compose.animation.core.spring
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.forEachGesture
@hrules6872
hrules6872 / KotlinExt.kt
Created October 2, 2022 13:15
Map It Please for Kotlin
/**
* Map it please. Returns a list containing the results of applying the
* given transform function to each element in the original collection.
*
* OP: https://twitter.com/jeranfox/status/1575133458631999488
*/
inline fun <TYPE, RESULT> Iterable<TYPE>.mip(transform: TYPE.() -> RESULT): List<RESULT> = map { it.transform() }
/** before:
* users.map { it.firstName }
@hrules6872
hrules6872 / SealedClassExt.kt
Last active September 22, 2022 16:01
safeOf(): returns the first subclass of a Sealed Class matching the given [predicate], or [default] if no such element was found / values(): list all subclasses (Kotlin)
fun <T : Any> KClass<T>.safeOf(default: T, predicate: (T) -> Boolean): T = this.values().find { predicate(it) } ?: default
fun <T : Any> KClass<T>.values(): List<T> {
if (!this.isSealed) throw IllegalCallerException("Receiver MUST be a Sealed class")
return this.sealedSubclasses.map { sealedSubclass ->
when {
sealedSubclass.objectInstance != null -> sealedSubclass.objectInstance!!
else -> try {
sealedSubclass.primaryConstructor?.callBy(mapOf()) ?: throw Exception()
} catch (ignored: Exception) {
@hrules6872
hrules6872 / obsidian-tables-horizontal-scrolling.css
Created August 22, 2022 15:59
Adds horizontal scrolling to tables in Obsidian Notes
/* Adds horizontal scrolling to tables in Obsidian Notes. Tested in Obsidian v0.15.9
See also: https://forum.obsidian.md/t/css-horizontal-scrolling-tables/26581/4
*/
/* in preview / read mode */
.markdown-preview-view table ,
.markdown-source-view table {
display: block; /* This is needed for scrollbar */
width: 100%;
max-width: -moz-max-content;
@dbonillaf
dbonillaf / links_bonilista_593.md
Last active September 2, 2022 13:33
Links sobre los One Man Armies
@hrules6872
hrules6872 / obsidian-vii-adjustable-readable-line-length.css
Last active May 15, 2023 06:33 — forked from vii33/obsidian-vii-adjustable-readable-line-length.css
Changes the readable line length in Obsidian Notes
/* Changes the readable line length in Obsidian Notes. Tested in Obsidian v0.15.9
See also: https://forum.obsidian.md/t/adjustable-readable-line-length/7564/6
Note: For this the "readable line length" property in settings has to be enabled
(as expected). 700px width is the application's default, adjust all numbers below.
Pixel (or percentage) as a unit enables a width independent from the number of characters
(good when adjusting zoom level / font size). For fixed amount of characters use rem */
:root {
@bagus2x
bagus2x / Calendar.kt
Last active April 4, 2023 17:19
custom calendar with jetpack compose & java.time
private val DaysInMonthCell = GridCells.Fixed(count = 7)
@Composable
fun Calendar(
modifier: Modifier = Modifier,
localDateTime: LocalDateTime
) {
val firstDate = remember(localDateTime) {
with(localDateTime) {
val firstOfMonth = withDayOfMonth(1)
@rock3r
rock3r / rms.xml
Created May 23, 2022 15:01
rms — live template to insert/surround with "val ... by remember { mutableStateOf(...) }"
<template name="rms" value="val $name$ by androidx.compose.runtime.remember { androidx.compose.runtime.mutableStateOf($SELECTION$$END$) }" description="Remember mutableState" toReformat="false" toShortenFQNames="true">
<variable name="name" expression="kotlinSuggestVariableName()" defaultValue="name" alwaysStopAt="true" />
<context>
<option name="KOTLIN_EXPRESSION" value="true" />
</context>
</template>
@vii33
vii33 / obsidian-vii-adjustable-readable-line-length.css
Last active April 13, 2024 14:50
Changes the readable line length in Obsidian Notes. Tested in Obsidian v1.0.0
/* Changes the readable line length in Obsidian Notes. Tested in Obsidian v1.0.0
See https://gist.github.com/vii33/f2c3a85b64023cefa9df6420730c7531/f4ea845b240e94c9fcd47d456340f78208dab38f
*/
body {
--file-line-width: 750px;
}
@hrules6872
hrules6872 / CircleView.kt
Created January 12, 2022 17:57
Circle View for Android in Kotlin
class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : View(context, attrs, defStyleAttr) {
private val paint by lazy { Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL } }
@ColorInt
var color: Int = Color.TRANSPARENT
set(value) {
field = value
invalidate()
}