Skip to content

Instantly share code, notes, and snippets.

Adam Warski adamw

Block or report user

Report or block adamw

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Logging.scala
override def openWebsocket[T, WS_RESULT](
request: Request[T, S],
handler: WS_HANDLER[WS_RESULT]): F[WebSocketResponse[WS_RESULT]] = {, handler)) {
case e: Exception =>
logger.error(s"Exception when opening websocket: $request", e)
}) { response =>
logger.debug(s"Websocket open: $request, with response headers: ${response.headers}")
View polynote_sttp.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View polynote.scala
case class LetterAndCount(letter: String, count: Int)
// result: Response[GitHubResult] is what we've read from the API
val firstLetterToName = result.items.groupBy(
val pairs = { case (letter, projects) =>
LetterAndCount(letter.toString, projects.size)
View sttp4.scala
package sttp.client.asynchttpclient.monix
import monix.eval.Task
import sttp.client._
import{WebSocket, WebSocketResponse}
import scala.concurrent.duration._
View sttp3.scala
import cats.effect.{ContextShift, IO, Timer}
import{WebSocket, WebSocketListener}
import sttp.client._
import sttp.client.asynchttpclient.WebSocketHandler
import scala.concurrent.duration._
object CatsWebsocketExample extends App {
View sttp2.scala
package sttp.client.akkahttp
import akka.Done
import{ActorSystem, Cancellable}
import{Message, TextMessage}
import{Flow, Keep, Sink, Source}
import akka.util.ByteString
import sttp.client._
View sttp1.scala
trait SttpBackend[F[_], -S, -WS_HANDLER[_]] {
def send[T](request: Request[T, S]): F[Response[T]]
def openWebsocket[T, WS_RESULT](
request: Request[T, S],
handler: WS_HANDLER[WS_RESULT]): F[WebSocketResponse[WS_RESULT]]
def close(): F[Unit]
def responseMonad: MonadError[F]
View t11.scala
val countPersons: ConnectionIO[Int] =
sql"SELECT COUNT(*) FROM persons".query[Int].unique
val callFromCount: ConnectionIO[IO[Unit]] = { count =>
if (count == 0) IO(println("No users!")) else IO(println(s"Found $count users"))
val showResults: IO[Unit] = callFromCount.transact(transactor).flatten
View t10.scala
val insertEventQuery: ConnectionIO[Int] =
sql"INSERT INTO events(msg) VALUES('made a http call')"
val result: IO[Int] = queryFromHttpCall
.map(countQuery => insertEventQuery >> countQuery)
View t9.scala
val httpCall: IO[String] = IO("Zoe")
val queryFromHttpCall: IO[ConnectionIO[Int]] = { name =>
sql"SELECT COUNT(*) FROM persons WHERE name = $name".query[Int].unique
You can’t perform that action at this time.