Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Denis Mikhaylov notxcain

🏠
Working from home
View GitHub Profile
View ReaderK.scala
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
View Projection.scala
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
Alpakka Kafka Fs2 interop
View interop.scala
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
View fs2-with-alpakka-kafka.scala
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 Feb 6, 2019
Postgres Table Audit Example
View tableaudit.sql
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);
View App.scala
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[_]] {
View Comonadic.scala
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)
View ActionRT.scala
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 {
View Counter.scala
// Tagless Encoding
trait Counter[F[_]] {
def increment(value: Int): F[Unit]
def decrement(value: Int): F[Unit]
def value: F[Int]
}
// Free Encoding
View Logger.scala
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]
You can’t perform that action at this time.