Skip to content

Instantly share code, notes, and snippets.

View LouisCAD's full-sized avatar

Louis CAD LouisCAD

View GitHub Profile
@c5inco
c5inco / WearPreviewUtility.kt
Last active February 22, 2022 16:24
Small utility for framing a Compose Wear app in a watch bezel, whether round, square, or rectangular.
import android.content.res.Configuration
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
@mpetuska
mpetuska / JSObj.kt
Created October 14, 2021 10:49
Fluent Kotlin DSL for building JSON trees
@DslMarker
annotation class JSBuilderDsl
@DslMarker
annotation class JSSetterDsl
data class JSObj(val map: MutableMap<String, Any?> = mutableMapOf()) : MutableMap<String, Any?> by map {
object Arr {
@JSBuilderDsl
operator fun get(vararg items: Any?) = items
@simonschiller
simonschiller / discard-kotlin-intrinsics.pro
Created September 16, 2021 18:19
Snippet for R8/ProGuard to discard Kotlin Intrinsics checks
-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
public static void checkNotNull(java.lang.Object);
public static void checkNotNull(java.lang.Object, java.lang.String);
public static void checkExpressionValueIsNotNull(java.lang.Object, java.lang.String);
public static void checkNotNullExpressionValue(java.lang.Object, java.lang.String);
public static void checkReturnedValueIsNotNull(java.lang.Object, java.lang.String, java.lang.String);
public static void checkReturnedValueIsNotNull(java.lang.Object, java.lang.String);
public static void checkFieldIsNotNull(java.lang.Object, java.lang.String, java.lang.String);
public static void checkFieldIsNotNull(java.lang.Object, java.lang.String);
public static void checkParameterIsNotNull(java.lang.Object, java.lang.String);
@mwolfson
mwolfson / Color.kt
Last active March 27, 2024 07:28
Material Design Color Resources for Jetpack Compose
import androidx.compose.ui.graphics.Color
// Material Color Resources
val amber_050 = Color(0xFFfff8e1) // Use with black text
val amber_100 = Color(0xFFffecb3) // Use with black text
val amber_200 = Color(0xFFffe082) // Use with black text
val amber_300 = Color(0xFFffd54f) // Use with black text
val amber_400 = Color(0xFFffca28) // Use with black text
val amber_500 = Color(0xFFffc107) // Use with black text
@bryansills
bryansills / WhiteBalanceAdjuster.kt
Last active July 25, 2021 11:31
Auto White Balance Adjustment
import android.graphics.Bitmap
import android.graphics.Color
import androidx.annotation.ColorInt
import com.curiouscreature.kotlin.math.Float3
import com.curiouscreature.kotlin.math.Mat3
import com.curiouscreature.kotlin.math.saturate
import com.curiouscreature.kotlin.math.transpose
import kotlin.math.pow
@hsnmrd
hsnmrd / RecyclerEdgeEffect.kt
Last active July 15, 2022 19:16
it supports vertical and horizontal effect
import android.graphics.Canvas
import android.widget.EdgeEffect
import androidx.dynamicanimation.animation.SpringAnimation
import androidx.dynamicanimation.animation.SpringForce
import androidx.recyclerview.widget.RecyclerView
/** The magnitude of translation distance while the list is over-scrolled. */
private const val OVERSCROLL_TRANSLATION_MAGNITUDE = 0.2f
@handstandsam
handstandsam / MyLifecycleOwner.kt
Last active January 30, 2025 02:47
Jetpack Compose OverlayService. You have to have all the correct permissions granted and in your manifest, but if you do, this this will show a green box with "Hello" in it!
import android.os.Bundle
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleRegistry
import androidx.savedstate.SavedStateRegistry
import androidx.savedstate.SavedStateRegistryController
import androidx.savedstate.SavedStateRegistryOwner
internal class MyLifecycleOwner : SavedStateRegistryOwner {
private var mLifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this)
private var mSavedStateRegistryController: SavedStateRegistryController = SavedStateRegistryController.create(this)
@ntherning
ntherning / build.gradle.kts
Last active October 27, 2020 09:02
Kotlin MPP iOS buildForXcode task - only build the configuration requested by Xcode and only invoke Gradle when needed
kotlin {
val isIosDevice = getenv("PLATFORM_NAME")?.startsWith("iphoneos") == true
val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget = if (isIosDevice) ::iosArm64 else ::iosX64
fun iosBuildDir(isDebug: Boolean, isDevice: Boolean): File {
return project.buildDir.resolve(buildString {
append("bin/ios/")
append(if (isDebug) "Debug" else "Release")
append("-")
append(if (isDevice) "iphoneos" else "iphonesimulator")
})
@fluidsonic
fluidsonic / FlowCombineLatest.kt
Last active July 2, 2024 07:28
Fast flow combination
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
private val undefined = Any()
internal fun <T> Iterable<Flow<T>>.combineLatest(): Flow<List<T>> =
combineLatest { it }
@fluidsonic
fluidsonic / FlowShareIn.kt
Created October 11, 2020 15:36
Rudimentary Flow.shareIn with WhenSubscribed behavior until the official operator is launched
fun <T> Flow<T>.shareIn(scope: CoroutineScope): Flow<T> {
val upstream = this
var broadcastChannel: BroadcastChannel<T>? = null
val mutex = Mutex()
var subscriberCount = 0
return flow {
val activeChannel = mutex.withLock {
subscriberCount += 1
broadcastChannel ?: upstream.broadcastIn(scope).also {