Skip to content

Instantly share code, notes, and snippets.

View Baccata's full-sized avatar

Olivier Mélois Baccata

View GitHub Profile
@Baccata
Baccata / echo.scala
Created October 3, 2024 13:22
Generically producing scalacheck `Gen` instances from ScalaPB generated code. Mostly useless
package foo
import scalapb.GeneratedMessageCompanion
import scalapb.descriptors._
import org.scalacheck.Gen
import com.google.protobuf.ByteString
import scalapb.GeneratedMessage
object ProtoScalacheck {
@Baccata
Baccata / hoconLeftovers.scala
Last active August 28, 2024 08:41
Poor man's solution for getting the "remainder" of a hocon config after its decoding, in order to increase confidence when moving/deleting config values
//> using dep "com.typesafe:config:1.4.3"
//> using dep "com.github.pureconfig::pureconfig:0.17.6"
//> using scala "2.13.14"
import com.typesafe.config._
import pureconfig.generic.semiauto._
import pureconfig.ConfigReader
import pureconfig.ConfigSource
import java.{util => ju}
@Baccata
Baccata / repro.scala
Last active June 9, 2023 13:28
Reproduction of a http/2 specific problem with http4s-ember-server
//> using lib "org.http4s::http4s-ember-server:0.23.19"
//> using lib "org.http4s::http4s-dsl:0.23.19"
package foo
import cats.effect._
import cats.syntax.all._
import org.http4s.implicits._
import org.http4s.ember.server._
import org.http4s._
import org.http4s._
import org.http4s.syntax.all._
import smithy4s.kinds._
import smithy4s.Service
import smithy4s.http4s.SimpleRestJsonBuilder
import cats.data.OptionT
import cats.effect._
import cats.effect.syntax.all._
def precompileRoutes[Alg[_[_, _, _, _, _]]](service: Service[Alg])(
@Baccata
Baccata / tenet.scala
Created January 26, 2023 11:07
Wait for queue drain example
//> using lib "co.fs2::fs2-core:3.5.0"
import cats.effect.IOApp
import cats.effect._
import cats.effect.std.Queue
import scala.concurrent.duration._
import cats.effect.syntax.all._
import cats.syntax.all._
import cats.instances.queue
object Main extends IOApp.Simple {
@Baccata
Baccata / PolykindedMapper.scala
Last active October 24, 2022 09:33
Playing with kind-polymorphism to create a poly-kinded mapper construct.
//> using lib "org.typelevel::cats-core:2.8.0"
package foo
import cats.Functor
import cats.arrow.FunctionK
import cats.Id
import cats.ApplicativeError
import cats.MonadError
import scala.util.Try
import cats.syntax.all._
@Baccata
Baccata / TupleK.scala
Last active March 28, 2022 13:14
Generalised KTuple POC
//> using lib "org.typelevel::cats-core:2.7.0"
import cats.Applicative
import cats.syntax.all._
import cats.ContravariantMonoidal
import cats.InvariantMonoidal
import cats.InvariantSemigroupal
import cats.Show
import cats.~>
import cats.arrow.FunctionK
import cats.kernel.Monoid
@Baccata
Baccata / recursion.scala
Last active February 1, 2022 10:22
Baccata's recursion schemes microlib (to copy/paste when needed). Only depends on cats-core.
import cats._
import cats.syntax.all._
// format: off
/**
* A couple recursion-schemes, named in a less arcanic fashion than usual.
* These functions allow to decouple the recursive aspect of model construction
* and validation, from the domain-specific concerns.
*/
object recursion {
@Baccata
Baccata / compatibility.md
Created November 22, 2021 08:26
Data/API compatibility rules

Reasoning formally about data compatibility

Data compatibility in distributed systems is a problem that is often adressed in ad-hoc manners and suffer from bikeshedding. Developing a formal framework for reasoning about it is crucial to ensure a seamless evolution of complex systems and easy inter-connectivity of components.

Disclaimer

This gist talks specifically about backward compatibility rules. Intuitively, forward compatibility rules are the opposite of backward ones.

Defining the problem

@Baccata
Baccata / CryptoJSFacade.scala
Last active September 14, 2021 08:23
JVM/JS/Native Platform-specific implementations of crypto functions required for implementing the AWS signature algorithm.
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
/**
* @see https://nodejs.org/dist/latest-v7.x/docs/api/crypto.html#crypto_crypto
*/
@js.native
trait Crypto extends js.Object {
def createHash(algorithm: String): Hash = js.native