Skip to content

Instantly share code, notes, and snippets.

View pedrovgs's full-sized avatar
😃

Pedro Gómez pedrovgs

😃
View GitHub Profile
@lencioni
lencioni / waitUntilSettled.ts
Last active October 20, 2023 14:43
cy.waitUntilSettled()
/**
* We often run into a problem with functions that select DOM nodes like
* `cy.get`, where in between the `cy.get` call and the next item in the chain,
* the DOM element that `cy.get` found ends up being removed from the DOM. This
* can affect code as simple as:
*
* cy.get('button').click();
*
* When it fails sporadically, it uses the following error message:
*
@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
suspend fun getCards() =
service.getCards()
.async(IO.async())
.fix()
.map { response ->
when (response.code()) {
200 -> response.body()?.cards?.right() ?: NoContent.left()
204 -> NoContent.left()
404 -> NoInternetConnection.left()
401 -> NotAllowedError.left()
@Serchinastico
Serchinastico / fizzbuzz.kt
Created September 11, 2018 09:13
Tail recursive FizzBuzz in kotlin
tailrec fun fizzbuzz(vararg args: Int) {
if (args.isEmpty()) return
val arg = args[0]
when {
arg % 15 == 0 -> print("FizzBuzz")
arg % 3 == 0 -> print("Fizz")
arg % 5 == 0 -> print("Buzz")
}
@pedrovgs
pedrovgs / wrapFunction.scala
Created June 11, 2017 17:11
Declaration of a wrap function using Scala.
type Text = Option[String]
case class ColumnWidth(width: Int)
sealed trait WrapError
case class InvalidText(text: Text) extends WrapError
case class InvalidColumnWidth(width: ColumnWidth) extends WrapError
def wrap(text: Text, width: ColumnWidth): Either[WrapError, Text] = ???
@adavis
adavis / CommonExtensions.kt
Last active April 2, 2024 20:51
Common Android Extensions in Kotlin
fun View.visible() {
visibility = View.VISIBLE
}
fun View.invisible() {
visibility = View.INVISIBLE
}
fun View.gone() {
visibility = View.GONE
@wassname
wassname / keras_weighted_categorical_crossentropy.py
Last active December 19, 2023 18:17
Keras weighted categorical_crossentropy (please read comments for updated version)
"""
A weighted version of categorical_crossentropy for keras (2.0.6). This lets you apply a weight to unbalanced classes.
@url: https://gist.github.com/wassname/ce364fddfc8a025bfab4348cf5de852d
@author: wassname
"""
from keras import backend as K
def weighted_categorical_crossentropy(weights):
"""
A weighted version of keras.objectives.categorical_crossentropy
@pedrovgs
pedrovgs / MVP_discussion.md
Last active August 2, 2023 16:53
Interfaces for presenters in MVP are a waste of time!

##Interfaces for presenters in MVP are a waste of time!

It's been a long time since we started talking about MVP. Today, the discussion is about if creating an interface for the Presenter in MVP is needed.

This is the Model View Presenter pattern's schema:

MVP Schema

In this schema the Model box is related to all the code needed to implement your business logic, the presenter is the class implementing the presentation logic and the view is an interface created to abstract the view implementation.

@txusballesteros
txusballesteros / PulseDrawable.java
Last active December 17, 2022 08:52
Pulse Drawable for Android
/*
* Copyright Txus Ballesteros 2015 (@txusballesteros)
*
* This file is part of some open source application.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
@romainpiel
romainpiel / MyTest.java
Last active August 13, 2019 08:31
Source for https://medium.com/p/3f6f4179652e - "RecyclerView and espresso, a complicated story"
RecyclerViewInteraction.<Item>onRecyclerView(withId(R.id.recyclerview))
.withItems(items)
.check(new ItemViewAssertion<Item>() {
@Override
public void check(Item item, View view, NoMatchingViewException e) {
matches(hasDescendant(withText(item.getDisplayName())))
.check(view, e);
}
});