Skip to content

Instantly share code, notes, and snippets.

@handstandsam
handstandsam / intersection.txt
Last active November 7, 2023 19:20
Work in Progress (Not finished) : Kotlin Script to take an AAR file and then strip a list of Classes out of it.
View intersection.txt
fun runCmd(
cwd: File,
cmd: String
) = runCatching {
println("In cwd ${cwd.path}, Running cmd $cmd")
ProcessBuilder("\\s".toRegex().split(cmd))
.directory(cwd)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
@handstandsam
handstandsam / build.gradle.kts
Last active September 26, 2023 16:08
NOTE: Kinda works.... Print Inputs and Output Directories for All Tasks in Project. This filters out all inputs/outputs outside of the project, and only looks at the directories monitored.
View build.gradle.kts
val outputFile = File("output.txt")
if(outputFile.exists() {
outputFile.delete()
}
afterEvaluate {
project.tasks.forEach { task ->
buildString {
appendLine("---------------")
appendLine("${task.name}")
@handstandsam
handstandsam / print_permissions_from_androidmanifest.py
Last active December 14, 2022 10:06
Python Script to parse permissions from an AndroidManifest.xml file, and sort them alphabetically.
View print_permissions_from_androidmanifest.py
from xml.dom.minidom import parseString
# Documentation on Permissions in AndroidManifest.xml
# https://developer.android.com/guide/topics/manifest/manifest-intro#perms
data = '' # string data from file
with open('AndroidManifest.xml', 'r') as f:
data = f.read()
dom = parseString(data) # parse file contents to xml dom
@handstandsam
handstandsam / InstallReferrerExt.kt
Created February 28, 2022 20:29
Install Referrer KTX - Kotlin Coroutine friendly wrapper for the Google Play's InstallReferrerClient API. This API is used to ask Google Play about where the installation originated.
View InstallReferrerExt.kt
import android.content.Context
import android.os.RemoteException
import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerStateListener
import com.android.installreferrer.api.ReferrerDetails
import kotlinx.coroutines.CompletableDeferred
/**
* https://developer.android.com/google/play/installreferrer/library
*
@handstandsam
handstandsam / PokeballCompose.kt
Created January 16, 2022 20:24
Draw a Pokeball on Canvas using Jetpack Compose
View PokeballCompose.kt
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
@handstandsam
handstandsam / Actor.kt
Created December 14, 2021 14:20
There is no support for Actor in Kotlin Multiplatform, nor is it planned. More info: https://github.com/Kotlin/kotlinx.coroutines/issues/87). What are the flaws of this?
View Actor.kt
/**
* JVM Implementation from KotlinX Coroutines
* https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/src/channels/Actor.kt#L31-L124
*/
@ObsoleteCoroutinesApi
public fun <E> CoroutineScope.actor(
context: CoroutineContext = EmptyCoroutineContext,
capacity: Int = 0, // todo: Maybe Channel.DEFAULT here?
start: CoroutineStart = CoroutineStart.DEFAULT,
onCompletion: CompletionHandler? = null,
@handstandsam
handstandsam / Dropdown.kt
Created July 20, 2021 12:23
Jetpack Compose Snippets
View Dropdown.kt
@Composable
fun DropdownComposable(items: List<String> = listOf("A", "B", "C"), onClick: (String) -> Unit) {
var expanded by remember { mutableStateOf(false) }
var selectedIndex by remember { mutableStateOf(0) }
Box(
modifier = Modifier
.wrapContentSize(Alignment.TopStart)
) {
Text(
text = state.value.eventName,
@handstandsam
handstandsam / MyLifecycleOwner.kt
Last active November 21, 2023 03:53
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!
View MyLifecycleOwner.kt
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)
View ImmutableDataWithMutableStateFlowTest.kt
package com.handstandsam.mutablestateflow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Test
class UseImmutableDataWithMutableStateFlow {
data class SomePojo(var name: String = "placeholder")
@handstandsam
handstandsam / a_Classes.kt
Last active June 8, 2020 21:26
Wrapping Mockito Mocks for Reusability
View a_Classes.kt
/** Whether the Oven command was successful, or something happened */
sealed class OvenResult {
object Success : OvenResult()
data class Failure(val e: Exception) : OvenResult()
}
/** Class we will use Mockito to Mock */
class Oven {
fun setTemperatureFahrenheit(tempF: Int) {
TODO("Implementation Goes Here")