Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Fu alexfu

View GitHub Profile
@alexfu
alexfu / avd_im_feeling_lucky.sh
Created Aug 16, 2019
Starts up a random AVD
View avd_im_feeling_lucky.sh
#!/usr/bin/env bash
emulator=$ANDROID_HOME/tools/emulator
adb=$ANDROID_HOME/platform-tools/adb
EMULATOR_COUNT=$($emulator -list-avds | wc -l | cut -c 8)
RANDOM_INDEX=$(shuf -i 1-$EMULATOR_COUNT -n 1)
EMULATOR_NAME=$($emulator -list-avds | head -n $RANDOM_INDEX | tail -n 1)
printf "Starting $EMULATOR_NAME..."
View DurationToHumanReadableString.kt
val units = listOf(
ChronoUnit.MILLENNIA,
ChronoUnit.CENTURIES,
ChronoUnit.DECADES,
ChronoUnit.YEARS,
ChronoUnit.MONTHS,
ChronoUnit.WEEKS,
ChronoUnit.DAYS,
ChronoUnit.HOURS,
ChronoUnit.MINUTES,
@alexfu
alexfu / multi-adb
Created Jan 4, 2019
ADB that prompts for which device when multiple devices are available
View multi-adb
#!/usr/bin/env python
import sys
import subprocess
def get_devices():
pipe = subprocess.PIPE
process = subprocess.Popen(["adb", "devices"], stdin=pipe, stdout=pipe, stderr=pipe)
output, error = process.communicate()
output_lines = output.strip().split("\n")
@alexfu
alexfu / geocode
Created Nov 1, 2018
Bash script that geocodes a location.
View geocode
#!/bin/bash
BASE_URL="https://maps.googleapis.com/maps/api/geocode/json"
API_KEY="" # Obtain an API key from https://developers.google.com/maps/documentation/geocoding/get-api-key
ADDRESS=$1
curl -s -G $BASE_URL --data-urlencode "address=$1" --data-urlencode "key=$API_KEY" | jq '.results[] | { name: .formatted_address, latLng: "\(.geometry.location.lat),\(.geometry.location.lng)" }'
@alexfu
alexfu / Instructions.md
Last active Nov 26, 2018
Creating GitHub PRs directly from JIRA tickets
View Instructions.md

Creating GitHub PRs directly from JIRA tickets

With a single command, you will be able to create a GitHub pull request from a JIRA ticket.

git jira-pr -t BUY-123 -b development

The above command will fetch the JIRA ticket and create a pull request using the JIRA ticket ID and summary as the pull request title.

@alexfu
alexfu / activity_main.xml
Last active Jul 10, 2018
Stretched LayerDrawable with centered icon
View activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:layout_width="200dp"
android:layout_height="100dp"
@alexfu
alexfu / TouchSlopDelegate.kt
Last active Apr 24, 2018
Android TouchSlopDelegate
View TouchSlopDelegate.kt
import android.content.Context
import android.view.MotionEvent
import android.view.MotionEvent.*
import android.view.ViewConfiguration
class TouchSlopDelegate(context: Context) {
private val targetTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
private var touchSlop: Int = 0
private var lastTouchX: Float = 0f
private var lastTouchY: Float = 0f
@alexfu
alexfu / app_build.gradle
Created Nov 30, 2017
Grouping shared dependencies
View app_build.gradle
/**
* This file would be located under /path/to/project/app/build.gradle
*/
apply plugin: 'com.android.application'
android {
// Usual stuff
}
@alexfu
alexfu / Demo.kt
Last active Mar 21, 2019
Making (Android) Spannable great again with Kotlin
View Demo.kt
val world = "World"
val mySpannedText = SpannableString("Hello ${world}!")
mySpannedText.spanWith(world) {
what = BackgroundColorSpan(Color.RED)
flags = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
}
@alexfu
alexfu / StateFrameLayout.java
Last active Dec 25, 2017
A FrameLayout that can show different states one at a time.
View StateFrameLayout.java
/**
* A {@link FrameLayout} that can show different states one at a time.
*/
public class StateFrameLayout extends ViewAnimator {
public static final String STATE_LOADING = "loading";
public static final String STATE_EMPTY = "empty";
public static final String STATE_ERROR = "error";
private static final String STATE_DEFAULT = "default";
private SimpleArrayMap<String, View> stateViewMap;
You can’t perform that action at this time.