Skip to content

Instantly share code, notes, and snippets.

View stanislav-chetvertkov's full-sized avatar

Stanislav Chetvertkov stanislav-chetvertkov

View GitHub Profile
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"license": {
"name": "MIT"
}
},
"servers": [
import java.time.Instant
import akka.actor.ActorSystem
import akka.http.scaladsl.model._
import akka.stream.ActorMaterializer
import cats.data.EitherT
import cats.implicits._
import com.twilio.service.encoding.json.CirceJsonSupport
import com.twilio.service.http.ServiceHttpClient.{ HttpClient, HttpError, IgnoredEntity, ServiceClientError, ServiceClientFailure, ServiceClientResult }
import com.twilio.service.http.{ ServiceHttpClient, SingleRequestHttpClient }
@stanislav-chetvertkov
stanislav-chetvertkov / circe.js
Created July 18, 2018 18:01
json omit nulls
implicit class FooBar(val json: Json) extends AnyVal {
def omitNull: Json = json
.mapArray(_.map(_.omitNull))
.mapObject(_
.filter { case (_, v) => !v.isNull }
.mapValues(_.omitNull)
)
}
@stanislav-chetvertkov
stanislav-chetvertkov / delayedFlow.scala
Created April 27, 2018 11:26
delayedFlow akka streams
object TestRunner {
def delayedFlow[T](delay: FiniteDuration)(implicit scheduler: Scheduler, ec: ExecutionContext): Flow[T, T, _] = {
Flow[T].mapAsyncUnordered(Int.MaxValue) { out =>
val promise = Promise[T]
scheduler.scheduleOnce(delay)(promise.success(out))
promise.future
}
}
}
import akka.actor.ActorSystem
import akka.stream.scaladsl.{Flow, GraphDSL, Merge, Partition, RunnableGraph, Sink, Source}
import akka.stream.{ActorMaterializer, ClosedShape, OverflowStrategy}
object GraphApp extends App {
implicit val actorSystem: ActorSystem = ActorSystem(name = "prog-voice")
implicit val mt: ActorMaterializer = ActorMaterializer()
val graph = RunnableGraph.fromGraph(GraphDSL.create() { implicit builder ⇒
def splitErrorsFlow[L, R, M, M1, M2](
routesSource: Source[Either[L, R], M],
leftSink: Sink[L, M1],
rightSink: Sink[R, M2]
)(implicit ec: ExecutionContext): RunnableGraph[(M, M1, M2)] =
RunnableGraph.fromGraph(GraphDSL.create(routesSource, leftSink, rightSink)((_, _, _)) { implicit b => (s, l, r) =>
import GraphDSL.Implicits._
val broadcast = b.add(Broadcast[Either[L, R]](2))
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{HttpRequest, HttpResponse, Uri}
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Sink, Source}
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import akka.pattern.after
import akka.actor.Scheduler
/**
* Given an operation that produces a T, returns a Future containing the result of T, unless an exception is thrown,
* in which case the operation will be retried after _delay_ time, if there are more possible retries, which is configured through
* the _retries_ parameter. If the operation does not succeed and there is no retries left, the resulting Future will contain the last failure.
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{Uri, HttpRequest, HttpResponse}
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Sink, Source}
import scala.concurrent.Future
/**
* Mock Akka HTTP Server, will handle requests which is provided with handle request
//Requires scalaz core and shapeless
import akka.actor.Actor.Receive
import akka.actor._
import shapeless.{Coproduct, :+:, CNil}
import scalaz.{Tag, @@}
object Test extends App {