Skip to content

Instantly share code, notes, and snippets.

View plokhotnyuk's full-sized avatar

Andriy Plokhotnyuk plokhotnyuk

View GitHub Profile
@lukestephenson
lukestephenson / readme.md
Last active January 29, 2024 08:12
Comparing Scala streaming library performance

Diving into Monix / Akka performance compared to fs2 and ZIO-streams

Disclaimer: Firstly, I'm not an expert in any of these libraries. I'm writing this from a position of sharing what I have learnt so far, but also hoping to be criticised and learn a lot more in the process.

Both fs2 and zio-streams document the need to make use of "Chunking". Here is what the zio-streams docs say:

Every time we are working with streams, we are always working with chunks. There are no streams with individual elements, these streams have always chunks in their underlying implementation. So every time we evaluate a stream, when we pull an element out of a stream, we are actually pulling out a chunk of elements.

So why streams are designed in this way? This is because of the efficiency and performance issues. Every I/O operation in the programming world works with batches. We never work with a single element.

While this is true that IO operations work with batches, from a programmers perspective it is sometimes easier

@thomasdarimont
thomasdarimont / MainMethodFinder.java
Last active September 8, 2023 22:28
Small tool to find classes with executable main methods in a given JDK.
import jdk.internal.org.objectweb.asm.*;
import java.io.*;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.Consumer;
/**
@adamw
adamw / gen.scala
Created September 6, 2022 07:15
How to generate an exhaustive match for a sealed trait in a Scala 3 macro?
// TestMacro.scala
import scala.quoted.*
object TestMacro {
inline def name[E](e: E): String = ${ nameImpl[E]('e) }
def nameImpl[E: Type](e: Expr[E])(using Quotes): Expr[String] = {
import quotes.reflect.*
@rail01
rail01 / Public_Polish_NTP_Servers.md
Last active April 25, 2024 14:45
List of publickly accessible NTP time servers in Poland

Below is the list of publickly accessible NTP time servers located in Poland, along with their hostnames, IP addresses, Stratum levels, AS numbers and contact information.

List consists of trustworthy sources such as government agencies, scientific organizations, ISPs or major infrastructure providers. STRATUM 1 and 2.

If you're looking to use any of those NTP servers in business-critical production environment, please consider obtaining time from a time source directly, e.g. via GPS receiver or caesium atomic clock.

List

Host organization Hostname(s) IPv4 IPv6 STRATUM ASN Contact information
Główny Urząd Miar (Central Office of Measures) tempus1.gum.gov.pl tempus2.gum.gov.pl 194.146.251.100 194.146.251.101 N/A 1 AS50606 time@gum.gov.pl
@chadbrewbaker
chadbrewbaker / notes-22-may-2022.md
Last active May 29, 2022 19:45
29 May 2022 Perfchat Show Notes

Snake With FRP

Introduction

The Game

I've been working on a side project for the past several days: making a Snake using purely reactive programming with ScalaJS. You can play it at https://wildfield.github.io/snake/. The source code at https://github.com/wildfield/snake-frp

Reader PSA: A lot of wheel reinvention and non-standard terminology ahead. This is not supposed to be a tutorial of any sorts, instead I just wanted to share a cool concept I've been working on.

HotSpot Escape Analysis and Scalar Replacement Status

Introduction

Escape Analysis (EA) is a compiler analysis to answer the following questions for a given object O, method M, and thread T.

  • Escapes(O, M): Does object O outlive the execution of method M? This may happen for instance if a reference to O is assigned to a global variable.
  • Escapes(O, T): Does object O escape the current execution thread? This may happen for instance if a reference to O is copied to another thread.

Answers to these questions enable a compiler to perform a few highly effective optimizations, for instance, Stack Allocation (SA), Lock Elision (LE), and Scalar Replacement of Aggregates (SRA). Note that,

@romanskie
romanskie / KafkaJsonSerde.scala
Last active June 16, 2020 07:50
A sample Kafka JSON SerDe written in Scala by using the Circe JSON library.
import java.nio.ByteBuffer
import java.util
import io.circe.parser._
import io.circe.syntax._
import io.circe.{Decoder, Encoder, _}
import org.apache.kafka.common.errors.SerializationException
import org.apache.kafka.common.serialization.{Deserializer, Serde, Serializer}
import scala.util.Try
@nadavwr
nadavwr / .gitpod.Dockerfile
Created May 28, 2020 15:18
GitPod Metals setup
FROM gitpod/workspace-full
USER gitpod
RUN brew install coursier/formulas/coursier
ENV COURSIER_CACHE /workspace/.coursier/cache/v1
RUN cs setup --yes --jvm 14 --apps sbt-launcher,scala,scalafmt,mill,mill-interactive
@jodersky
jodersky / pickler.scala
Created May 26, 2020 17:57
Simple ujson-based pickler using Dotty typeclass derivation
import scala.deriving._
import scala.compiletime.{erasedValue, summonInline}
// super primitive (but composable via typeclass derivation) JSON reader
trait Reader[A] {
def read(json: ujson.Value): A
}
object Reader {
given Reader[Int] = new Reader[Int] {