Skip to content

Instantly share code, notes, and snippets.

View LMnet's full-sized avatar

Yuriy Badalyants LMnet

View GitHub Profile
@dataclass
class InstanceGroups:
master_nodes: Ec2InstancesGroup
core_nodes: Ec2InstancesGroup
@dataclass
class InstanceFleets:
config: list[dict[str, any]]
subnets: set[KnownEc2Subnets]
@LMnet
LMnet / StreamUtils.scala
Last active September 29, 2022 14:07
StreamUtils with parJoinPrioritized
package fs2
import cats.Applicative
import cats.effect.kernel.{Fiber, Outcome}
import cats.effect.syntax.all._
import cats.effect.{Concurrent, Deferred}
import cats.syntax.all._
import fs2.concurrent.{Channel, SignallingRef}
import fs2.internal.Scope
import tmp.Queue
@LMnet
LMnet / UnNone.scala
Last active May 25, 2020 11:27
unNone method on scala 2.13 collections
import scala.collection.generic.IsIterable
import scala.collection.{BuildFrom, IterableOps}
import scala.language.implicitConversions
// Пример для одной конкретной коллекции, рабочий
object ListUtils {
implicit class ListOps[A](val self: List[A]) extends AnyVal {
def unNone[B](implicit ev: A <:< Option[B]): List[B] = {
ev.liftCo(self).collect {
case Some(x) => x
@LMnet
LMnet / readWithDefaults.scala
Last active November 8, 2019 05:33
Doobie readWithDefaults
/**
* Summon `Read[A]` instance for case class `A` with default parameters.
* {{{
* case class A(a: String, b: Boolean = false)
* implicit val aRead: Read[A] = readWithDefaults[A]()
* }}}
*/
class readWithDefaults[A] {
def apply[
@LMnet
LMnet / GlobalSeed.scala
Created October 16, 2019 08:24
Stable scalacheck seed
import java.util.concurrent.atomic.AtomicReference
import org.scalacheck.rng.Seed
import scala.annotation.tailrec
import scala.util.Try
class GlobalSeed(initial: Seed) extends Seed {
private val current = new AtomicReference[Seed](initial)
@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 {
@LMnet
LMnet / docker-compose.yml
Created April 22, 2019 07:12
Kafka docker compose
version: '2.1'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "32181:2181"
healthcheck:
test: "./bin/zkServer.sh status"
interval: 5s
@LMnet
LMnet / LazyFuture.scala
Created February 9, 2019 08:14
LazyFuture example for pragmatic fp talk
package monix.eval
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.concurrent.duration._
object Test extends App {
object LazyFuture {
def delay[A](body: => A): LazyFuture[A] = {
@LMnet
LMnet / LabelledGenericDescription.scala
Last active October 16, 2018 04:01
LabelledGeneric based keys descriptions
import shapeless._
import shapeless.record._
case class User(
id: Long,
name: String,
age: Int
)
val user = User(15L, "Test", 25)
@LMnet
LMnet / MatrixPermutations.scala
Last active June 7, 2018 01:40
Находит все перестановки в матрице
object MatrixPermutations {
def main(args: Array[String]): Unit = {
val in = List(
List(1,2),
List(3,4),
List(5,6),
)
def findAllPermutations[T](matrix: List[List[T]]): List[List[T]] = {