Skip to content

Instantly share code, notes, and snippets.

View jchapuis's full-sized avatar

Jonas Chapuis jchapuis

View GitHub Profile
@Daenyth
Daenyth / CachedResource-Blog.md
Last active March 26, 2024 17:19
CachedResource for cats-effect

Concurrent resource caching for cats

Motivation

cats-effect Resource is extremely handy for managing the lifecycle of stateful resources, for example database or queue connections. It gives a main interface of:

trait Resource[F[_], A] {
  /** - Acquire resource
    * - Run f
 * - guarantee that if acquire ran, release will run, even if `use` is cancelled or `f` fails
@laughedelic
laughedelic / sbt-dependency-management-guide.md
Last active April 25, 2024 19:06
Explicit dependency management in sbt

Some of these practices might be based on wrong assumptions and I'm not aware of it, so I would appreciate any feedback.

  1. avoiding some dependency conflicts:

    • install sbt-explicit-dependencies globally in your ~/.sbt/{0.13,1.0}/plugins/plugins.sbt
    • run undeclaredCompileDependencies and make the obvious missing dependencies explicit by adding them to libraryDependencies of each sub-project
    • (optionally) run unusedCompileDependencies and remove some obvious unused libraries. This has false positives, so ; reload; Test/compile after each change and ultimately run all tests to see that it didn't break anything
    • (optionally) add undeclaredCompileDependenciesTest to the CI pipeline, so that it will fail if you have some undeclared dependencies
  2. keeping dependencies up to date and resolving conflicts:

    • install sbt-updates globally in your `~/.sbt/{0.13,1.0}/plugins/plugins.

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.

@cedricwalter
cedricwalter / readme.md
Last active October 29, 2021 08:56
Sonatype NEXUS 2 has a rest API :-) but NEXUS 3 has none/not ready, the following simulate curl/wget call

Fetching artifact programmatically through REST/API fro Nexus2/3

Nexus 2.x had a REST API to download artifacts like below based on some Maven GAV co-ordinates but this no longer works for Nexus 3.x

Nexus 2.x

Nexus 2.x had a REST API to download artifacts based on some Maven GAV co-ordinates

wget "http://local:8081/service/local/artifact/maven/redirect?g=com.mycompany&a=my-app&v=LATEST" --content-disposition

or

@eunomie
eunomie / README.md
Created April 27, 2017 09:44
How to send containers log to ELK using gelf log driver

Send docker logs to ELK through gelf log driver

There's so many way to send logs to an elk... logspout, filebeat, journalbeat, etc.

But docker has a gelf log driver and logstash a gelf input. So here we are.

Here is a docker-compose to test a full elk with a container sending logs via gelf.

@tg44
tg44 / CombineLatest.scala
Last active July 27, 2018 06:09
Quick implementation of the CombineLatest RX operator in AkkaStreams
import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl.{Flow, GraphDSL, Keep, RunnableGraph, Sink, Source}
import akka.stream.stage.{GraphStage, GraphStageLogic, InHandler, OutHandler}
import akka.testkit.TestKit
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
import scala.concurrent.Await
class CombineLatest[A, B]
@thesamet
thesamet / ScalaPbSerializer.scala
Last active November 30, 2020 05:50
Akka serializer for ScalaPB messages
package protoser
import java.util.concurrent.atomic.AtomicReference
import akka.actor.ExtendedActorSystem
import akka.serialization.BaseSerializer
import com.trueaccord.scalapb.GeneratedMessageCompanion
class ScalaPbSerializer(val system: ExtendedActorSystem) extends BaseSerializer {
private val classToCompanionMapRef = new AtomicReference[Map[Class[_], GeneratedMessageCompanion[_]]](Map.empty)
import com.google.protobuf.Descriptors.{MethodDescriptor, ServiceDescriptor}
import com.trueaccord.scalapb.compiler.FunctionalPrinter.PrinterEndo
import com.trueaccord.scalapb.compiler._
import scala.collection.JavaConverters._
final class MonixGrpcPrinter(service: ServiceDescriptor,
override val params: GeneratorParams)
extends DescriptorPimps {
import java.util.concurrent.TimeUnit
import monix.execution.cancelables.MultiAssignmentCancelable
import monix.execution.{Cancelable, Scheduler}
import monix.execution.schedulers.{ExecutionModel, LocalBatchingExecutor}
import scala.concurrent.ExecutionContext
import scala.concurrent.duration.FiniteDuration
class AkkaToMonixScheduler(
akkaScheduler: akka.actor.Scheduler,
context: ExecutionContext,
@MichalZalecki
MichalZalecki / index.js
Created March 12, 2016 12:24
How to import RxJS 5
// Import all
import Rx from "rxjs/Rx";
Rx.Observable
.interval(200)
.take(9)
.map(x => x + "!!!")
.bufferCount(2)
.subscribe(::console.log);