Skip to content

Instantly share code, notes, and snippets.

View arainko's full-sized avatar
🙀
TYPES

Aleksander Rainko arainko

🙀
TYPES
  • Gdańsk, Poland
View GitHub Profile
@arainko
arainko / tutorial_cs2_audio_issues_linux.md
Last active December 31, 2025 02:00
Fix CS2 audio issues on Linux (pop_os in particular)

Issue: playing CS2 and talking on Discord is impossible - the game audio cuts off after a certain time and never comes back.

Solution: Create a virtual device using some pipewire trickery and then use that virtual device as the output device in CS2.

  1. Save output of pactl list to a file (get this package installed if you don't have it)
  2. Search for Sink with State: RUNNING in the file we created in the previous point, in my case it looked like this:
Sink #52
	State: RUNNING
@arainko
arainko / ByMirror.scala
Created July 12, 2025 06:11
Access fields directly from an inline method (not via `productIterator`)
import scala.deriving.Mirror
import scala.compiletime.*
object ByMirror {
inline def fields[A: Mirror.ProductOf as A](value: A) = {
iterateOver[Tuple.Zip[A.MirroredElemTypes, A.MirroredElemLabels], A](value)
}
inline def iterateOver[Fields <: Tuple, A](value: A): List[Any] = {
inline erasedValue[Fields] match {
@arainko
arainko / Subfield.scala
Created September 8, 2024 12:27
Generate a refinement type that encompasses most of the possible paths in a transformation based on `ducktape.internal.Plan`
package io.github.arainko.ducktape
import scala.quoted.*
import internal.*
import io.github.arainko.ducktape.internal.Plan.*
sealed trait Subfield[Source, Dest] extends Selectable {
def selectDynamic(name: String): Nothing
def applyDynamic(name: String)(args: Any*): Nothing
trait Mode[F[+x]] {
def pure[A](value: A): F[A]
def zip[A, B](fa: F[A], fb: F[B]): F[(A, B)]
}
object Mode {
type Unechecked[F[_], +A] = FreeApplicative[F, A @uncheckedVariance]
def mode[AA]: Mode[Unechecked[Codec.Field[AA, _], _]] = new:
def pure[A](value: A): Unechecked[Codec.Field[AA, _], A] =
FreeApplicative.pure(value)
@arainko
arainko / FieldName.scala
Created April 20, 2024 23:14
How to pattern match on a function expression in a Scala 3 macro
trait FieldName {
def uppercase: FieldName
def lowercase: FieldName
}
object FieldName {
// prints 'lowercase, uppercase, uppercase, uppercase'
FunctionExpressionMatching
.printOutUsedMethods(_.lowercase.uppercase.uppercase.uppercase)
@arainko
arainko / grouper.scala
Created November 11, 2023 08:25
Partitioning a List of coproducts into a tuple of its children
//> using scala 3.3.1
import scala.deriving.*
import scala.compiletime.*
import scala.collection.Factory
import scala.collection.mutable.Builder
enum Whatever {
case Str(str: String)
case Number(int: Int)
@arainko
arainko / AST.scala
Last active March 25, 2023 14:43
astformatter
enum AST {
case Node(name: String, span: Span, values: Vector[AST])
case Singleton(name: String)
case Text(value: String)
case Number(value: String)
lazy val length: Int =
this match {
case AST.Node(name, span, _) =>
name.length + span.length + 2
@arainko
arainko / resolve_companion.scala
Last active April 5, 2022 16:22
Scala 3 macros
import scala.quoted.*
// Given a type A resolves its companion which can then be spliced back
def resolveCompanion[A: Type](using Quotes) = {
import quotes.reflect.*
TypeRepr.of[A] match {
case TypeRef(a, b) => Ident(TermRef(a, b))
}
}