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 / tg.scala
Created March 29, 2025 13:31
reviving an old concept for a new tagless final encoding in scala 3, thanks to inspiration from Noel Welsh's scalar 2025 talk
//> using dep org.typelevel::cats-effect:3.6.0
import cats.effect.IO
import cats.effect.unsafe.IORuntime
import cats.effect.IOApp
enum Permission {
case View
case Edit
case Both(p1: Permission, p2: Permission)
}
@kubukoz
kubukoz / finally-noel.scala
Last active March 29, 2025 13:19 — forked from arosien/finally-noel.scala
tagless final implementation from noel welsh's talk "tagless final for humans" https://noelwelsh.com/talks/tagless-final-for-humans
// https://noelwelsh.com/talks/tagless-final-for-humans
trait Algebra:
type Ui[_]
trait Controls extends Algebra:
def text(prompt: String): Ui[String]
def choice(prompt: String, options: (String, Boolean)*): Ui[Boolean]
// etc...
@kubukoz
kubukoz / ws.scala
Created September 21, 2024 18:09
WebSocket server in http4s that forwards messages from each client to the others
//> using dep org.http4s::http4s-ember-server::0.23.28
import cats.effect.IO
import cats.effect.IOApp
import cats.effect.std.UUIDGen
import cats.syntax.all.*
import fs2.concurrent.Topic
import org.http4s.HttpApp
import org.http4s.ember.server.EmberServerBuilder
import org.http4s.websocket.WebSocketFrame
@kubukoz
kubukoz / .scalafmt.conf
Last active February 1, 2025 19:53
How to disable significant indentation in Scala
runner.dialect = scala3
runner.dialectOverride.allowSignificantIndentation = false
# allows `if x then y`
runner.dialectOverride.allowQuietSyntax = true
//> using option -Ykind-projector
trait Demo {
type LA
type LB
type RA
type RB
def x(using
laEqLb: LA =:= LB,
raEqRb: RA =:= RB
@kubukoz
kubukoz / SagemakerMock.scala
Created July 26, 2024 13:43
Sagemaker invocation mock with http4s and records4s
//> using dep org.http4s::http4s-ember-server:0.23.27
//> using dep org.http4s::http4s-dsl:0.23.27
//> using dep org.http4s::http4s-circe:0.23.27
//> using dep com.github.tarao::record4s-circe:0.13.0
//> using option -Wunused:all
import cats.effect.IO
import cats.effect.IOApp
import com.comcast.ip4s.*
import com.github.tarao.record4s.%
import com.github.tarao.record4s.select
@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 July 6, 2024 15:26
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 / 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