Skip to content

Instantly share code, notes, and snippets.

@majk-p
majk-p / main.scala
Created April 4, 2025 13:48
[fix] Found A => A instead of missing given instance - fixed by chaning order of givens
//> using scala 3.3.5
trait StreamArnFor[A] {
val name: String
}
object api {
def expect[
CompanionObject,
@majk-p
majk-p / main.scala
Created April 4, 2025 13:47
Found A => A instead of missing given instance
//> using scala 3.3.5
trait StreamArnFor[A] {
val name: String
}
object api {
def expect[
CompanionObject,
@majk-p
majk-p / lib.scala
Created January 9, 2025 14:28
Weird behavior of -Ywarn-unused:privates
package example
private object lib {
def doStuff = println("Hello from MyLib")
}
@majk-p
majk-p / sort.scala
Last active December 18, 2024 15:00
Selection sort
import scala.annotation.tailrec
object SelectionSort {
@tailrec
def sort(arr: List[Int], acc: List[Int] = Nil): List[Int] = {
if (arr.isEmpty) acc.reverse
else {
val min = arr.min
val (left, right) = arr.span(_ != min)
@majk-p
majk-p / main.py
Created December 12, 2024 20:45
atproto to smithy converter
import os
import json
import argparse
from typing import Dict, Any, List
def convert_atproto_type_to_smithy(atproto_type: str, nested: bool = False) -> str:
"""
Convert ATP types to Smithy types with more robust type mapping
"""
type_mapping = {
@majk-p
majk-p / Encoder.scala
Last active November 20, 2024 13:40
Bug in union-derivation 0.2.0
import cats.Show
import cats.syntax.all.*
trait Encoder[A] {
def encode(v: A): String
}
object Encoder extends EncoderDerivation {
object instances {
@majk-p
majk-p / main.scala
Created October 8, 2024 05:25
Scala 3.3.3 -> 3.3.4 regression example
//> using dep "org.typelevel::cats-effect:3.5.4"
//> using scala "3.3.3"
import cats.Functor
import cats.effect.std.UUIDGen
import cats.syntax.all.*
import java.util.UUID
final class MyId private (val id: String)
@majk-p
majk-p / oslib-weaver-expecty.test.scala
Created September 13, 2024 09:27
Reproduction example of multisegment os.Path breaking expecty
//> using dep "com.disneystreaming::weaver-cats:0.8.4"
//> using dep "com.lihaoyi::os-lib:0.10.7"
import weaver.*
import os.Path
object ExampleSuite extends FunSuite {
test("os-lib test") {
val path: os.Path = ???
@majk-p
majk-p / .scalafmt.conf
Last active September 11, 2024 10:58 — forked from kubukoz/.scalafmt.conf
How to disable significant indentation in Scala
runner.dialect = scala3
runner.dialectOverride.allowSignificantIndentation = false
# allows `if x then y`
runner.dialectOverride.allowQuietSyntax = true
fileOverride {
"glob:**/*.sbt" {
runner.dialect = scala213
# disable `if x then y` as it uses scala 2 syntax
runner.dialectOverride.allowQuietSyntax = false
}
@majk-p
majk-p / main.scala
Last active August 27, 2024 13:44
Extract field values form scalacheck seed
//> using dep "org.scalacheck::scalacheck:1.18.0"
import org.scalacheck.rng.Seed
@main
def main(base64Seed: String) = {
val seed: Seed =
Seed
.fromBase64(base64Seed)
.toOption
.get