Skip to content

Instantly share code, notes, and snippets.

View toantran-ea's full-sized avatar

Toan Tran toantran-ea

View GitHub Profile
{
"location": "Ho Chi Minh City",
"forecast": [
{
"date": "2024-09-25",
"temperature": {
"high": 33,
"low": 26
},
"conditions": "Partly Cloudy",
@file:Suppress("BlockingMethodInNonBlockingContext")
package features.file.download
import android.content.Context
import androidx.hilt.Assisted
import androidx.hilt.work.WorkerInject
import androidx.lifecycle.Observer
import androidx.work.Constraints
import androidx.work.CoroutineWorker
Academic/Background
------------------------------------------------------------------------------------------------------------
Software Architecture, Perspectives on an emerging discipline - Mary Shaw, David Garlan
Introduction / Practice within Business
------------------------------------------------------------------------------------------------------------
Software Architecture in Practice - Len Bass, Paul Clements, Rick Kazman
In depth handbook for reaching requirements
------------------------------------------------------------------------------------------------------------
@toantran-ea
toantran-ea / AweSpanBuilder.kt
Created September 19, 2020 04:49
Effortless SpannableStringBuilder
package mobi.toan.etc
import android.text.SpannableStringBuilder
import android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE
import java.util.*
/**
Kotlin's version of Thuss from Jake Wharton
**/
@toantran-ea
toantran-ea / benchmark.kt
Last active July 14, 2020 06:03
sequence benchmarking
fun main(args: Array<String>) {
val result = mutableListOf<Pair<Long, Long>>()
repeat(100) {
result.add(task())
}
println("====================")
println("LIST TIME (ns) || SEQUENCE TIME (ns)")
result.forEach {
println(" ${it.first} || ${it.second} || delta ${it.first - it.second} ")
}
@toantran-ea
toantran-ea / measureNanoTime.kt
Created July 13, 2020 23:37
measureNanoTime.kt
/**
* Executes the given [block] and returns elapsed time in nanoseconds.
*/
public inline fun measureNanoTime(block: () -> Unit): Long {
val start = System.nanoTime()
block()
return System.nanoTime() - start
}
@toantran-ea
toantran-ea / Main.kt
Created July 9, 2020 22:34
sequence 2
fun main(args: Array<String>) {
val seq = listOf("a", "ba", "cda", "def")
val listFilter1 = seq.filter {
it.length > 1
}
println(listFilter1) // [ba, cda, def]
val listFilter2 = listFilter1.filter {
it.length > 2
@toantran-ea
toantran-ea / Main.kt
Created July 9, 2020 22:27
sequence 1
fun main(args: Array<String>) {
val seq = sequenceOf("a", "ba", "cda", "def")
val filter1 = seq.filter {
it.length > 1
}
println(filter1) // kotlin.sequences.FilteringSequence@28a418fc
val filter2 = filter1.filter {
it.length > 2
@toantran-ea
toantran-ea / emulator_setup.sh
Created February 21, 2020 04:27
Stablize CI emulator before running test
adb shell settings put global window_animation_scale 0.0
adb shell settings put global transition_animation_scale 0.0
adb shell settings put global animator_duration_scale 0.0
adb shell settings put secure show_ime_with_hard_keyboard 0
adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE EN
@toantran-ea
toantran-ea / imperative.kt
Created January 8, 2020 12:12
Imperative way of solving Reachable Number Problem
fun f(x: Int): Int {
var cur = x + 1
while (cur % 10 == 0) cur /= 10
return cur
}