Skip to content

Instantly share code, notes, and snippets.

View gkaffka's full-sized avatar

Gabriel Kaffka gkaffka

View GitHub Profile
@Kardelio
Kardelio / edit-pref-file.sh
Last active July 11, 2023 14:58
Edit an apps shared preference entire file from a bash script (using run-as & sed)
#!/usr/bin/env bash
# IMPORTANT:
# make sure to edit the variables below to make the script work for you and your app
package="my.package.com"
filename="sharedprefs.xml"
line=$(adb exec-out run-as "$package" cat "/data/data/$package/shared_prefs/$filename")
echo "$line" > /tmp/editpreffile.txt
@Kardelio
Kardelio / android-tap-if-exists.sh
Created April 7, 2023 11:01
Bash script to trigger python uiautomator2 to get specific UI element on android screen and click it if it exists
#!/usr/bin/env bash
#NOTE: requires python3 and the pip package uiautomator2
#These functions can be copied over to your own bash script
#and can be used by simply triggering tapIfExists...
function tapIfExists(){
coords=$(getCoords "${1}")
if [[ "$coords" != "-" ]]; then
$fullAdb shell input tap "$coords"
fi
@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>()
@tntclaus
tntclaus / generateAndroidDrawables.sh
Last active November 1, 2023 18:24
Simple Android drawable image resource generator script with specified DP with ImageMagic or Inkscape
#!/bin/sh
# Example usage:
# ./generateAndroidDrawables.sh my_image.png 140 /absolute/path/to/android/res/drawables
#
# Will generate 140dp android drawables for 6 DPI on out/my_image.png/ directory.
# Be sure your original image has sustainable resolution for xxxhdpi drawable,
# which is 140 x 4 PX in case of this example.
#
# Requires ImageMagic
# SVG conversion recommended to be done with Inkscape:
@willurd
willurd / web-servers.md
Last active May 4, 2024 07:22
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000