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
import cats.implicits._
import cats.{ Applicative, Monad }
// Операции над контекстом
trait ContextWriter[F[_]] {
def put(key: String, value: String): F[Unit]
}
@algebra
trait Ag[F[_]] {
def mate(name: String): F[Unit]
def feed(food: String): F[Unit]
def kill: F[Unit]
}
sealed trait AgEvent
case class AgBorn(name: String) extends AgEvent
case class AgAte(food: String) extends AgEvent
@notxcain
notxcain / Cache.scala
Created May 3, 2017 15:26
Monix function cache with TTL
object Cache {
def apply[A, B](ttl: FiniteDuration)(f: A => Task[B]): A => Task[B] = {
val mvar = MVar(Map.empty[A, B])
a =>
for {
cached <- mvar.read.map(_.get(a))
out <- cached match {
case Some(b) => Task.pure(b)
case None =>
for {
@notxcain
notxcain / OffsetRepartitioner.scala
Last active April 13, 2017 08:34
Repartition Offset Calculator
package io.aecor.distributedprocessing
object OffsetRepartitioner {
type Partition = Int
def apply[A, Offset: Ordering](
oldPartitioner: A => Partition,
newNumberOfPartitions: Int,
getNearestLeftInNewPartition: (Partition, Offset) => Option[A],
offsetOf: A => Offset
import cats.{ Functor, ~> }
import cats.implicits._
import shapeless.{ :+:, ::, CNil, Coproduct, Generic, HList, HNil, Inl, Inr }
sealed abstract class HasHandlers[C[_], F[_], H, A] {
type Out
def apply(h: H, a: A): F[Out]
}
object HasHandlers {
@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]]
@notxcain
notxcain / cofree.scala
Created December 13, 2016 08:32
Streams for (Co)free
import cats.data.Kleisli
import cats.implicits._
import cats.{Applicative, FlatMap, Functor, Monad, Monoid, ~>}
final case class Cofree[F[_], A](head: A, tail: F[Cofree[F, A]]) {
def map[B](f: A => B)(implicit F: Functor[F]): Cofree[F, B] =
Cofree(f(head), F.map(tail)(_.map(f)))
def zip[B](other: Cofree[F, B])(implicit F: Applicative[F]): Cofree[F, (A, B)] =
Cofree((head, other.head), (tail |@| other.tail).map(_ zip _))
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="UniversalPaymentGate" targetNamespace="http://upg.sbns.bssys.com/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://upg.sbns.bssys.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://bssys.com/upg/request"
targetNamespace="http://bssys.com/upg/request" elementFormDefault="qualified"
attributeFormDefault="unqualified" version="1.0">
<wsdl:types>
<xs:schema elementFormDefault="qualified" targetNamespace="http://upg.sbns.bssys.com/" version="1.0" xmlns:tns="http://upg.sbns.bssys.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="changePassword" type="tns:changePassword"/>
<xs:element name="changePasswordResponse" type="tns:changePasswordResponse"/>
<xs:element name="getRequestStatus" type="tns:getRequestStatus"/>
@notxcain
notxcain / upg5.wsdl
Last active November 15, 2016 15:00
<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions name="UniversalPaymentGate" targetNamespace="http://upg.sbns.bssys.com/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://upg.sbns.bssys.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema elementFormDefault="qualified" targetNamespace="http://upg.sbns.bssys.com/" version="1.0" xmlns:tns="http://upg.sbns.bssys.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="changePassword" type="tns:changePassword"/>
<xs:element name="changePasswordResponse" type="tns:changePasswordResponse"/>
<xs:element name="getRequestStatus" type="tns:getRequestStatus"/>
<xs:element name="getRequestStatusResponse" type="tns:getRequestStatusResponse"/>
<xs:element name="getRequestStatusSRP" type="tns:getRequestStatusSRP"/>
<xs:element name="getRequestStatusSRPResponse" type="tns:getRequestStatusSRPResponse"/>
@notxcain
notxcain / request.xsd
Created November 15, 2016 12:16
СБЕРБАНК УПШ 2.0
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://bssys.com/upg/request"
targetNamespace="http://bssys.com/upg/request" elementFormDefault="qualified"
attributeFormDefault="unqualified" version="1.0">
<xs:element name="Request" type="Request">
<xs:annotation>
<xs:documentation>Запрос УС к СББОЛ</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="Fraud">