Skip to content

Instantly share code, notes, and snippets.

View pedrovgs's full-sized avatar
😃

Pedro Gómez pedrovgs

😃
View GitHub Profile
@pedrovgs
pedrovgs / ComposeViewModel.kt
Created April 28, 2021 16:58
Example of a base view model for Jetpack Compose
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
pedrovgs / IsRunningTests.swift
Created January 17, 2020 16:31
How to check if I'm running tests in iOS
import Foundation
class IsRunningTests {
static func check() -> Bool {
guard let value = ProcessInfo.processInfo.environment["IS_RUNNING_TESTS"] else {
return false
}
return value == "true"
}
@pedrovgs
pedrovgs / TestConfig.kt
Created January 17, 2020 16:28
How to check if I'm running tests with robolectric or instrumentation tests
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
pedrovgs / compressFiles.sh
Last active December 4, 2020 08:40
Manga Time!! Add these files to your path and from any folder execute mangaTime.sh or compressFiles.sh <FOLDER> to transform a folder with a set of images into a zip folder
#!/bin/bash
if [ -z "$1" ]; then
echo "Help : To compress file use argument with directory"
exit 0
fi
filename="${1}.cbz"
if [ -e "$filename" ]; then
@pedrovgs
pedrovgs / MockWebServerTest.kt
Created December 12, 2019 09:22
Utility class to use mock web server in our tests
import com.google.gson.Gson
import com.google.gson.JsonElement
import com.google.gson.JsonParser
import okhttp3.Headers
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import okhttp3.mockwebserver.RecordedRequest
import org.apache.commons.io.FileUtils
import org.junit.After
@pedrovgs
pedrovgs / ScreenshotTest.kt
Last active November 22, 2019 12:50
Interface you can import from your tests to be able to use screenshot testing for Android with different resolutions easily
import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.view.View
import androidx.fragment.app.Fragment
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.facebook.testing.screenshot.Screenshot
import com.facebook.testing.screenshot.ViewHelpers
@pedrovgs
pedrovgs / AnyTestExample.kt
Last active June 16, 2021 09:01
Handling Kotlin Coroutines homogeneously
class AnyTestExample {
@Test
fun `test with coroutines`() = runBlockingTest {
sut = AnyClassUsingAsyncCode(Dispatchers.Unconfined, scope, view, api)
sut.foo()
advanceTimeBy(5000)
assertTrue(true)
@pedrovgs
pedrovgs / FlipperInterceptor.java
Created April 4, 2019 07:34
OkHttp version 1 client interceptor for Flipper
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
import com.facebook.flipper.plugins.network.NetworkReporter;
import com.squareup.okhttp.*;
import okio.Buffer;
import okio.BufferedSource;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.ArrayList;
@pedrovgs
pedrovgs / FormValidationKata.md
Created March 30, 2019 16:36
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
pedrovgs / android_start_bitrise_emulator.sh
Last active August 15, 2021 10:04
A ready to work emulator for Bitrise.io
#!/usr/bin/env bash
set -e
build_dir=$(pwd)
echo "Curren build dir:"
echo $build_dir
cd $ANDROID_HOME/emulator
echo "Creating sdcard image"