Skip to content

Instantly share code, notes, and snippets.

Working from home

Debasish Ghosh debasishg

Working from home
View GitHub Profile
debasishg / ZKleisli.scala
Created September 28, 2022 15:44
ZIO Kleisli
View ZKleisli.scala
package zio
case class ZKleisli[-R, +E, -A, +B](
run: A => ZIO[R, E, B]
) { self =>
// compose with a ZIO not lifted into a Kleisli
def mapZIO[R1 <: R, E1 >: E, A1 <: A, C1](bc: B => ZIO[R1, E1, C1]): ZKleisli[R1, E1, A, C1] =
// Modify the output of the Kleisli function with `f`
View CayleyTransform.scala
import cats.{Applicative, Functor}
import cats.syntax.all._
/** Is this the proper Scala encoding for the Haskell snippet in comments ? */
/** from : */
/** with help from @Odomontois */
// newtype Cayley f a = Cayley {runC :: ∀b. f b → f (a, b) }
trait Cayley[F[_], A] {
debasishg / cayley.scala
Last active September 28, 2021 13:28
Encoding for Cayley transform in Scala
View cayley.scala
import cats.{ Applicative, Functor }
import cats.syntax.all._
/** Is this the proper Scala encoding for the Haskell snippet in comments ? */
/** from : */
// newtype Cayley f a = Cayley {runC :: ∀b. f b → f (a, b) }
sealed trait Cayley[F[_], A] {
def apply[B](fb: F[B]): F[(A, B)]
debasishg / phones.scala
Created September 16, 2021 17:38
Phone numbers out of chess moves
View phones.scala
package interview
object DominoInterview extends App {
debasishg / UnfoldPages.scala
Created June 14, 2021 18:36 — forked from rrodseth/UnfoldPages.scala
Create akka-stream Source from a pagination, using Source.unfoldAsync
View UnfoldPages.scala
// Inspired by a tweet from @trautonen 1/13/2016
// Use Source.unfoldAsync to turn paginated database results into an akka-streams Source
// unfold is the inverse of fold
case class Page[T](pageNumber:Long, totalPages:Long, contents:List[T])
case class Thing(id: Long, name: String = "foo")
val totalPages = 5 //
val pageSize = 3
View scalatest_future_fail.scala
import org.scalatest._
import org.scalatest.concurrent.ScalaFutures
import scala.concurrent.Future
// from
class ExampleSpec extends FlatSpec with Matchers with ScalaFutures {
sealed trait Boom extends Throwable
final case class ExampleFail() extends Boom
debasishg / cloudsql-proxy.ts
Created May 17, 2021 15:17 — forked from ddunkin/cloudsql-proxy.ts
Pulumi functions to setup and add a Google Cloud SQL Proxy sidecar to a Kubernetes deployment
View cloudsql-proxy.ts
import * as pulumi from '@pulumi/pulumi';
import * as gcp from '@pulumi/gcp';
import * as k8s from '@pulumi/kubernetes';
import * as k8sInputApi from '@pulumi/kubernetes/types/input';
const serviceAccountKeys = new Map<string, gcp.serviceAccount.Key>();
* Creates a service account and key, and sets the cloudsql.client role in IAM.
View async_redis_client.scala
import cats.effect._
object Main extends IOApp {
override def run(args: List[String]): IO[ExitCode] =
RedisClient.makeWithURI[IO](new URI("http://localhost:6379")).use { cmd =>
import cmd._
val result = for {
debasishg / refined_runtime_validation.scala
Created July 23, 2020 15:26
Incorporating compile time and runtime validation using refinement types in Scala
View refined_runtime_validation.scala
import cats.implicits._
import eu.timepit.refined._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.numeric._
import eu.timepit.refined.collection._
object person {

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.