Skip to content

Instantly share code, notes, and snippets.

@hector6872
hector6872 / 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 {
@hector6872
hector6872 / 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;
@hector6872
hector6872 / 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) {
@hector6872
hector6872 / 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 }
@hector6872
hector6872 / ListPadExt.kt
Created February 22, 2023 07:21
Kotlin List.padStart and List.padEnd extensions
fun <TYPE> List<TYPE>.padEndOrCompact(size: Int, fallback: TYPE): List<TYPE> {
if (size < 0) throw IllegalArgumentException("Desired length $size is less than zero.")
return (0 until size).map { this.getOrNull(it) ?: fallback }
}
fun <TYPE> List<TYPE>.padEnd(size: Int, fallback: TYPE): List<TYPE> {
if (size < 0) throw IllegalArgumentException("Desired length $size is less than zero.")
return when {
size > this.size -> this.padEndOrCompact(size, fallback)
else -> this
@hector6872
hector6872 / FadingEdge.kt
Last active April 12, 2023 19:10 — forked from dovahkiin98/FadingEdge.kt
A Jetpack Compose implementation of the `fadingEdge` effect
fun Modifier.horizontalFadingEdge(
scrollState: ScrollState,
length: Dp,
edgeColor: Color? = null,
) = composed(
debugInspectorInfo {
name = "length"
value = length
}
) {
@hector6872
hector6872 / ComposeStore.kt
Last active November 29, 2024 12:17
Zustand 🐻 implementation for Kotlin :) https://github.com/pmndrs/zustand
/*
* Copyright (c) 2022. Héctor de Isidro - hector6872
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@hector6872
hector6872 / PhoneNumberVisualTransformation.kt
Created April 3, 2023 09:49
Compose PhoneNumber VisualTransformation implementation
class PhoneNumberVisualTransformation(countryCode: String) : SeparatorVisualTransformation() {
private val phoneNumberFormatter = PhoneNumberFormatter(countryCode)
override fun transform(input: CharSequence): CharSequence = phoneNumberFormatter.format(input.toString())
override fun isSeparator(char: Char): Boolean = !PhoneNumberUtils.isNonSeparator(char)
}
private class PhoneNumberFormatter(countryCode: String) {
private val formatter = PhoneNumberUtil.getInstance().getAsYouTypeFormatter(countryCode)
fun format(number: String): String = number
@hector6872
hector6872 / Calendar.kt
Last active April 4, 2023 18:02 — forked from bagus2x/Calendar.kt
Jetpack Compose Simple calendar
@Composable
private fun Calendar(
modifier: Modifier = Modifier,
date: LocalDate
) {
val firstDate = with(date) {
val firstOfMonth = withDayOfMonth(1)
val firstDayOfFirstWeek = firstOfMonth.dayOfWeek.value
firstOfMonth.minusDays(firstDayOfFirstWeek.toLong())
}

"Pair programming is a conversation. You're always talking. You're always explaining. You're always trying to combine your knowledge." - Sarah Mei