Skip to content

Instantly share code, notes, and snippets.

Avatar

Héctor de Isidro hrules6872

View GitHub Profile
@hrules6872
hrules6872 / StickyHeaderItemDecoration.kt
Last active Sep 11, 2019
ItemDecorator for sticky headers in Kotlin
View StickyHeaderItemDecoration.kt
import android.graphics.*
import android.view.*
import android.view.MotionEvent.ACTION_DOWN
import androidx.recyclerview.widget.RecyclerView
class StickyHeaderItemDecoration(
parent: RecyclerView,
private val isHeader: (position: Int) -> Boolean
) : RecyclerView.ItemDecoration() {
@hrules6872
hrules6872 / delete-darktable-rejected.sh
Created Aug 18, 2019
Delete all Darktable rejected and low-rated pictures
View delete-darktable-rejected.sh
#!/bin/sh
if [ -z "$1" ]; then
echo Delete all Darktable rejected pictures
echo
echo "Usage:"
echo $0 [source] --onestar to delete also all pictures with one star rating
exit 1
fi
@hrules6872
hrules6872 / ClazzesExt.kt
Last active Aug 12, 2019
Reduce two (Data) Classes in Kotlin
View ClazzesExt.kt
inline infix fun <reified T : Any> T?.reduce(other: T?): T? = when {
this == null && other == null -> null
this != null && other == null -> this
this == null && other != null -> other
else -> {
val nameToProperty = T::class.declaredMemberProperties.associateBy { property -> property.name }
val primaryConstructor = T::class.primaryConstructor!!
val args = primaryConstructor.parameters.associate { parameter ->
val property = nameToProperty[parameter.name]!!