Skip to content

Instantly share code, notes, and snippets.

@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")
@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 / 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 / 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 / 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 / kill-hung-emulators.sh
Last active August 18, 2017 07:37
Kill Hung Emulators on CI (Mac & Linux) that have been running more than 1 hour
#!/bin/bash
# Will find all emulator processes that have been running longer than an hour, and kill -9 them.
SEARCH_TERM="qemu-system"
echo "$(ps eaxo etime,pid,comm | grep ${SEARCH_TERM})" | while read line
do
if [ "${#line}" -gt 0 ]; then
echo "Found Emulator -> $line"
COLUMNS=()
for word in $line
@handstandsam
handstandsam / Example Output
Created August 17, 2017 20:14
Killing Hung Emulators on CI (Mac & Linux Commands)
15:56:46 Found Emulator -> 1-04:55:18 93339 qemu-system-i38
15:56:46 EMULATOR has been running longer than an hour 1-04:55:18, KILLING PID 93339
15:56:46 Found Emulator -> 1-04:30:54 94320 qemu-system-i38
15:56:46 EMULATOR has been running longer than an hour 1-04:30:54, KILLING PID 94320
15:56:46 Found Emulator -> 1-02:16:26 96137 qemu-system-i38
15:56:48 EMULATOR has been running longer than an hour 1-02:16:26, KILLING PID 96137
15:56:48 Found Emulator -> 23:41:33 100149 qemu-system-i38
15:56:48 EMULATOR has been running longer than an hour 23:41:33, KILLING PID 100149
15:56:48 Found Emulator -> 23:40:02 100494 qemu-system-i38
15:56:48 EMULATOR has been running longer than an hour 23:40:02, KILLING PID 100494
@handstandsam
handstandsam / is_job_done.sh
Last active February 22, 2023 15:17
Bash Script - Get Jenkins Job Status over API
#!/bin/bash
BUILD_NUMBER="";
STATUS="None";
COMPLETE="false";
function isJenkinsJobComplete() {
API_RESPONSE=`curl ${1}`;
STATUS=`echo "${API_RESPONSE}" | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["result"]'`;
BUILD_NUMBER=`echo "${API_RESPONSE}" | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["id"]'`;
@handstandsam
handstandsam / create_emulator.sh
Created April 25, 2017 17:07
Script to Create Android Emulator for Espresso Tests on CI
AVD_NAME="384x640_mdpi_api_23"
echo "Creating (forceful) AVD with name ${AVD_NAME}"
# We have to echo "no" because it will ask us if we want to use a custom hardware profile, and we don't.
CREATE_AVD_COMMAND="android create avd \
--name ${AVD_NAME} \
--target android-23 \
--skin 384x640 \
--abi google_apis/x86_64 \
--force"
@handstandsam
handstandsam / SSLHandshakeInterceptor.java
Created April 7, 2017 17:57
OkHttp 3 SSL Handshake Interceptor - Prints TLS Version & Cipher Suite Used
import android.util.Log;
import java.io.IOException;
import okhttp3.CipherSuite;
import okhttp3.Handshake;
import okhttp3.Response;
import okhttp3.TlsVersion;
/** Prints TLS Version and Cipher Suite for SSL Calls through OkHttp3 */
public class SSLHandshakeInterceptor implements okhttp3.Interceptor {