Skip to content

Instantly share code, notes, and snippets.

View fernandospr's full-sized avatar

Fernando Sproviero fernandospr

  • Ciudad de Buenos Aires, Argentina
View GitHub Profile
@fernandospr
fernandospr / CountdownTimer.kt
Last active May 10, 2024 18:14
Testing RX operations with delay
fun countdownTimer(
duration: Long,
scheduler: Scheduler = Schedulers.io()
) = Observable.interval(1, TimeUnit.SECONDS, scheduler)
.takeWhile { it < duration }
.map { duration - it }
@fernandospr
fernandospr / missing-serializedname-finder.sh
Created January 27, 2023 15:03
Recursively looks for Request/Response Kotlin models that may have missing @SerializedName annotations
#!/bin/bash
if [ -z "$1" ]; then
echo "Recursively looks for Kotlin files having missing @SerializedName annotations."
echo
echo "Usage: $0 <directory to analyze>"
exit 1
fi
currentPath=$PWD
cd $1
@fernandospr
fernandospr / 1-CountryProvider.kt
Last active January 6, 2021 13:28
CountryCode to Resource Mapper
interface CountryProvider {
fun getCountryCode(): String
}
@fernandospr
fernandospr / JUnit4ParameterizedTest.kt
Created April 27, 2020 19:45
JUnit4 Parameterized Test
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
class Multiplier {
fun byTwo(value: Int): Int = value * 2
}
@RunWith(Parameterized::class)
@fernandospr
fernandospr / MockingTextUtilsMethods.kt
Last active May 31, 2022 06:42
Shows how to mock TextUtils methods so that it's possible to unit test classes that use them
import android.text.TextUtils
import io.mockk.every
import io.mockk.mockkStatic
import org.junit.Assert
import org.junit.Test
class TextValidator {
fun validate(string: String) = !TextUtils.isEmpty(string)
}
@fernandospr
fernandospr / android-materials-generator.sh
Created September 14, 2019 20:51
Android Materials Generator
#!/bin/sh
if [ $# -eq 0 ]; then
echo
echo "Example usage:"
echo "Having MyProject-Starter and MyProject-Final folders execute:"
echo
echo "$ bash $0 MyProject-Starter MyProject-Final"
echo
echo "This will generate a Materials.zip containing MyProject-Starter and MyProject-Final folders."
exit 1
@fernandospr
fernandospr / LiveData+ViewModel+RxJava+LCE+Action+UnitTests.kt
Last active July 25, 2019 20:34
LiveData+ViewModel+RxJava+LCE+Action+UnitTests
sealed class SampleAction {
object Action1 : SampleAction()
data class Action2WithParams(val param1: String, val param2: String) : SampleAction()
}
sealed class SampleResource {
object Loading : SampleResource()
object Error : SampleResource()
data class Success(val resource: MyResource) : SampleResource()
}
@fernandospr
fernandospr / gist:00c3025d2ae576356ee09b58edf7889b
Last active September 19, 2016 18:57
First pixel white check
import javax.imageio.ImageIO;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
...
public static boolean isFirstPixelWhite(String imageFilename) throws IOException {
BufferedImage image = ImageIO.read(new File(imageFilename));
@fernandospr
fernandospr / gist:6c0b8970cfc6f087a878
Last active August 29, 2015 14:21
Git pre push script (.git/hooks/pre-push)
#!/bin/bash
CMD="mvn test" # Run the tests before pushing
$CMD
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "Failed $CMD"
exit 1
fi
@fernandospr
fernandospr / gist:3731d4e24c7b9e596b5f
Created April 10, 2015 16:01
Spring MVC no cache Java
public class WebMvcConfig
extends WebMvcConfigurerAdapter {
...
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addIntercetpro(this.webContentInterceptor());
super.addInterceptors(registry);
}