Skip to content

Instantly share code, notes, and snippets.

@hrules6872
hrules6872 / Obsidian-internal-linker.kts
Last active September 14, 2023 10:24
Script for auto-creating [[internal links]] for Obsidian 🔗 https://forum.obsidian.md/t/script-for-auto-creating-internal-links/67245
#!/usr/bin/env kscript
/*
* Copyright (c) 2023. Héctor de Isidro - hrules6872
*
* 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
@hrules6872
hrules6872 / SwipeableSnackbarHost.kt
Created August 17, 2023 16:55
Jetpack Compose Snackbar's swipe-to-dismiss behavior
/*
* Copyright (c) 2023. Héctor de Isidro - hrules6872
*
* 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
@hrules6872
hrules6872 / DragDropLazyColum.kt
Last active April 3, 2024 01:24
LazyColum Drag&Drop implementation in Jetpack Compose
/*
* Copyright (c) 2023. Héctor de Isidro - hrules6872
*
* 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

Pull Requests became popular for two reasons:

  • Asynchronous communication. Developers can review and respond at any time, allowing them to continue development without interruption and review PRs when they come to a natural pause in their flow.
  • Quality Assurance. Reviewing and testing code before it hits the target branch ensures that the target branch stays clean.

How to Pull Request:

  • Authoring
    • Keep them small: it's very tempting to rewrite, refactor, boy scout and reformat the code as you develop but in general, it's best not to do it all at once.
    • Perform a Self-Review: although it's very tempting to just dump your changes in a PR and let other people find the mistakes, create a draft PR and do a full review yourself. You can also use this “self-review” to point things out to your reviewers.
    • Create a meaningful title: keep the title short and meaningful and avoid titles generated from the b

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

@hrules6872
hrules6872 / 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())
}
@hrules6872
hrules6872 / 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
@hrules6872
hrules6872 / ComposeStore.kt
Last active April 2, 2023 17:03
Zustand 🐻 implementation for Kotlin :) https://github.com/pmndrs/zustand
/*
* Copyright (c) 2022. Héctor de Isidro - hrules6872
*
* 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
@hrules6872
hrules6872 / 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
}
) {
@hrules6872
hrules6872 / 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