Skip to content

Instantly share code, notes, and snippets.

View notxcain's full-sized avatar
🏠
Working from home

Denis Mikhaylov notxcain

🏠
Working from home
View GitHub Profile
@notxcain
notxcain / Observable.scala
Created May 14, 2018 11:46
Effect Polymorphic Push-based Observable
import cats.data.EitherT
import cats.effect.Timer
import cats.implicits._
import cats.{ApplicativeError, Foldable, Functor, Monad, MonadError}
import scala.concurrent.duration.FiniteDuration
trait Observable[F[_], A] { outer =>
def subscribe[O](observer: Observer[F, A, O]): F[O]
final def foldLeft[O](o: O)(f: (O, A) => O)(
@notxcain
notxcain / KafkaStream.scala
Last active May 11, 2018 11:45
Fs2 Kafka Consumer
import java.util
import java.util.{Collections, UUID}
import cats.effect.{Async, Timer}
import io.evotor.webhooks.common.Committable
import fs2._
import org.apache.kafka.clients.consumer._
import org.apache.kafka.common.TopicPartition
import org.apache.kafka.common.serialization.Deserializer
import scala.concurrent.blocking
@notxcain
notxcain / Root.scala
Created March 30, 2018 07:29
Opaque Sealed Hierarchy
// Tired of subtyping and `extends Product with Serializable`?
// It is impossible to instantiate a concrete subtype of `Root`
// It preserves pattern matching exhaustiveness check
sealed abstract class Root
object Root {
private final case class LeafInt(i: Int) extends Root
object LeafInt { def apply(i: Int): Root = new LeafInt(i) }
private final case class LeafString(s: String) extends Root
object LeafString { def apply(s: String): Root = new LeafString(s) }
@notxcain
notxcain / kill-pods.sh
Last active December 6, 2017 08:28
Continuously kill all pods except one randomly chosen.
#!/bin/bash
app=$1
chosen_one=$(kubectl get pods -l app=$app | tail -1 | awk '{print $1}')
echo "Keeping alive $chosen_one"
while true; do
pods=$(kubectl get pods -l app=$app | tail -n +2 | awk '{print $1}')
for pod in $pods; do
#!/bin/bash
working_dir="$( cd "$1" && pwd )"
chart_name=$(basename $(pwd))
unamestr=$(uname)
if [[ "$unamestr" == 'Darwin' ]]; then
sha='shasum'
elif [[ "$unamestr" == 'Linux' ]]; then
sha='sha1sum'
@notxcain
notxcain / Projection.scala
Created October 16, 2017 14:22
Projection
package com.evotor.payments.common
import aecor.data.Folded
import cats.MonadError
import cats.implicits._
object Projection {
def apply[F[_], I, E, S](
store: Store[F, I, Versioned[S]]
)(implicit F: MonadError[F, Throwable], SE: Eventsourced[S, E]): (I, Long, E) => F[Unit] = {
@notxcain
notxcain / cassandra-stress.md
Last active October 16, 2017 13:17
cassandra-stress

Digital Energy

> cassandra-stress mixed ratio\(write=1,read=3\) n=1000000 cl=QUORUM \
  -pop dist=UNIFORM\(1..1000000\) \
  -mode native cql3 \
  -rate threads=50 \
  -node test-cassandra21.market.local,test-cassandra22.market.local,test-cassandra23.market.local
import akka.http.scaladsl.server.Directives._
import akka.cluster.Member
import akka.actor.Address
import akka.http.scaladsl.model.StatusCodes
import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._
import io.circe.generic.auto._
val cluster = Cluster(system)
final case class ClusterView(status: MemberStatus,
@notxcain
notxcain / App.scala
Last active March 17, 2021 19:39
Akka Http Prometheus Endpoint
import io.prometheus.client.CollectorRegistry
import io.prometheus.client.dropwizard.DropwizardExports
import io.prometheus.client.hotspot.DefaultExports
import nl.grons.metrics.scala.DefaultInstrumented
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.http.scaladsl.Http
object App extends App with DefaultInstrumented {
Drift into Failure - http://www.amazon.com/Drift-into-Failure-Components-Understanding-ebook/dp/B009KOKXKY
How Complex Systems Fail - http://web.mit.edu/2.75/resources/random/How%20Complex%20Systems%20Fail.pdf
Leverage Points: Places to Intervene in a System - http://www.donellameadows.org/archives/leverage-points-places-to-intervene-in-a-system/
Going Solid: A Model of System Dynamics and Consequences for Patient Safety - http://www.ncbi.nlm.nih.gov/pmc/articles/PMC1743994/
Resilience in Complex Adaptive Systems: Operating at the Edge of Failure - https://www.youtube.com/watch?v=PGLYEDpNu60
Puppies! Now that I’ve got your attention, Complexity Theory - https://www.ted.com/talks/ nicolas_perony_puppies_now_that_i_ve_got_your_attention_complexity_theory
How Bacteria Becomes Resistant - http://www.abc.net.au/science/slab/antibiotics/resistance.htm
Towards Resilient Architectures: Biology Lessons - http://www.metropolismag.com/Point-of-View/March-2013/Toward-Resilient-Architectures-1-Biology-Lessons/ Dealing in