Skip to content

Instantly share code, notes, and snippets.

View Fristi's full-sized avatar

Mark Fristi

View GitHub Profile
@Fristi
Fristi / profiling.txt
Created May 6, 2020 09:34
scalac-profiling
This file has been truncated, but you can view the full file.
Compiling postgres (14 Scala sources)
[E-1] xsbt-analyzer : 1 spans, ()6.485ms (0.0%)
[E-1] silencerCheckUnused : 1 spans, ()0.083ms (0.0%)
[E-1] scalacenter-profiling : 1 spans, ()3581.37ms (5.1%)
[E-1] semanticdb-jvm : 1 spans, ()0.271ms (0.0%)
[E-1] jvm : 1 spans, ()977.622ms (1.4%)
[E-1] delambdafy : 1 spans, ()100.727ms (0.1%)
[E-1] cleanup : 1 spans, ()96.443ms (0.1%)
[E-1] mixin : 1 spans, ()94.082ms (0.1%)
[E-1] flatten : 1 spans, ()60.325ms (0.1%)
@Fristi
Fristi / OT2.scala
Last active April 28, 2020 15:59
Improved zio-telemetry OpenTracing
package zio.telemetry.opentracing
import java.util.concurrent.TimeUnit
import io.opentracing.{Span, Tracer}
import zio.clock.Clock
import zio._
object OpenTracing2 {
type OT = Has[Service]
@Fristi
Fristi / DiffableDerivation.scala
Created November 28, 2018 07:37
specs2 `Diffable` magnolia derivation
import magnolia.{CaseClass, Magnolia, SealedTrait}
import org.specs2.matcher.describe._
import scala.language.experimental.macros
object DiffableDerivation {
/** binds the Magnolia macro to this derivation object */
implicit def genDiffable[T]: Diffable[T] = macro Magnolia.gen[T]
@Fristi
Fristi / Service.scala
Created November 7, 2018 07:13
Http4s refined endpoint with tests
import cats.Show
import cats.data.EitherT
import cats.effect.{IO, Sync}
import eu.timepit.refined.api.Refined
import eu.timepit.refined.collection.NonEmpty
import eu.timepit.refined.types.numeric.PosInt
import io.chrisdavenport.log4cats.Logger
import io.chrisdavenport.log4cats.slf4j.Slf4jLogger
import io.circe._
import io.circe.refined._
@Fristi
Fristi / Xenolittle.scala
Created September 5, 2018 22:29
Simple Schema implementation derived from Xenomorph to practice around with all the concepts
import jason.HFunctor.HAlgebra
import scalaz._
import scalaz.Scalaz._
import io.circe._
trait HFunctor[F[_[_], _]] {
def hfmap[M[_], N[_]](nt: M ~> N): F[M, ?] ~> F[N, ?]
}
object HFunctor {
import scalaz._
import scalaz.Scalaz._
trait HFunctor[F[_[_], _]] {
def hfmap[M[_], N[_]](nt: M ~> N): F[M, ?] ~> F[N, ?]
}
object HFunctor {
def apply[F[_[_], _]](implicit v: HFunctor[F]) = v
@Fristi
Fristi / MockitoScalaMagic.scala
Created July 4, 2017 08:57
Workaround for Mockito's issue with mocking AnyVal as described here: https://stackoverflow.com/questions/27289757/mockito-matchers-scala-value-class-and-nullpointerexception - requires shapeless
import org.mockito.ArgumentMatchers.{eq => is}
import shapeless.ops.hlist.IsHCons
import shapeless._
trait MockitoScalaMagic {
def isAnyVal[A <: AnyVal, V, VN <: HList](
v: A
)(implicit LB: Generic.Aux[A, VN], ev: IsHCons.Aux[VN, V, HNil], same: (V :: HNil) =:= VN): A =
LB.from(is(ev.head(LB.to(v))) :: HNil)
@Fristi
Fristi / EitherT.scala
Created May 19, 2017 12:51
Simple EitherT monad transformer example
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scalaz.Scalaz._
import scalaz._
case class Person(name: String, age: Int, teamId: Int)
case class Team(name: String)
@Fristi
Fristi / Mapping.scala
Last active April 10, 2017 10:18
Mapping type class
import shapeless._
import shapeless.labelled.{ FieldType, field }
import scala.reflect.ClassTag
import scala.util.control.NonFatal
import scalaz.Scalaz._
import scalaz.{ DLeft, DRight, Disjunction }
/**
@Fristi
Fristi / Optics.scala
Created January 1, 2017 13:30
Accessing elements via optics in a Map[String, Any]
package maps
import monocle._
import monocle.std.map._
import monocle.function.all._
import scala.reflect.ClassTag
object Test extends App {