Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View guizmaii's full-sized avatar
🏄‍♂️

Jules Ivanic guizmaii

🏄‍♂️
View GitHub Profile
@lbialy
lbialy / local-mutability-under-spectacle.scala
Last active September 16, 2023 17:02
Early check whether Chimney can deal with mutable classes and whether it even makes sense to use localised mutability at all. Needs JMH.
//> using lib "io.github.martinhh::scalacheck-derived:0.4.1"
//> using lib "org.scalacheck::scalacheck:1.17.0"
//> using lib "io.scalaland::chimney:0.8.0-M1"
//> using lib "org.openjdk.jmh:jmh-core:1.37"
package local.mutability
import scala.collection.mutable
import io.scalaland.chimney.dsl.*
@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

import zio.*
import zio.prelude.*
import zio.prelude.fx.*
object BaseSyntax:
type Program[S, R, E, A] = ZPure[Nothing, S, S, R, E, A]
type LoggedProgram[W, S, R, E, A] = ZPure[W, S, S, R, E, A]
@kubukoz
kubukoz / semiauto-vs-auto.md
Created October 5, 2021 17:36
Semiauto vs auto derivation

You mention that you would only use circe auto derivation in only a few limited cases - may I ask why? It looks like you are using semi-auto derivation instead. Why is this better/more stable?

The difference is where the derivation happens - in semiauto, you only have one place where a codec for a given type will be derived: at definition site, which is usually the companion object (it's the companion object in our case, but it could be anywhere really - point still stands that it's easier to track). In auto derivation, codecs are derived as needed by the usage - e.g. in the endpoint definitions or in a controller (depending on the tech stack you use). The problem here is that you need all the codecs of all the fields and all their fields (...and so on...) to be available there.

The centralization of the codecs in Semiauto mode allows us to switch to a different format at any time, while keeping the representation consistent across all usages of it. Additionally, it allows us to test the codec logic witho

@petrbouda
petrbouda / memory-limit-request-jvm.md
Last active March 10, 2024 22:55
Memory LIMIT and REQUEST in Containers and JVM

Memory LIMIT and REQUEST in Containers and JVM

  • Do you run a JVM inside a container on Kubernetes (or maybe OpenShift)?
  • Do you struggle with REQUEST and LIMIT parameters?
  • Do you know the impact of those parameters on your JVM?
  • Have you met OOM Killer?

Hope you will find answers to these questions in this example-based article.

How to set up JVM Heap size in a Container

Fibers

Fibers are an abstraction over sequential computation, similar to threads but at a higher level. There are two ways to think about this model: by example, and abstractly from first principles. We'll start with the example.

(credit here is very much due to Fabio Labella, who's incredible Scala World talk describes these ideas far better than I can)

Callback Sequentialization

Consider the following three functions

@nigredo-tori
nigredo-tori / JlinkPluginFix.scala
Last active August 23, 2021 04:04
JlinkPlugin settings to make dealing with jdeps less of a pain
import java.lang.{Runtime => JRuntime}
import java.lang.module.ModuleDescriptor
import java.net.URI
import java.nio.file.FileSystems
import java.util.jar.JarFile
import java.util.zip.ZipFile
import scala.collection.JavaConverters._
import com.typesafe.sbt.packager.archetypes.jlink.JlinkPlugin
import com.typesafe.sbt.packager.archetypes.jlink.JlinkPlugin.autoImport._
@ChristopherDavenport
ChristopherDavenport / Libraries.md
Last active February 1, 2024 11:38
A Current Listing of Libraries
@nileshtrivedi
nileshtrivedi / home-server.md
Last active January 10, 2024 06:30
Home Server setup: Raspberry PI on Internet via reverse SSH tunnel

Raspberry Pi on Internet via reverse SSH tunnel

HackerNews discussed this with many alternative solutions: https://news.ycombinator.com/item?id=24893615

I already have my own domain name: mydomain.com. I wanted to be able to run some webapps on my Raspberry Pi 4B running perpetually at home in headless mode (just needs 5W power and wireless internet). I wanted to be able to access these apps from public Internet. Dynamic DNS wasn't an option because my ISP blocks all incoming traffic. ngrok would work but the free plan is too restrictive.

I bought a cheap 2GB RAM, 20GB disk VM + a 25GB volume on Hetzner for about 4 EUR/month. Hetzner gave me a static IP for it. I haven't purchased a floating IP yet.

@nafg
nafg / paramCodec.scala
Last active March 10, 2020 10:55
Deriving circe with Magnolia but only as a fallback
import scala.language.experimental.macros
import scala.reflect.ClassTag
import io.circe.{Decoder, Encoder, Json}
import magnolia._
class ParamEncoder[T](val underlying: Encoder[T]) extends AnyVal
trait ParamEncoderLowPriority {
type Typeclass[T] = ParamEncoder[T]