Skip to content

Instantly share code, notes, and snippets.

@Odomontois
Odomontois / FromPublisher.scala
Created February 11, 2021 12:22
FromPublisher
package healer.reactive
import java.util.concurrent.atomic.{AtomicBoolean, AtomicReference}
import cats.effect.Concurrent
import cats.syntax.foldable._
import cats.syntax.monoid._
import cats.{Monad, Monoid}
import healer.reactive.impl._
import io.iteratee.Enumerator
@Odomontois
Odomontois / HigherKind.md
Last active September 23, 2020 18:33
Рак на Миде

Поясняю за Mid по запросу @aleksei_t

Исходная мысль была такая. Итак у нас есть

trait MyBusinessModule[F[_]]{
  def doBusinessThing(entity: Entity, info: Info): F[Value]
  def undoBusinessThing(entity: Entity): F[Respect]
}
@LMnet
LMnet / StreamPriorityUtils.scala
Last active May 26, 2020 15:37
StreamPriorityUtils
import cats.Applicative
import cats.data.NonEmptyList
import cats.effect.Concurrent
import cats.effect.concurrent.{Deferred, Ref}
import cats.implicits._
import fs2.concurrent.{InspectableQueue, SignallingRef}
import fs2.{Chunk, CompositeFailure, Scope, Stream}
object StreamPriorityUtils {
import cats.implicits._
import cats.effect.ExitCase.{Completed, Error}
import cats.effect.{ExitCode, IO, IOApp}
import cats.effect.concurrent.Ref
import eu.timepit.refined.api.{Refined, RefinedTypeOps}
import eu.timepit.refined.numeric.Interval
import eu.timepit.refined.W
import eu.timepit.refined.types.numeric.PosInt
import fs2.concurrent.Queue
import cats.effect.ExitCase._
import cats.effect.Sync
import cats.effect.concurrent.Ref
import cats.syntax.flatMap._
import cats.syntax.functor._
trait Tap[F[_]] {
def apply[A](effect: F[A]): F[A]
}
@jpsoroulas
jpsoroulas / debezium-installation.adoc
Last active March 29, 2024 15:46
Debezium installation procedure for PostgreSQL without docker

Debezium installation

@mtesseract
mtesseract / haskell-records.md
Last active March 8, 2023 22:25
Working around Haskell's namespace problem for records

The Problem

Defining records in Haskell causes accessor functions for the record's fields to be defined. There is no seperate namespace for these accessor functions.

The Goal

Be able to

  • use records in Haskell, which share field names.
  • use lenses for accessing these fields
@aappddeevv
aappddeevv / multiple cake-patterns.md
Last active January 27, 2024 16:01
scala, cake patterns, path-dependent types and composition (and a little bit of slick)

Scala and Cake Patterns and the Problem

Standard design patterns in scala recommend the cake pattern to help compose larger programs from smaller ones. Generally, for simple cake layers, this works okay. Boner's article suggests using it to compose repository and service layers and his focus is on DI-type composition. As you abstract more of your IO layers however, you realize that you the cake pattern as described does not abstract easily and usage becomes challenging. As the dependencies mount, you create mixin traits that express those dependence and perhaps they use self-types to ensure they are mixed in correctly.

Then at the end of the world, you have to mix in many different traits to get all the components. In addition, perhaps you have used existential types and now you must have a val/object somewhere (i.e. a well defined path) in order to import the types within the service so you can write your program. Existential

@chanks
chanks / gist:7585810
Last active February 29, 2024 03:50
Turning PostgreSQL into a queue serving 10,000 jobs per second

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t