Skip to content

Instantly share code, notes, and snippets.

View lbialy's full-sized avatar

Łukasz Biały lbialy

View GitHub Profile
@lbialy
lbialy / graalvm-in-docker.txt
Created March 28, 2024 21:30
Have fun Anton
$ sbt new http4s/http4s.g8 --branch 1.0-scala3
// use all the defaults, just set sbt to 1.9.9
$ cd quickstart
$ sbt assembly
$ cat Dockerfile # create this file with these contents:
FROM ghcr.io/graalvm/jdk-community:22
RUN mkdir /opt/app
//> using scala 3.4.0
import language.experimental.captureChecking
class DbCon:
def runUpdate(): Unit = println(s"runUpdate on ${Thread.currentThread()}")
def close(): Unit = println("closing DbCon")
def transact[A](f: DbCon^ => A): A =
val dbCon = DbCon()
@lbialy
lbialy / backpressure.scala
Created March 2, 2024 22:10
Demonstration of backpressure with Loom
//> using scala 3.3.3
//> using jvm graalvm-java21:21.0.2
//> using dep com.softwaremill.ox::core:0.0.21
import ox.*
import java.util.concurrent.*
@main def main = supervised {
val queue = ArrayBlockingQueue[Int](5)
@lbialy
lbialy / Helpers.scala
Last active February 27, 2024 17:19 — forked from prolativ/Helpers.scala
import scala.quoted.*
extension (using quotes: Quotes)(repr: quotes.reflect.TypeRepr)
def flatMapResultType(f: quotes.reflect.TypeRepr => Option[quotes.reflect.TypeRepr]): Option[quotes.reflect.TypeRepr] =
import quotes.reflect.*
repr match
case MethodType(paramNames, paramTypes, resultType) =>
resultType.flatMapResultType(f).map(tp => MethodType(paramNames)(_ => paramTypes, _ => tp))
// case PolyType => // should not appear here
case tp =>
@lbialy
lbialy / caliban-demo.sc
Last active December 30, 2023 13:04
Run with `scala-cli run caliban-demo.sc` or `scala-cli run https://gist.github.com/lbialy/c9aa46136f3ee7897600c697de273567`
//> using dep com.github.ghostdogpr::caliban-quick:2.5.0
enum Origin {
case EARTH, MARS, BELT
}
case class Character(
name: String,
nicknames: List[String],
origin: Origin
@lbialy
lbialy / main.scala
Last active December 29, 2023 21:09
comparing word counting: std vs fs2
//> using scala "3.3.1"
//> using lib "co.fs2::fs2-io:3.9.3"
import scala.util.*
import scala.io.Source
def safePrintln(s: Any): Either[Throwable, Unit] =
try Right(println(s))
catch case err: Throwable => Left(err)
@lbialy
lbialy / app.decompiled.java
Created October 27, 2023 12:24
Decompiled Kotlin coroutine rendezvous from SML Blogpost
// AppKt.java
package hello;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.CoroutineContext;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.SourceDebugExtension;
@lbialy
lbialy / pom.xml
Created October 27, 2023 11:10
Pom for kotlin coroutines rendezvous snippet
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jetbrains.kotlin.examples</groupId>
<artifactId>hello-world</artifactId>
<version>1.0-SNAPSHOT</version>
@lbialy
lbialy / README.md
Created October 6, 2023 19:56
Scala Ox handling JDBC interruption
@lbialy
lbialy / release-repository.sh
Created September 24, 2023 08:05 — forked from romainbsl/release-repository.sh
Sonatype: close and release a staging repository
#!/usr/bin/env bash
username=
password=
stagedRepositoryId=
while [ "$1" != "" ]; do
case $1 in
-u | --username)
shift