Skip to content

Instantly share code, notes, and snippets.

@bishabosha
bishabosha / hello.scala
Created January 25, 2024 19:32
Hello Scala
val hello = "Hello, world!"
val multiline = s"""
)))
))))))))))))))
))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))
))))))))))))))))))))))@@@@@@
)))))))@@@@@@@@@@@@@@@@@@@@)))
@@@@@@@@@@@@)))))))))))))
@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 / 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 / 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 / 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 / NTCopy.scala
Last active May 6, 2025 16:25
Named Tuple copy method
import NamedTuple.{Names, AnyNamedTuple, NamedTuple}
type ContainsAll[X <: Tuple, Y <: Tuple] <: Boolean = X match
case x *: xs => Tuple.Contains[Y, x] match
case true => ContainsAll[xs, Y]
case false => false
case EmptyTuple => true
type FilterName0[N, Ns1 <: Tuple, Vs1 <: Tuple] <: Option[Any] =
(Ns1, Vs1) match
case (N *: ns, v *: vs) => Some[v]
@bishabosha
bishabosha / bench.scala
Created May 31, 2025 20:19
SimpleTable benchmarks
//> using jmh
//> using toolkit 0.7.0
//> using scala 3.7.0
//> using dep org.scala-lang::scala3-compiler:3.7.0
package bench
import dotty.tools.dotc.Driver
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.annotations.Scope
@bishabosha
bishabosha / Scala.plist
Created September 25, 2025 09:46
Scala BBEdit Module with metals LSP
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- Enhanced Scala Codeless Language Module for BBEdit
Supports advanced syntax highlighting, folding, function indexing, and Metals LSP -->
<dict>
<!-- You must identify the plist as a CLM: -->
@bishabosha
bishabosha / zed_tasks.json
Created October 10, 2025 18:16
Zed configuration to extract main class fqn for Scala
[
{
"label": "Scala run",
"command": "scala",
"args": [
"run",
"-M",
"$(if [ -z \"${ZED_CUSTOM_scala_package_name:}\" ] ; then echo \"$ZED_CUSTOM_scala_main_function_name\"; else echo \"${ZED_CUSTOM_scala_package_name:}.$ZED_CUSTOM_scala_main_function_name\"; fi)",
"$ZED_WORKTREE_ROOT"
],
@bishabosha
bishabosha / string-interpolators.scala
Created November 3, 2025 14:58
Useful Scala string interpolators
extension (ctx: StringContext)
/** Regex pattern */
transparent inline def rg(s: Any*): scala.util.matching.Regex =
ctx.raw(s*).r
/** Whitespace-Separated list*/
transparent inline def ws(s: Any*): IndexedSeq[String] =
ctx.s(s*).split(raw"\s+").filter(_.nonEmpty).toIndexedSeq