Skip to content

Instantly share code, notes, and snippets.

View filosganga's full-sized avatar

Filippo De Luca filosganga

View GitHub Profile
@filosganga
filosganga / JsonTagger.scala
Last active October 27, 2021 06:23
The JSON tagger allows to decode an ADT encoded in JSON avoiding the focus to switch to a different branch
import io.circe._
import io.circe.generic.semiauto._
import cats.syntax.all._
object JsonTagger {
private implicit class Tagger[A](d: Decoder[A]) {
def tag(accessor: String): Decoder[Decoder[A]] =
Decoder
@filosganga
filosganga / Memoize.scala
Last active March 5, 2020 20:16
Computational memoization
import cats._
import cats.implicits._
import cats.effect._
import cats.effect.concurrent._
import cats.effect.implicits._
trait Memoize[F[_], Key, A] {
def get(id: Key): F[A]
}
@filosganga
filosganga / Queue.scala
Created February 25, 2020 22:12
Several effectful Queue implementation using cats-effect
import cats.data._
import cats.implicits._
import cats.effect._
import cats.effect.concurrent._
trait Queue[F[_], A] {
def enqueue(a: A): F[Unit]
def dequeue: F[A]
@filosganga
filosganga / GuavaFutures.scala
Created September 16, 2017 06:25
How to convert a Guava ListeanbelFuture to Cats Async
import cats.effect.Async
import com.google.common.util.concurrent.{FutureCallback, Futures, ListenableFuture}
import scala.concurrent.ExecutionContext
object GuavaFutures {
implicit class RichListenableFuture[T](lf: ListenableFuture[T]) {
def toAsync[F[_]: Async](implicit ec: ExecutionContext): F[T] = {
{
"type" : "record",
"name" : "TimeExamples",
"namespace": "com.example",
"fields" : [
{
"name": "aDate",
"type": "int"
"logicalType": "date"
},
@filosganga
filosganga / ResourceMapStage.scala
Last active March 23, 2017 10:51
A map stage that control a resource lifecycle.
import akka.stream.ActorAttributes.SupervisionStrategy
import akka.stream._
import akka.stream.stage.{GraphStage, GraphStageLogic, InHandler, OutHandler}
import scala.util.control.NonFatal
class ResourceMapStage[In, Out, R](opener: () => R, closer: R => Unit, f: R => In ⇒ Out) extends GraphStage[FlowShape[In, Out]] {
val in = Inlet[In]("ResourceMap.in")
val out = Outlet[Out]("ResourceMap.out")

Keybase proof

I hereby claim:

  • I am filosganga on github.
  • I am filippodeluca (https://keybase.io/filippodeluca) on keybase.
  • I have a public key ASC15nUa_a2CLHbteLCqNLcJOdILRNSHq5YRpdaV2xplzAo

To claim this, I am signing this object:

Verifying that +filosganga is my blockchain ID. https://onename.com/filosganga
@filosganga
filosganga / .gitignore
Last active August 29, 2015 14:27 — forked from mpilquist/.gitignore
Simulacrum Example
target
@filosganga
filosganga / CssParser.scala
Created February 17, 2015 23:15
CSS Parser
import util.parsing.combinator.JavaTokenParsers
case class Rule(val selectors : List[String], val properties : List[Property])
case class Property(name: String, value: String)
object CssParser extends JavaTokenParsers {
def rules = rule+