Skip to content

Instantly share code, notes, and snippets.


Sam Edwards handstandsam

View GitHub Profile
handstandsam /
Last active Mar 27, 2022
Python Script to parse permissions from an AndroidManifest.xml file, and sort them alphabetically.
from xml.dom.minidom import parseString
# Documentation on Permissions in AndroidManifest.xml
data = '' # string data from file
with open('AndroidManifest.xml', 'r') as f:
data =
dom = parseString(data) # parse file contents to xml dom
handstandsam / InstallReferrerExt.kt
Created Feb 28, 2022
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 kotlinx.coroutines.CompletableDeferred
handstandsam / PokeballCompose.kt
Created Jan 16, 2022
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
handstandsam / Actor.kt
Created Dec 14, 2021
There is no support for Actor in Kotlin Multiplatform, nor is it planned. More info: What are the flaws of this?
View Actor.kt
* JVM Implementation from KotlinX Coroutines
public fun <E>
context: CoroutineContext = EmptyCoroutineContext,
capacity: Int = 0, // todo: Maybe Channel.DEFAULT here?
start: CoroutineStart = CoroutineStart.DEFAULT,
onCompletion: CompletionHandler? = null,
handstandsam / Dropdown.kt
Created Jul 20, 2021
Jetpack Compose Snippets
View Dropdown.kt
fun DropdownComposable(items: List<String> = listOf("A", "B", "C"), onClick: (String) -> Unit) {
var expanded by remember { mutableStateOf(false) }
var selectedIndex by remember { mutableStateOf(0) }
modifier = Modifier
) {
text = state.value.eventName,
handstandsam / MyLifecycleOwner.kt
Last active Aug 9, 2022
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 / a_Classes.kt
Last active Jun 8, 2020
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")
handstandsam / InMemorySharedPreferences.kt
Last active Oct 30, 2021
Shared Preferences is an Interface, so we can back that interface by an "In Memory" version that never persists anything to the file system. I googled around and the closest thing I found was
View InMemorySharedPreferences.kt
import android.content.SharedPreferences
* In Memory implementation of [SharedPreferences], which just transiently saves data in memory, backed by a [MutableMap].
class InMemorySharedPreferences : SharedPreferences {
private val preferenceValuesMap = mutableMapOf<String, Any?>()
private val changeListeners = mutableListOf<SharedPreferences.OnSharedPreferenceChangeListener>()
handstandsam / 0_SqlDelight 1.x Quick Start Guide for
Last active May 29, 2019
SqlDelight 1.x Quick Start Guide for Android
View 0_SqlDelight 1.x Quick Start Guide for

These are snippets you can use when getting started with SqlDelight 1.x on Android

These snippets should mostly work, but if you want a fully compiling project then please check out my ShoppingApp project here: in that project there is a shopping-cart module and shopping-cart-sqldelight module that are used to implement the DB functionality.