Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Fu alexfu

View GitHub Profile
@alexfu
alexfu / ghof
Last active Aug 22, 2022
GitHub Open File (GHOF)
View ghof
#!/usr/bin/env bash
# Prints the GitHub URL of the chosen file. Requires fzf.
FILE=$1
if [ -z "${FILE}" ]
then
FILE=$(fzf)
fi
CURRENT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
@alexfu
alexfu / DateTimeExtensions.kt
Created Jul 22, 2022
Do you wish there was an easier way to write dates in Kotlin?
View DateTimeExtensions.kt
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.Month
import java.time.ZonedDateTime
import java.util.TimeZone
fun January(day: Int, year: Int) = LocalDate.of(year, Month.JANUARY, day)
fun February(day: Int, year: Int) = LocalDate.of(year, Month.FEBRUARY, day)
fun March(day: Int, year: Int) = LocalDate.of(year, Month.MARCH, day)
fun April(day: Int, year: Int) = LocalDate.of(year, Month.APRIL, day)
View git-add-interactive.md

git addi

Add git files interactively from the command line.

asciicast

Requirements

@alexfu
alexfu / docker-compose.yml
Last active Aug 26, 2021
Sourcegraph Docker Compose
View docker-compose.yml
version: "3.8"
services:
sourcegraph:
image: sourcegraph/server:3.29.1
container_name: leafly-sourcegraph
ports:
- 7080:7080
- 3370:3370
volumes:
- "~/.sourcegraph/config:/etc/sourcegraph"
@alexfu
alexfu / git-eject
Last active May 13, 2021
git eject
View git-eject
#!/bin/bash
# Bails on current working branch and switches to main
# Install: Place this script anywhere that is in your $PATH and make it executable (chmod +x)
BRANCH_TO_EJECT=$(git rev-parse --abbrev-ref HEAD)
git reset HEAD --hard
git checkout main
git br -D $BRANCH_TO_EJECT
View git-bugfix
#!/bin/bash
# Creates a new named bugfix branch in the following format: bugfix/xyz
# $1 - Name of the branch
# $2 - Base branch
BRANCH_NAME=bugfix/$1
START_POINT=$2
git checkout -b $BRANCH_NAME $START_POINT
@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)" }'