Skip to content

Instantly share code, notes, and snippets.


Pedro Gómez pedrovgs

View GitHub Profile
pedrovgs / ComposeViewModel.kt
Created Apr 28, 2021
Example of a base view model for Jetpack Compose
View ComposeViewModel.kt
import androidx.lifecycle.*
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
abstract class ComposeViewModel<C, E> : ViewModel(), LifecycleObserver {
pedrovgs / IsRunningTests.swift
Created Jan 17, 2020
How to check if I'm running tests in iOS
View IsRunningTests.swift
import Foundation
class IsRunningTests {
static func check() -> Bool {
guard let value = ProcessInfo.processInfo.environment["IS_RUNNING_TESTS"] else {
return false
return value == "true"
pedrovgs / TestConfig.kt
Created Jan 17, 2020
How to check if I'm running tests with robolectric or instrumentation tests
View TestConfig.kt
package com.github.pedrovgs
object TestConfig {
val runningTests by lazy {
isRunningUITests() || isRunningRobolectricTests()
private fun isRunningRobolectricTests(): Boolean = checkIfClassIsAvailable("org.robolectric.RobolectricTestRunner")
private fun isRunningUITests(): Boolean = checkIfClassIsAvailable("com.github.pedrovgs.MyAndroidTestRunner")
pedrovgs /
Last active Dec 4, 2020
Manga Time!! Add these files to your path and from any folder execute or <FOLDER> to transform a folder with a set of images into a zip folder
if [ -z "$1" ]; then
echo "Help : To compress file use argument with directory"
exit 0
if [ -e "$filename" ]; then
pedrovgs / MockWebServerTest.kt
Created Dec 12, 2019
Utility class to use mock web server in our tests
View MockWebServerTest.kt
import okhttp3.Headers
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import okhttp3.mockwebserver.RecordedRequest
import org.junit.After
pedrovgs / ScreenshotTest.kt
Last active Nov 22, 2019
Interface you can import from your tests to be able to use screenshot testing for Android with different resolutions easily
View ScreenshotTest.kt
import android.content.Context
import android.view.View
import com.facebook.testing.screenshot.Screenshot
import com.facebook.testing.screenshot.ViewHelpers
pedrovgs / AnyTestExample.kt
Last active Jun 16, 2021
Handling Kotlin Coroutines homogeneously
View AnyTestExample.kt
class AnyTestExample {
fun `test with coroutines`() = runBlockingTest {
sut = AnyClassUsingAsyncCode(Dispatchers.Unconfined, scope, view, api)
pedrovgs /
Created Apr 4, 2019
OkHttp version 1 client interceptor for Flipper
import com.squareup.okhttp.*;
import okio.Buffer;
import okio.BufferedSource;
import javax.annotation.Nullable;
import java.util.ArrayList;
pedrovgs /
Created Mar 30, 2019
Form validation kata statement

Most of our tasks as software engineers are related to forms. Sign up forms, sing in forms, onboarding forms, etc. So today we are going to practice how to validate any form data using accumulative errors so we can now in just one method invocation what are the errors our form contains.

Our task for today's practice is to write a program to be able to validate if the data contained in a form with the following information is valid or not.

  • First name: It can't be empty.
  • Lst name: It can't be empty.
  • Birthdate. It has to be, at least, 18 years old.
  • Document ID: A value containing eight digits and one letter.
  • Phone number: Any combination of 9 numbers.
  • Email: Any valid email.
pedrovgs /
Last active Aug 15, 2021
A ready to work emulator for
#!/usr/bin/env bash
set -e
echo "Curren build dir:"
echo $build_dir
cd $ANDROID_HOME/emulator
echo "Creating sdcard image"