Skip to content

Instantly share code, notes, and snippets.

View angelcervera's full-sized avatar
🏠
Working from home

Ángel Cervera Claudio angelcervera

🏠
Working from home
View GitHub Profile
@angelcervera
angelcervera / Gzip.scala
Created May 30, 2022 13:47 — forked from owainlewis/Gzip.scala
Gzip Scala
import java.io.{ByteArrayOutputStream, ByteArrayInputStream}
import java.util.zip.{GZIPOutputStream, GZIPInputStream}
import scala.util.Try
object Gzip {
def compress(input: Array[Byte]): Array[Byte] = {
val bos = new ByteArrayOutputStream(input.length)
val gzip = new GZIPOutputStream(bos)
@angelcervera
angelcervera / FakeHttpServer.scala
Last active November 16, 2020 17:17
FakeHttpServer Fixture for testing using unfiltered
import unfiltered.request._
import unfiltered.response._
import java.lang.Thread.sleep
trait FakeHttpServer {
private val CONTEXT_OAUTH2 = "/oauth2"
private val CONTEXT_SERVICE1 = "/service1"
private val DELAY = 500
@angelcervera
angelcervera / WithMetrics.scala
Last active August 12, 2022 08:29
withMetrics Fixture
def withMetrics[R](f: => R): (Long, R) = {
val t0 = System.currentTimeMillis()
val result = f
(System.currentTimeMillis() - t0, result)
}
@angelcervera
angelcervera / ScalatestBeforeAfterExecutionOrder.scala
Last active October 25, 2020 09:38
Execution order in ScalaTest
package com.acervera.osm4scala.spark
import org.scalatest.matchers.should.Matchers
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
import org.scalatest.wordspec.AnyWordSpec
class ScalaTestExecutionOrderSpec extends AnyWordSpec with Matchers with BeforeAndAfterAll with BeforeAndAfterEach {
override protected def beforeAll(): Unit = {
println("BEFORE ALL ...........")
super.beforeAll()
@angelcervera
angelcervera / ExceptionHandlingExamplesTest.scala
Created February 1, 2020 10:43
Exception handling to Either
import org.scalatest.{Matchers, WordSpecLike}
import scala.util.{Failure, Success, Try}
object ExceptionHandlingExamples {
case class CaseClass(a: Int, b: Int)
def parseUsingMatchOnTry(str: String): Either[String, CaseClass] =
str.split("_") match {
@angelcervera
angelcervera / 01_pkcs12-cacerts-workaround.sh
Created May 5, 2018 07:59 — forked from mikaelhg/01_pkcs12-cacerts-workaround.sh
Workaround for java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
# Ubuntu 18.04 and various Docker images such as openjdk:9-jdk throw exceptions when
# Java applications use SSL and HTTPS, because Java 9 changed a file format, if you
# create that file from scratch, like Debian / Ubuntu do.
#
# Before applying, run your application with the Java command line parameter
# java -Djavax.net.ssl.trustStorePassword=changeit ...
# to verify that this workaround is relevant to your particular issue.
#
# The parameter by itself can be used as a workaround, as well.
@angelcervera
angelcervera / SparkTestSetup.scala
Last active September 15, 2017 07:47
Example of common Spark Test setup
import org.apache.spark.{SparkConf, SparkContext}
import org.scalatest.{BeforeAndAfterAll, Suite}
trait SparkTestSetup extends BeforeAndAfterAll { this: Suite =>
// Overwrite if it is neccesary
def master = "local[4]"
def appName: String
def defaultSparkConf = new SparkConf().setAppName(appName).setMaster(master)