Skip to content

Instantly share code, notes, and snippets.

View notxcain's full-sized avatar
🏠
Working from home

Denis Mikhaylov notxcain

🏠
Working from home
View GitHub Profile
@notxcain
notxcain / App.scala
Last active March 17, 2021 19:39
Akka Http Prometheus Endpoint
import io.prometheus.client.CollectorRegistry
import io.prometheus.client.dropwizard.DropwizardExports
import io.prometheus.client.hotspot.DefaultExports
import nl.grons.metrics.scala.DefaultInstrumented
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.http.scaladsl.Http
object App extends App with DefaultInstrumented {
package aecor.testkit
import aecor.data.PairE
import aecor.encoding.WireProtocol
import aecor.encoding.WireProtocol.{ Encoded, Invocation }
import cats.data.ReaderT
import cats.tagless.FunctorK
import cats.tagless.implicits._
import cats.~>
import scodec.bits.BitVector
import cats.data.Kleisli
import cats.effect.{ Concurrent, Sync }
import cats.effect.concurrent.MVar
import cats.implicits._
import cats.{ Applicative, Functor, Monad }
// Let's start with our dsl
// First we need to interact with a console
trait Console[F[_]] {
package aecor.runtime.akkapersistence.readside
import aecor.data.{ EntityEvent, Fold, Folded }
import aecor.runtime.Eventsourced.Versioned
import cats.MonadError
import cats.implicits._
object Projection {
final case class ProjectionError(message: String) extends RuntimeException(message)
@notxcain
notxcain / interop.scala
Created May 28, 2019 13:22
Alpakka Kafka Fs2 interop
package aecor.kafkadistributedprocessing
import java.time.Duration
import java.util
import java.util.concurrent.Executors
import aecor.util.effect._
import akka.NotUsed
import akka.kafka.ConsumerMessage.PartitionOffset
import akka.kafka.scaladsl.Consumer
@notxcain
notxcain / fs2-with-alpakka-kafka.scala
Created March 20, 2019 10:38
fs2 with Alpakka Kafka
import akka.actor.ActorSystem
import akka.kafka.scaladsl.Consumer
import akka.kafka.{ConsumerSettings, Subscriptions}
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Keep, Sink => AkkaSink}
import cats.effect.{ConcurrentEffect, ExitCode, IO, Resource}
import cats.implicits._
import fs2.interop.reactivestreams._
import org.apache.kafka.common.serialization.StringDeserializer
@notxcain
notxcain / tableaudit.sql
Created February 6, 2019 11:43
Postgres Table Audit Example
CREATE OR REPLACE FUNCTION auditlogfunc RETURNS TRIGGER AS $example_table$
DECLARE
row_key JSONB;
affected_row JSON;
operation char;
BEGIN
IF TG_OP IN('INSERT', 'UPDATE') THEN
affected_row := row_to_json(NEW);
ELSE
affected_row := row_to_json(OLD);
@notxcain
notxcain / FormatCompanion.scala
Last active January 15, 2019 13:34
play.api.libs.json.Format[A] automatic derivation using LabelledTypeClass from shapeless
/*
* Copyright (c) 2014-15 Denis Mikhaylov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
import cats.{ Comonad, Monad }
import cats.effect.{ Concurrent, Resource, Timer }
import cats.implicits._
import scala.concurrent.duration.FiniteDuration
object Ex {
final case class Point(x: Long, y: Long)
final case class Direction(value: Double)
@notxcain
notxcain / App.scala
Last active September 21, 2018 13:54
Onion Architecture using Finally Tagless and Liberator
import cats.data.{ EitherT, State }
import cats.implicits._
import cats.{ Monad, ~> }
import io.aecor.liberator.macros.free
import io.aecor.liberator.syntax._
import io.aecor.liberator.{ ProductKK, Term }
@free
trait Api[F[_]] {
def doThing(aThing: String, params: Map[String, String]): F[Either[String, String]]