Skip to content

Instantly share code, notes, and snippets.

View BaseKeyValueStoreBenchmark.scala
import io.univalence.data.{Stock, StockKey, StockKeyBinarySerde, StockBinarySerde}
import java.time.Instant
import java.time.temporal.ChronoUnit
import org.openjdk.jmh.annotations._
import scala.util.Random
abstract class BaseKeyValueStoreBenchmark {
val products = List("café", "chocolat", "miel")
@fsarradin
fsarradin / TextMain.scala
Created Apr 2, 2021
Text exploration with Spark Core
View TextMain.scala
package io.univalence.aboutfp
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SparkSession
object TextMain {
def main(args: Array[String]): Unit = {
val spark = SparkSession.builder()
.master("local[*]")
.appName(getClass.getSimpleName)
@fsarradin
fsarradin / Currency.java
Last active Dec 20, 2020
Deep nested Avro schema
View Currency.java
/**
* Autogenerated by Avro
*
* DO NOT EDIT DIRECTLY
*/
package test.entity;
@org.apache.avro.specific.AvroGenerated
public enum Currency implements org.apache.avro.generic.GenericEnumSymbol<Currency> {
EUR, USD ;
public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"Currency\",\"namespace\":\"test.entity\",\"symbols\":[\"EUR\",\"USD\"]}");
@fsarradin
fsarradin / ServiceConfigurationLoader.scala
Created Dec 4, 2020
A configuration loader to that is able to get data from different sources with different key case schemas (zio-config 1.0.0-RC28)
View ServiceConfigurationLoader.scala
import java.lang.{Boolean => JBoolean}
import scala.util.{Failure, Success, Try}
import com.typesafe.config._
import zio.config.PropertyTree.{Leaf, Record, Sequence}
import zio.config.{ConfigSource, PropertyTree, ReadError}
import zio.{IO, config}
/**
* Load a configuration from different sources based on the given
* configuration schema.
@fsarradin
fsarradin / Expression.scala
Created Nov 13, 2020
Arithmetic expression
View Expression.scala
/**
* Arithmetic expression representation.
*
* In this expressions you can only have a unique variable.
* eg. Mult(Var, Add(Const(2), Var)) represents X * (2 + X)
*/
sealed trait Expression
object Expression {
// represent a variable
case object Var extends Expression
@fsarradin
fsarradin / build.sbt
Created Feb 26, 2020
Read a fixed length format file by using ZIO, ZStream, and Magnolia
View build.sbt
name := "zkafka"
version := "0.1"
scalaVersion := "2.13.1"
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % "1.0.0-RC17",
"dev.zio" %% "zio-streams" % "1.0.0-RC17",
"com.propensive" %% "magnolia" % "0.12.6"
@fsarradin
fsarradin / DottyDerivation.scala
Created Mar 29, 2019
Typeclass derivation in Dotty
View DottyDerivation.scala
import scala.reflect._
import scala.compiletime._
import scala.compiletime.Shape._
enum Maybe[+A] derives ToJson {
case Just(value: A)
case Nope
}
View DottyTypeclassMain.scala
trait Functor[F[_]] {
def (fa: F[A]) map[A, B](f: A => B): F[B]
}
case class IO[+A](run: () => A)
object IO {
def pure[A](a: => A): IO[A] = IO(() => a)
implied IOFunctor for Functor[IO] {
@fsarradin
fsarradin / TestMain.scala
Created Mar 4, 2019
Spark and Case class deser
View TestMain.scala
import com.twitter.chill.Externalizer
import org.apache.spark.sql._
import org.apache.spark.sql.expressions.UserDefinedFunction
import org.apache.spark.sql.functions._
import scala.reflect.runtime.universe._
object TestMain {
def main(args: Array[String]): Unit = {
val spark: SparkSession =
SparkSession
@fsarradin
fsarradin / Main.scala
Created Sep 7, 2018
Getting some system information
View Main.scala
import java.lang.management.ManagementFactory
import java.net.{InetAddress, NetworkInterface}
object Main {
import scala.collection.JavaConverters._
def main(args: Array[String]): Unit = {
val localHost = InetAddress.getLocalHost
println(localHost)