Skip to content

Instantly share code, notes, and snippets.

View StuStirling's full-sized avatar

Stu Stirling StuStirling

View GitHub Profile

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@StuStirling
StuStirling / toFlagEmoji.kt
Created April 4, 2022 21:30
toFlagEmoji.kt
/**
* This method is to change the country code like "us" into 🇺🇸
* Stolen from https://stackoverflow.com/a/35849652/75579
* 1. It first checks if the string consists of only 2 characters: ISO 3166-1 alpha-2 two-letter country codes (https://en.wikipedia.org/wiki/Regional_Indicator_Symbol).
* 2. It then checks if both characters are alphabet
* do nothing if it doesn't fulfil the 2 checks
* caveat: if you enter an invalid 2 letter country code, say "XX", it will pass the 2 checks, and it will return unknown result
*/
fun String.toFlagEmoji(): String {
// 1. It first checks if the string consists of only 2 characters: ISO 3166-1 alpha-2 two-letter country codes (https://en.wikipedia.org/wiki/Regional_Indicator_Symbol).
@StuStirling
StuStirling / FlowablePreviousAndLatest.kt
Created February 16, 2021 08:46
Flowable that emits previous item as well as latest.
data class PreviousAndLatest<T>(
var previous: T?,
var latest: T?
) {
fun addLatest(newLatest: T): PreviousAndLatest<T> {
if (latest != null) previous = latest
latest = newLatest
return this
}
}
@StuStirling
StuStirling / Useful Git Commands.sh
Last active February 16, 2021 09:03
Things I have found useful in the past relating to GIT
# Push tags matching specific pattern (this example will match all tags starting with "release/")
git tag -l "release/*" | xargs -n 1 -I% git push origin %
# Output list of ticket ids that have been merged since the last commit. Replace `HEAD^1` with a specific commit id if you like.
git rev-list HEAD^1..HEAD --oneline --date-order | grep "\[EXEP-.*\]\|\[SS-.*\]" -o | sort -u | tr -d '[',']'
# Get the short version of the current commit hash
git rev-parse --short HEAD
@StuStirling
StuStirling / prebuild.gradle
Created April 24, 2018 15:56
Android Prebuild Task
task copyFiles(type: Copy) {
from "$projectDir/src/flavorDevelop/cpp/"
into "$projectDir/src/develop/cpp/"
}
tasks.whenTaskAdded { task ->
if (task.name == 'preFlavorDevelopDebugBuild') {
task.dependsOn copyFiles
}
}
@StuStirling
StuStirling / versioning.gradle
Last active March 3, 2018 10:22
Using GIT to Version the Android App
def getVersionName = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--match', "dev/[0-9]*.[0-9]*.[0-9]*", "--abbrev=0", 'HEAD'
standardOutput = stdout
}
return stdout.toString().replace("version/","").trim()
}
catch (ignored) {
@StuStirling
StuStirling / File.kt
Created July 20, 2017 14:18
Some useful File extensions
/**
* Generates a checksum for a file.
*/
fun File.checksum() : Long? {
val crc = CRC32()
crc.update(readBytes())
return crc.value
}