Skip to content

Instantly share code, notes, and snippets.

@bishabosha
bishabosha / typefun.scala
Created March 18, 2025 19:56
Type function DSL scala
// example of a "type level function" resolved via implicit search using inline match - to get around named tuple types not working with match types
sealed trait Foo
type TypeFun[Cases <: Tuple] = [T] =>> TypeFun.Resolved[T, Cases]
type ->>[Case, R] = (Case, R)
object TypeFun:
sealed trait Wild[F[_]]
final class Resolved[T, Cases <: Tuple]:
type Out
@bishabosha
bishabosha / get-sdkman-x.sh
Last active February 26, 2025 15:02
Debuggable Get SDKMAN - does not perform redirects so maybe more usable from docker
#!/bin/bash
#
# Copyright 2017 Marco Vermeulen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@bishabosha
bishabosha / sbtScriptedToVulpix.sc
Created November 15, 2024 19:59
Copy sbt test to Vulpix
//> using toolkit default
//> using options -experimental
//> using scala 3.6.1
// This script copies from scala3/sbt-test/unroll-annot to dotty/tests/run
// current directory is repo for github.com/scala/scala3
val srcDir = os.pwd / "sbt-test" / "unroll-annot"
val destDir = os.pwd / "tests" / "run"
@bishabosha
bishabosha / pdfscan.sc
Created March 9, 2024 15:43
scala script to convert PDF to plain text
//> using repository "https://repo.e-iceblue.com/nexus/content/groups/public/"
//> using dep "e-iceblue:spire.pdf:9.10.3"
//> using dep "jakarta.xml.bind:jakarta.xml.bind-api:4.0.0"
//> using scala 3.4.0
//> using toolkit default
import com.spire.pdf.PdfDocument
import scala.util.Using, Using.Releasable
import scala.util.chaining.given
@bishabosha
bishabosha / hello.scala
Created January 25, 2024 19:32
Hello Scala
val hello = "Hello, world!"
val multiline = s"""
)))
))))))))))))))
))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))
))))))))))))))))))))))@@@@@@
)))))))@@@@@@@@@@@@@@@@@@@@)))
@@@@@@@@@@@@)))))))))))))
@bishabosha
bishabosha / day17-aoc-2021.scala
Last active November 30, 2023 11:17
Advent of Code Day 17 2021 using named tuples
//> using scala "3.4.0-RC1-namedtuples-bin-SNAPSHOT"
// original solution taken from https://scalacenter.github.io/scala-advent-of-code/puzzles/day17#final-code (by @bishabosha)
import scala.language.experimental.namedTuples
type Target = (xs: Range, ys: Range)
type Point = (x: Int, y: Int)
type Probe = (position: Point, velocity: Point)
val initial = (x = 0, y = 0)
@bishabosha
bishabosha / LazyClasspathSuite.test.scala
Last active November 1, 2023 10:42
tasty-query classpath from dotty classpath
//> using toolkit 0.2.1
//> using scala 3.3.1
//> using dep ch.epfl.scala::tasty-query:0.11.0
//> using dep org.scala-lang::scala3-compiler:3.3.1
//> using dep io.get-coursier:coursier_2.13:2.1.7
package tastyquery.jdk.classpaths
import tastyquery.Classpaths.Classpath
import tastyquery.Classpaths.ClasspathEntry
@bishabosha
bishabosha / MH.scala
Created July 19, 2023 09:48
MethodHandles with static fields in scala 3
package foo
import scala.annotation.static
import java.lang.invoke.{MethodHandle, MethodHandles, MethodType}
class MH
object MH:
@static private val lookup = MethodHandles.lookup()
@bishabosha
bishabosha / loops.scala
Last active December 14, 2024 22:55
Scala break/continue zero-cost loop abstraction
//> using scala "3.3.0"
import scala.util.boundary, boundary.break
object Loops:
type ExitToken = Unit { type Exit }
type ContinueToken = Unit { type Continue }
type Exit = boundary.Label[ExitToken]
@bishabosha
bishabosha / aoc-day-6-optimal.scala
Created December 6, 2022 16:30
AOC 2022 day 6 optimal
def part1(input: String): Int =
findIndexOptimal(input, n = 4)
def part2(input: String): Int =
findIndexOptimal(input, n = 14)
class MultiSet:
private val counts = new Array[Int](128)
private var total = 0
def size = total