Skip to content

Instantly share code, notes, and snippets.

Alex Fu alexfu

Block or report user

Report or block alexfu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
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 / bookmarklet.js
Last active Mar 20, 2019
Bookmarklet for displaying GitHub PRs you created yesterday/today
View bookmarklet.js
javascript:(function() {
let author = ""; // Replace with your username
let today = new Date();
let yesterday = new Date();
yesterday.setDate(today.getDate() - 1);
let todayStr = today.toISOString().slice(0, 10);
let yesterdayStr = yesterday.toISOString().slice(0, 10);
location.href = `https://github.com/search?q=author%3A${author}+created%3A${yesterdayStr}..${todayStr}+type%3Apr`
})();
@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
}
You can’t perform that action at this time.