Skip to content

Instantly share code, notes, and snippets.

@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 {
@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 / prompt.py
Last active December 16, 2023 04:44
Google's Gemini AI Wrote me a Song
import pathlib
import google.generativeai as genai
import google.ai.generativelanguage as glm
API_KEY="..."
genai.configure(api_key=API_KEY)
model = genai.GenerativeModel('gemini-pro')
prompt = "I want to record a song in the next 30 minutes. I am a good guitar player, and okay singer. Can you come up with a simple song and chord progression? Please provide me with the bpm of the song, and be sure to include the following sections: verse, chorus, verse, chorus, bridge, chorus. This song should be about 3 minutes in length. Ideally it will use power chords on guitar or common major and minor chords on a guitar that is tuned in standard."
@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.
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.
val outputFile = File("output.txt")
if(outputFile.exists() {
outputFile.delete()
}
afterEvaluate {
project.tasks.forEach { task ->
buildString {
appendLine("---------------")
appendLine("${task.name}")
@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 / 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
@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 / 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.
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 / 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.
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