Skip to content

Instantly share code, notes, and snippets.

View rodrigohenriques's full-sized avatar

Rodrigo Henriques rodrigohenriques

View GitHub Profile
@rodrigohenriques
rodrigohenriques / KittyCalculationsOnATree.kt
Created July 27, 2022 05:13
Buggy solution. Can you spot the problem?
import java.io.File
import java.util.*
import kotlin.math.pow
private data class GraphNode(val label: Int, val parent: Int?, val depth: Int)
private val nodes = mutableMapOf<Int, GraphNode>()
/**
441888214
@rodrigohenriques
rodrigohenriques / AndroidManifest.xml
Last active September 25, 2017 11:58
Segment DEBUG and RELEASE Android Build Data with Crashlytics
<manifest ... >
...
<application ... >
...
<meta-data
android:name="io.fabric.ApiKey"
@rodrigohenriques
rodrigohenriques / Functions.kt
Created July 29, 2016 20:19
Read file content using recursion with Kotlin
fun readFileContent(file: File) : String {
val reader = FileReader(file)
fun readBuffer(bufferedReader: BufferedReader) : String {
val result = StringBuilder()
fun finally() : String {
bufferedReader.close()
return result.toString()
}
@rodrigohenriques
rodrigohenriques / SampleTest.java
Created March 22, 2016 19:04
Testing asyncronous observables to parallelize work
public class SampleTest {
@Test
public void testObservableParallel() {
List<String> terminals = new ArrayList<>();
for (int i = 0; i < 100000; i++) {
terminals.add(i, String.format("Terminal %s", i + 1));
}
PublishSubject<String> publisher = PublishSubject.create();
@rodrigohenriques
rodrigohenriques / build.gradle
Last active September 2, 2020 09:22
Add version name to generated apk file
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace(".apk", "-${variant.versionName}.apk"))
}
}
@rodrigohenriques
rodrigohenriques / CoordinatedImageView.java
Last active September 4, 2020 08:53
Used to collapse image view anchored at appbar
package com.github.rodrigohenriques.samples.customview;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
@rodrigohenriques
rodrigohenriques / ClickToSelectEditText.java
Last active July 28, 2024 11:13
Used to make your EditText a better option than Spinners
public class ClickToSelectEditText<T extends Listable> extends AppCompactEditText {
List<T> mItems;
String[] mListableItems;
CharSequence mHint;
OnItemSelectedListener<T> onItemSelectedListener;
public ClickToSelectEditText(Context context) {
super(context);