Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
😃

Pedro Gómez pedrovgs

💭
😃
View GitHub Profile
@pedrovgs
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
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
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
pedrovgs / compressFiles.sh
Last active Dec 4, 2020
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
View compressFiles.sh
#!/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 Dec 12, 2019
Utility class to use mock web server in our tests
View MockWebServerTest.kt
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 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.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 Jun 16, 2021
Handling Kotlin Coroutines homogeneously
View AnyTestExample.kt
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 Apr 4, 2019
OkHttp version 1 client interceptor for Flipper
View FlipperInterceptor.java
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 Mar 30, 2019
Form validation kata statement
View FormValidationKata.md

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 Aug 15, 2021
A ready to work emulator for Bitrise.io
View android_start_bitrise_emulator.sh
#!/usr/bin/env bash
set -e
build_dir=$(pwd)
echo "Curren build dir:"
echo $build_dir
cd $ANDROID_HOME/emulator
echo "Creating sdcard image"