Skip to content

Instantly share code, notes, and snippets.

@davethomas11
davethomas11 / when_in.kt
Created March 4, 2018 18:41
You can use the in keyword in Kotlin with any class that implements operator contains
/**
* Using in keyword with other classes in Kotlin.
* ----------------------------------------------
*
*
* You can provide an operator contains function for a class so
* that you can use the in syntax in a when statement.
*/
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
text_view.text = loadDexFile("dm.dex").text
textView2.text = loadDexFile("dm2.dex").text
}
# Classes.jar is the input file being run through the dex process
dx --dex --output "dexFile.dex" classes.jar
class ModuleLoader(val cacheDir: String) {
fun load(dex: File, cls: String = "com.example.dynamicmodule.DynamicModule"): IDynamicModule {
try {
val classLoader = DexClassLoader(dex.absolutePath, cacheDir,
null, this.javaClass.classLoader)
val moduleClass = classLoader.loadClass(cls)
if (IDynamicModule::class.java.isAssignableFrom(moduleClass)) {
public interface IDynamicModule {
String getText();
}
@davethomas11
davethomas11 / pull-db.sh
Created February 6, 2017 16:14
Pull a database from your Android device
#!/bin/bash
if [ -z "$1" ]; then
echo "Please specify DB file name"
echo "usage $0 [Database File] [App Package]"
exit 1
fi
if [ -z "$2" ]; then
echo "Please specify the package name to run as"
# Dave Thomas Oct 2015
# I've added this function to my ~/.bash_profile
# It allows for quick one liner tests of java code from the command line
# Usage example:
# javai 'System.out.println("Hello, World!");'
#
# Second param can be import statements
# Eg:
#!/bin/bash
#
# Strict mode: http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
#
# Usage: script -f fileToPull -p packageName
#
import System.Environment
import Text.Printf
bz = 0.552284749831
zero = read "0" :: Float
main = do
args <- getArgs
let c = parseArg 0 args
#!/bin/bash
#
# ADB Connect android device for building via wifi
# Based on stack over flow answer:
# http://stackoverflow.com/questions/4893953/run-install-debug-android-applications-over-wi-fi
#
# Usage:
#
# 1. Make sure adb command is in executable path
#