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
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
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);
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[_]] {
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 / ActionRT.scala
Created September 21, 2018 08:15
ActionRT
package aecor.data
import aecor.data.ActionT.{ActionFailure, ActionResult}
import cats.data._
import cats.implicits._
import cats.{Applicative, Functor, Monad, ~>}
final class ActionT[F[_], S, E, R, A] private (
val unsafeRun: (S, (S, E) => Folded[S], Chain[E]) => F[ActionResult[R, E, A]]
) extends AnyVal {
// Tagless Encoding
trait Counter[F[_]] {
def increment(value: Int): F[Unit]
def decrement(value: Int): F[Unit]
def value: F[Int]
}
// Free Encoding
@notxcain
notxcain / Logger.scala
Created June 7, 2018 14:12
Logger[F[_]]
import cats.Applicative
import cats.effect.Sync
import com.evotor.common.logging.Logger.Level
import org.slf4j.LoggerFactory
import scala.reflect.ClassTag
trait Logger[F[_]] {
def log(level: Level.Value, msg: => String, throwable: Throwable): F[Unit]