Skip to content

Instantly share code, notes, and snippets.

@francescofrontera
francescofrontera / AvroGenSerDesOps.scala
Last active March 19, 2018 20:52
Type Class for Serialize/Deserialize Avro generated Class using SpecificDatumReader.
import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer
import io.confluent.connect.avro.{AvroAuthentication, AvroPrimaryBrandCreated}
import org.apache.avro.io.{BinaryEncoder, EncoderFactory}
import org.apache.avro.specific.{SpecificDatumReader, SpecificDatumWriter}
import scala.reflect.ClassTag
abstract class GenDeserializerOps[T <: SpecificRecordBase: ClassTag] extends Serializable {
@francescofrontera
francescofrontera / InternalTopicManager.scala
Last active January 22, 2019 14:00
Kafka utils DSL for create Topics
import java.util.Properties
import org.apache.kafka.clients.admin.{AdminClient, AdminClientConfig, NewTopic}
object InternalTopicManager {
import scala.collection.JavaConverters._
final def removeNoAlphanumericCharsFromTopic(topicName: String): String =
topicName.replaceAll("[^\\p{L}\\p{Nd}]+", "")
@francescofrontera
francescofrontera / SerializationTest.scala
Last active February 15, 2019 14:28
Serialize Enum using spark standar implicits
sealed case class EvaluableData(
value: BigDecimal,
threshold: Threshold,
serviceClass: String,
serviceInstance: String,
triggeredEvent: String
)
sealed case class Threshold(criteria: Criteria.CriteriaValue,
critical: BigDecimal,
@francescofrontera
francescofrontera / SlickCatsOps.scala
Last active April 23, 2020 16:47
Simple Cats Slick Ops using EitherT or other cats data types over DBIO..
import scala.concurrent.ExecutionContext
import scala.concurrent.ExecutionContext.Implicits._
import slick.dbio.DBIO
import cats.{Functor, Monad}
object SlickCatsOps {
implicit def functor(implicit ex: ExecutionContext): Functor[DBIO] = new Functor[DBIO] {
override def map[A, B](fa: DBIO[A])(f: A => B): DBIO[B] = fa map f
}
@francescofrontera
francescofrontera / PhantomBuilder.scala
Created September 12, 2019 11:02
Free, Simple PhantomBuilder in scala
object PhantomBuilder extends App {
object Builder {
sealed trait State
trait Checked extends State
trait Unchecked extends State
@francescofrontera
francescofrontera / Sink.scala
Created May 7, 2020 14:49
Simple InfluxDB Sink
package ai.igenius.sink
import java.util.concurrent.TimeUnit
import cats.Functor
import cats.effect._
import org.influxdb._
import org.influxdb.dto.Point
import pureconfig._
import pureconfig.generic.auto._
@francescofrontera
francescofrontera / Op.scala
Last active November 11, 2023 05:22
Apply Aux pattern through Shapeless
import shapeless._, shapeless.ops.hlist._, shapeless.labelled.FieldType
trait Op[A] extends DepFn1[A]
trait LowPriority {
implicit def identity[A]: Op.Aux[A, A] = Op.createInstance(i => i)
}
object Op extends LowPriority {
type Aux[A, OUT0] = Op[A] { type Out = OUT0 }