Skip to content

Instantly share code, notes, and snippets.

@handstandsam
handstandsam / Expo2000.cpp
Created August 30, 2017 01:04
Sam Edwards - High School Junior Expo Project - Year 2000
//Sam Edwards
//expo.cpp
//Include statements
#include<iomanip.h>
#include<iostream.h>
#include<math.h>
#include<string.h>
#include<process.h>
#include<conio.h>
#include<stdlib.h>
@handstandsam
handstandsam / AndroidManifest.xml
Last active January 10, 2019 16:20
NFC Hackathon
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="...">
<!-- To get access to the NFC hardware, you have to apply for permission in the manifest. -->
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.VIBRATE" />
<application>
<activity
android:name=".ui.ContactlessActivity"
@handstandsam
handstandsam / 0_SqlDelight 1.x Quick Start Guide for Android.md
Last active May 29, 2019 12:29
SqlDelight 1.x Quick Start Guide for Android

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: https://github.com/handstandsam/ShoppingApp in that project there is a shopping-cart module and shopping-cart-sqldelight module that are used to implement the DB functionality.

@handstandsam
handstandsam / InMemorySharedPreferences.kt
Last active August 4, 2023 06:12
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 https://gist.github.com/amardeshbd/354173d00b988574ee5019c4ba0c8a0b
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
handstandsam / a_Classes.kt
Last active June 8, 2020 21:26
Wrapping Mockito Mocks for Reusability
/** 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")
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 / MyLifecycleOwner.kt
Last active March 30, 2024 16:59
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)
@handstandsam
handstandsam / Dropdown.kt
Created July 20, 2021 12:23
Jetpack Compose Snippets
@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 / 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?
/**
* 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 / PokeballCompose.kt
Created January 16, 2022 20:24
Draw a Pokeball on Canvas using Jetpack Compose
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