Skip to content

Instantly share code, notes, and snippets.

View jaredrummler's full-sized avatar

Jared Rummler jaredrummler

View GitHub Profile
@jaredrummler
jaredrummler / MOCK_INJECT.md
Created April 13, 2018 06:31
Mock lazy injection using reflection

Method to set all @Inject fields in a class to mocks:

fun mockInjectables(obj: Any) {
    obj::class.java.declaredFields.forEach { field ->
        field.getAnnotation(Inject::class.java)?.apply {
            if (field.type.isAssignableFrom(dagger.Lazy::class.java)) {
                if (!field.isAccessible) field.isAccessible = true

                val type = field.genericType as ParameterizedType
@jaredrummler
jaredrummler / ROOT_BROWSER_STORAGE_PERMISSIONS.md
Last active June 25, 2019 22:01
Root Browser Permissions

Root Browser File Manager allows users to copy, move, delete and modify files on internal, external, root and cloud storages. To accomplish this Root Browser requires various permssions as explained below:

Internal Storage Permission:

The Internal Storage on an Android device is often referred to as the SD card. This is not a removable storage.

Root Browser needs the user to grant the WRITE_EXTERNAL_STORAGE permission to work properly. The permission is requested when the app is first launched on Android 6.0+. For previous versions of Android, the permission is granted when the app is downloaded from the Google Play Store.

@jaredrummler
jaredrummler / boot2gif.sh
Last active February 1, 2023 23:08
Convert an Android boot animation to an animated GIF
#!/bin/bash
################################################################################
#
# boot2gif.sh
#
# DESCRIPTION: Convert an Android boot animation to a GIF
# You will need ImageMagick to run this script.
#
# USAGE:
#
@jaredrummler
jaredrummler / FizzBuzz.kt
Created February 24, 2017 12:43
Kotlin FizzBuzz
fun main(args: Array<String>) {
for (i in 1..100) {
println(if (i % 15 == 0) "FizzBuzz" else if (i % 3 == 0) "Fizz" else if (i % 5 == 0) "Buzz" else i)
}
}
@jaredrummler
jaredrummler / NAME_FROM_UID.md
Last active December 21, 2016 11:15
Get name of UID/GID on Android

Android has a way to get the name for a numeric UID using android.os.Process.getUidForName(String name). There is no method to get the numeric id from a UID name. This really ugly reflection will get the numeric UID/GID:

public static String getNameForUid(int id) {
  try {
    Class<?> clazz = Class.forName("libcore.io.Libcore");
    Field field = clazz.getDeclaredField("os");
    if (!field.isAccessible()) {
      field.setAccessible(true);
    }
@jaredrummler
jaredrummler / PsCommand.java
Created December 19, 2016 05:13
Get a list of running processes using toolbox ps on a rooted Android device
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.WorkerThread;
import com.jrummyapps.android.shell.CommandResult;
import com.jrummyapps.android.shell.Shell;
import java.util.ArrayList;
import java.util.Collections;
@jaredrummler
jaredrummler / LS_COMMAND_REGEX.md
Created December 14, 2016 10:41
ls command regex

group symlink:

^\s*(\d+)?\s?([rwxSTstdcb\-lp?]{10})\s+(\d+)?\s?(\S+)\s+(\S+)\s+([0-9,]+)?\s+(\d+)?\s?([0-9\-]{10}\s+[0-9:]{5}|[A-Z][a-z]{2}\s+[0-9]{1,2}\s+[0-9:]{4,5})\s((?:(?!\s\->\s).)*)(\s\->\s)?(.*)

no symlink:

^\s*(\d+)?\s?([rwxSTstdcb\-lp?]{10})\s+(\d+)?\s?(\S+)\s+(\S+)\s+([0-9,]+)?\s+(\d+)?\s?([0-9\-]{10}\s+[0-9:]{5}|[A-Z][a-z]{2}\s+[0-9]{1,2}\s+[0-9:]{4,5})\s(.*)
@jaredrummler
jaredrummler / android-arsenal-adblock-placeholder-remover.user.js
Last active February 10, 2018 02:42
Redirect to project pages on android-arsenal.com. Saves a click.
// ==UserScript==
// @name android-arsenal-adblock-placeholder-remover.user.js
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Remove adBlock placeholders. Guilt++
// @author Jared Rummler
// @match https://android-arsenal.com/*
// @grant none
// ==/UserScript==
@jaredrummler
jaredrummler / README.md
Created November 30, 2016 01:47
Get number of results for a Google Search

Using Jsoup:

public static int getGoogleResultsCount(String query) throws IOException {
  String url = "https://www.google.com/search?q=" + query;
  Document document = Jsoup.connect(url)
      .userAgent("Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)")
      .get();
  Element divResultStats = document.select("div#resultStats").first();
 return Integer.parseInt(divResultStats.text().replaceAll("\\D", ""));
@jaredrummler
jaredrummler / REGEX.md
Created November 22, 2016 21:47
regex collection