Skip to content

Instantly share code, notes, and snippets.

@easterapps
easterapps / ActivityRestart.kt
Last active March 23, 2024 18:44
restart android application programmatically
fun triggerRestart(context: Activity) {
val intent = Intent(context, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
if (context is Activity) {
(context as Activity).finish()
}
Runtime.getRuntime().exit(0)
}
@hector6872
hector6872 / delete-darktable-rejected.sh
Created August 18, 2019 12:46
Delete all Darktable rejected and low-rated pictures
#!/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
@hector6872
hector6872 / ClazzesExt.kt
Last active August 12, 2019 19:29
Reduce two (Data) Classes in Kotlin
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]!!
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
@dmytrodanylyk
dmytrodanylyk / description.md
Last active June 20, 2022 15:00
Where this dependency comes from?

Did you ever have android build failed​ issue because of dependency resolution?

… or you were curious where all these old rxjava dependencies come from?

You can pretty easy track the module causing issues via following gradle command.

gradlew :root-module:dependencyInsight \
--configuration debugRuntimeClasspath \ // or debugCompileClasspath
--dependency io.reactivex:rxjava:1.1.0 &gt; dependencies.txt // saves result to 'dependencies.txt' file
@davidvavra
davidvavra / NonNullAssertionDetector.kt
Created March 22, 2019 17:06
Lint check for detecting non-null assertion (!!) in your code
import com.android.tools.lint.client.api.UElementHandler
import com.android.tools.lint.detector.api.*
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UPostfixExpression
class NonNullAssertionDetector : Detector(), Detector.UastScanner {
override fun getApplicableUastTypes(): List<Class<out UElement>>? {
return listOf(UPostfixExpression::class.java)
}
@filipkowicz
filipkowicz / HeaderItemDecoration.kt
Last active February 26, 2025 18:20
Item Decorator for sticky headers in Kotlin
package com.filipkowicz.headeritemdecorator
/*
solution based on - based on Sevastyan answer on StackOverflow
changes:
- take to account views offsets
- transformed to Kotlin
- now works on viewHolders
@shane-harper
shane-harper / appCenterUpload.sh
Created March 6, 2019 13:17
Simple AppCenter Upload Script
#!/bin/sh
owner_name="appcenter-username"
app_name="App-Name"
token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
build_path="Unity-iPhone.ipa"
destination_name="Collaborators"
release_notes="Release notes go here"
# Step 1: Create an upload resource and get an upload_url (good for 24 hours)
request_url="https://api.appcenter.ms/v0.1/apps/${owner_name}/${app_name}/release_uploads"