Skip to content

Instantly share code, notes, and snippets.

View kubukoz's full-sized avatar
😱
I might take a week to respond. Or a month.

Jakub Kozłowski kubukoz

😱
I might take a week to respond. Or a month.
View GitHub Profile
@kubukoz
kubukoz / compile.sh
Created January 13, 2024 00:46
Primitive Playdate game built with clang
#!/bin/bash
set -euo pipefail
# You'll have to change this, also see note about caveat below
SDK_PATH=/Users/kubukoz/Developer/PlaydateSDK/C_API
rm -rf HelloWorld.pdx || true
rm Source/pdex.elf || true
@kubukoz
kubukoz / slides.md
Last active November 11, 2023 10:34
Let's build an IDE!

Jakub Kozłowski | Scala in the city | 26 X 2023

Code | Recording


Why build an IDE?

  1. For fun
  2. For your proprietary DSL
@kubukoz
kubukoz / scala3tailrec-inline.sc
Created October 15, 2023 21:40
Scala 3 inlines before tailrec analysis
// compiles
//> using scala "3.3.1"
import scala.annotation.tailrec
case class Opt[A](value: A | Null) {
inline def flatMap[B](inline f: A => Opt[B]): Opt[B] =
if (value == null)
Opt(null)
else
@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

@kubukoz
kubukoz / showProcessedCount.scala
Created March 15, 2021 17:39
Periodically show the amount of elements produced by an fs2 stream
def showProcessedCount[F[_]: Concurrent: Timer, A]: Pipe[F, A, A] = stream =>
fs2.Stream.eval(Ref[F].of(0)).flatMap { count =>
stream.chunks
.evalMap { chunk =>
count.update(_ + chunk.size).as(chunk)
}
.flatMap(fs2.Stream.chunk)
.concurrently(
fs2.Stream
@kubukoz
kubukoz / ngrams.scala
Created May 4, 2023 18:24
My solution to the "top n-grams" problem for my mock interview on Marcin Krykowski's channel
//> using scala "3.2.2"
//> using lib "co.fs2::fs2-io:3.6.1"
//> using lib "io.circe::circe-core:0.14.5"
//> using lib "io.circe::circe-parser:0.14.5"
import cats.data.NonEmptyList
import cats.effect.IO
import cats.effect.IOApp
import cats.implicits.*
import cats.kernel.Order
import fs2.io.file.Files
@kubukoz
kubukoz / Demo.scala
Created April 19, 2023 13:50
Using `getAndDiscreteUpdates` and `mapN` and it still works
//> using lib "co.fs2::fs2-core:3.7.0-RC4"
import cats.effect.IOApp
import cats.effect.IO
import scala.concurrent.duration._
import cats.effect.std.UUIDGen
import cats.implicits._
import scala.util.Random
import fs2.concurrent.Signal
object Demo extends IOApp.Simple {
@kubukoz
kubukoz / fs2zip.scala
Created January 22, 2023 04:03
Example of using fs2 + ZipInputStream to open a zipfile in Scala. Probably buggy and maybe leaky.
//> using scala "2.13.10"
//> using lib "co.fs2::fs2-io:3.5.0"
//> using option "-Wunused:imports"
import cats.effect.IO
import cats.effect.IOApp
import cats.effect.kernel.Resource
import cats.implicits._
import fs2.io.file.Files
import fs2.io.file.Path
https://www.usenix.org/legacy/events/hotos07/tech/full_papers/dolstra/dolstra.pdf
https://edolstra.github.io/pubs/phd-thesis.pdf
https://nixos.org/manual/nix/stable/
https://nixos.org/guides/nix-pills/index.html
https://nix.dev/
https://wiki.nikitavoloboev.xyz/package-managers/nix
https://edolstra.github.io/pubs/nixos-jfp-final.pdf
https://nixos.org/docs/SCR-2005-091.pdf
https://medium.com/@MrJamesFisher/nix-by-example-a0063a1a4c55
https://scrive.github.io/nix-workshop/01-getting-started/01-introduction.html
@kubukoz
kubukoz / demo.scala
Created December 15, 2022 01:25
Smithy's NeighborProvider and unit shapes
//> using lib "software.amazon.smithy:smithy-model:1.26.4"
//> using scala "2.13.10"
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.neighbor.NeighborProvider
import software.amazon.smithy.model.shapes.ShapeId
import scala.jdk.CollectionConverters._
object demo extends App {