Skip to content

Instantly share code, notes, and snippets.

View Vilkina's full-sized avatar
❤️
I may be slow to respond.

Aleksandra A Vilkina

❤️
I may be slow to respond.
View GitHub Profile
sealed trait TreeSeq[+A] {
lazy val size: Int = this match {
case Leaf(_) => 1
case Branch(l, r) => (l.size + r.size)
}
def +[A1 >: A](a1: A1): TreeSeq[A1] = TreeSeq(a1)
name := "zio-kafka-test"
version := "0.1"
scalaVersion := "2.13.3"
libraryDependencies += "dev.zio" %% "zio-kafka" % "0.12.0"
libraryDependencies += "dev.zio" %% "zio-streams" % "1.0.0"
object Test {
import zio._
import zio.duration._
import zio.kafka.consumer._
val settings: ConsumerSettings =
ConsumerSettings(List("localhost:9092"))
.withGroupId("group")
.withClientId("client")
import zio._
import zio.console._
import zio.kafka.consumer._
import zio.kafka.serde._
val subscription: Subscription = Subscription.topics("topic")
val readKafka: RIO[Console with Blocking with Clock, Unit] =
Consumer.consumeWith(settings, subscription, Serde.string, Serde.string) {
case (key, value) =>
putStrLn(s"Received message ${key}: ${value}")
object Test {
import zio._
import zio.duration._
import zio.kafka.consumer._
val settings: ConsumerSettings =
ConsumerSettings(List("localhost:9092"))
.withGroupId("group")
.withClientId("client")
object Test {
import zio._
import zio.duration._
import zio.kafka.consumer._
val settings: ConsumerSettings =
ConsumerSettings(List("localhost:9092"))
.withGroupId("group")
.withClientId("client")
@Vilkina
Vilkina / immutable-red-black-tree.js
Created April 24, 2023 08:14
Red-Black Tree in JavaScript with ES6 syntax
class Node {
constructor(key, value, color, left = null, right = null) {
Object.assign(this, { key, value, color, left, right });
}
async insert(key, value) {
const cmp = key < this.key ? "left" : "right";
const child = this[cmp];
const newChild = child === null ? new Node(key, value, true) : await child.insert(key, value);
return newChild.color && this.color ? this.fixup(newChild, cmp) : new Node(this.key, this.value, this.color, cmp === "left" ? newChild : this.left, cmp === "right" ? newChild : this.right);