Skip to content

Instantly share code, notes, and snippets.

@jairobjunior
jairobjunior / Benchmark.kt
Created December 15, 2021 00:40
Simple Benchmark block time elapsed measure
object Benchmark {
inline fun <reified T : Any> process(tag: String, block: () -> T) : T {
val now = System.currentTimeMillis()
val result = block.invoke()
val delta = System.currentTimeMillis() - now
println("Benchmark :: $tag :: Took ms=$delta")
return result
}
}
@jairobjunior
jairobjunior / AdbCommands
Created June 4, 2021 19:23 — forked from israelcena/AdbCommands
Adb useful commands list
== Adb Server
adb kill-server
adb start-server
== Adb Reboot
adb reboot
adb reboot recovery
adb reboot-bootloader
== Shell
@jairobjunior
jairobjunior / robolectricDownloader.gradle
Last active January 12, 2023 10:53 — forked from simtel12/robolectricDownloader.gradle
Robolectric manual download
/**
* Downloads all android-all dependencies and copies them to the mavenLocal() repository
*
* Once applied to your gradle project, can be executed with ./gradlew robolectricSdkDownload
*/
import java.nio.file.Files
// The general idea of this was borrowed from https://gist.github.com/xian/05c4f27da6d4156b9827842217c2cd5c
// I then modified it heavily to allow easier addition of new SDK versions
@jairobjunior
jairobjunior / Kotlin CountDownLatch(1).md
Last active December 16, 2019 21:43
Android / Kotlin - A coroutine version of CountDownLatch 1 and BroadcastReceivers

There is a very common pattern using CountDownLatch when developing with Android, sometimes you want to make an async implementation to be sync when dealing with BroadcastReceivers and CountDownLatch is pretty handy. The AOSP is filled with CountDownLatch(1).

private suspend fun yourSuspendMethod() {
    val job = GlobalScope.async {    
        val latch = CountDownLatch(1)

        val watcher = object : BroadcastReceiver() {

 override fun onReceive(context: Context?, intent: Intent?) {
@jairobjunior
jairobjunior / terminal.sh
Last active August 21, 2019 19:25
How to get Android Version and API level
Android version:
`adb shell getprop ro.build.version.release`
>> 6.0.1
Android API Level:
`adb shell getprop ro.build.version.sdk`
>> 23
@jairobjunior
jairobjunior / Benchmarking.swift
Created July 6, 2016 17:27
Simple benchmarking func in Swift to display block execution time.
public func benchmarking(operationName: String, operation: ()->()) {
let startTime = CFAbsoluteTimeGetCurrent()
operation()
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
print("Time elapsed for \(operationName): \(timeElapsed) s")
}
@jairobjunior
jairobjunior / transparent-hex-android.java
Created May 24, 2016 17:30
Java code to get all of the transparent hex value from 100% to 0% alpha - Android
for (double i = 1; i >= 0; i -= 0.01) {
i = Math.round(i * 100) / 100.0d;
int alpha = (int) Math.round(i * 255);
String hex = Integer.toHexString(alpha).toUpperCase();
if (hex.length() == 1) hex = "0" + hex;
int percent = (int) (i * 100);
System.out.println(String.format("%d%% — %s", percent, hex));
}
/*
@jairobjunior
jairobjunior / adb uninstall
Created December 17, 2014 03:45
Uninstall Android Wear App From Real Device - Debugging via bluetooth
adb -s localhost:4444 uninstall example.com.yourappname
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="ivory">#FFFFF0</color>
<color name="lightyellow">#FFFFE0</color>
<color name="yellow">#FFFF00</color>
<color name="snow">#FFFAFA</color>
<color name="floralwhite">#FFFAF0</color>
<color name="lemonchiffon">#FFFACD</color>
<color name="cornsilk">#FFF8DC</color>
# Built application files
/*/build/
# Crashlytics configuations
com_crashlytics_export_strings.xml
# Local configuration file (sdk path, etc)
local.properties
# Gradle generated files