Skip to content

Instantly share code, notes, and snippets.

Avatar

Reid Baker reidbaker

View GitHub Profile
View DiffUtilExample.java
private void updateList(@NonNull List<Device> newDevices) {
// Sort new list
Collections.sort(newDevices, mComplicatedComparitor);
//Calculate difference between old and new list
DiffUtil.DiffResult result = DiffUtil.calculateDiff(new CustomDiffCallback(mDevices, newDevices));
//Wipe old list and replace with sorted new list
mDevices.clear();
mDevices.addAll(newDevices);
//Let diff handle ui update calls to adapter
result.dispatchUpdatesTo(this);
@reidbaker
reidbaker / check_for_git_hooks.gradle
Last active Feb 25, 2016 — forked from tmelz/check_for_git_hooks.gradle
fail the gradle build if git-hooks don't exist
View check_for_git_hooks.gradle
// Apply by adding the following line to your build.gradle:
// apply from: 'scripts/check_for_git_hooks.gradle'
// Comment out any hook files that aren't relevant for you.
final GIT_HOOK_DIR = ".git/hooks/"
final IGNORE_HOOKS_FLAG = "ignoreMissingHooks"
final GIT_HOOK_FILES = [
"applypatch-msg",
"commit-msg",
"post-applypatch",
"post-checkout",
View Mp4 to animated gif
function mp4togif() {
FILTERS="fps=30,scale=w='if(gt(iw,ih),-1,480)':h='if(gt(iw,ih),480,-1)':flags=lanczos"
TEMP="$(mktemp -t mp4togif).png"
echo "Creating palette..."
ffmpeg -v warning -i $1 -vf "$FILTERS,palettegen" -y "$TEMP"
echo "Encoding GIF..."
ffmpeg -v warning -i $1 -i "$TEMP" -lavfi "$FILTERS[x];[x][1:v]paletteuse=dither=floyd_steinberg" -y -f gif "$1.gif"
echo "Done!"
}
#Credit @jakewharton ASG
View one line screencap with adb
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > <LOCATION HERE>
View Search for hard coded colors in android xml
# find all xml files `find res -name "*.xml"`
# then serch them for a # followed by 0-f 6 times (will find either rgb or argb)
find res -name "*.xml" -exec grep -Hn "#[0-9a-fA-F]\{6\}" {} \;
View Get icon for another app
ResolveInfo activityInfo = (ResolveInfo) mDataModel.getActivity(position)
Drawable icon = activityInfo.loadIcon(packageManager);
View Gerrit helpers
## Gerrit is dumb ##
####################
alias gerrit='ssh -p 29418 <wherever you run gerrit> gerrit'
# Usage #
# gerritIds <project>
# will list all change ids by you that are open for <project>
# useful to find what ids will will be abandoned by abandonALl
gerritIds() {
gerrit query --format=JSON --patch-sets -- status:open project:$1 | grep -v runTimeMilliseconds | grep -E "`git config user.email`" | grep -E -o '"number":"\d\d+"' | tr '"' ' ' | cut -d' ' -f4-
View Launch default activity in apk
##Launch default activity in apk##
# Commands are surrounded in triple quotes '''
#'''adb shell am start -n <package name>/<activity name>''' will start activity
#'''`<command here>`''' will evaluate command in back ticks
#'''aapt dump badging <your apk file>.apk''' will print a bunch of things including the package and default activity
#'''grep -o "package.*[\.][a-zA-Z]*[\']\|launchable-activity.*[\.][a-zA-Z]*[\']"''' will match either the package or activity
#'''| grep -o "['][a-zA-Z\.].*[']"''' then strip out everything but what we want surrounded by quotes
#'''sed "s/'//g"''' strip quotes
#'''sed -n -e ":a" -e "$ s/\n/\//gp;N;b a"''' replace newline with forward slash
adb shell am start -n `aapt dump badging <your apk file>.apk | grep -o "package.*[\.][a-zA-Z]*[\']\|launchable-activity.*[\.][a-zA-Z]*[\']" | grep -o "['][a-zA-Z\.].*[']" | sed "s/'//g" | sed -n -e ":a" -e "$ s/\n/\//gp;N;b a"`
You can’t perform that action at this time.