Skip to content

Instantly share code, notes, and snippets.

View spamegg1's full-sized avatar
:octocat:
perpetually dissatisfied

spamegg spamegg1

:octocat:
perpetually dissatisfied
View GitHub Profile
@ghostdogpr
ghostdogpr / Derivation.scala
Last active February 8, 2025 08:46
Sum Type Derivation
import scala.annotation.nowarn
import scala.deriving.Mirror
trait TC[A] {
def show(a: A): Unit
}
@nowarn
inline def gen[A](using m: Mirror.SumOf[A]): TC[A] = {
val subTypes = compiletime.summonAll[Tuple.Map[m.MirroredElemTypes, TC]]
@keynmol
keynmol / clay-glue.c
Created January 1, 2025 13:55
Scala Native bindings for Clay - https://github.com/nicbarker/clay
#include <string.h>
void __sn_wrap_clay_Clay_CreateArenaWithCapacityAndMemory(uint32_t capacity, void * offset, Clay_Arena *____return) {
Clay_Arena ____ret = Clay_CreateArenaWithCapacityAndMemory(capacity, offset);
memcpy(____return, &____ret, sizeof(Clay_Arena));
}
void __sn_wrap_clay_Clay_EndLayout(Clay_RenderCommandArray *____return) {
Clay_RenderCommandArray ____ret = Clay_EndLayout();
@bench87
bench87 / scalaMetaprogramming.scala
Created September 22, 2024 07:55
Inline your boilerplate – harnessing Scala 3 metaprogramming without macros
//> using scala "3"
import scala.compiletime.{erasedValue, summonInline, constValue, error}
import scala.deriving.Mirror
import scala.collection.Factory
import scala.annotation.implicitNotFound
import scala.util.NotGiven
import Field.TypeForLabel
infix type =:!=[A, B] = NotGiven[A =:= B]
@johnhungerford
johnhungerford / dependency-injection.md
Last active February 22, 2025 18:15
ZIO-like dependency injection using implicit resolution

ZIO-like dependency injection using implicit resolution

Daniel Ciocîrlan recently published a video showcasing a dependency-injection (DI) approach developed by Martin Odersky that uses Scala's implicit resolution to wire dependencies automatically. (See also his reddit post.)

The basic pattern for defining services in Odersky's approach is as follows:

class Service(using Provider[(Dep1, Dep2, Dep3)])
@kubukoz
kubukoz / .scalafmt.conf
Last active June 29, 2025 16:32
How to disable significant indentation in Scala
runner.dialect = scala3
runner.dialectOverride.allowSignificantIndentation = false
# allows `if x then y`
runner.dialectOverride.allowQuietSyntax = true
@tanishiking
tanishiking / bench.md
Last active July 26, 2024 05:49
Scala.js wasm backend benchmark
wasm js wasm / js
sha512 12368.78034 69356.554 0.1783361431
sha512int 12078.89027 18342.09272 0.6585339229
queens 3.299606497 9.262363477 0.3562380709
list 76.06484363 142.8739845 0.5323911412
richards 92.35085892 130.1592505 0.7095220552
cd 40129.51947 62085.45494 0.6463594332
gcbench 111415.1666 135005.6104 0.8252632331
tracerFloat 1048.518644 1280.901067 0.8185789445
@MatthewGlenn
MatthewGlenn / CombineVideosWithFFmpegAndPython.md
Last active March 8, 2025 13:41
Combine all videos in a folder using ffmpeg and python

Combine Videos with FFmpeg and Python

This script allows you to combine multiple videos into a single video using FFmpeg and Python.

Dependencies

  • Python
  • FFmpeg

Optional Enhancement

@kyouko-taiga
kyouko-taiga / main.md
Last active February 13, 2025 22:06
Generic programming with type classes

Generic programming with type classes

Generic programming is a discipline that encourages the construction of abstractions and the reuse of software component without loss of efficiency. Subtyping through inheritance can be adversary to this goal because it encourages type erasure, promising that efficiency is maintained thanks to dynamic dispatch. Sadly, this promise gets broken when generic data structures and algorithms depend on more than one generic receiver. In those instances, one must resort to generic parameters to preserve type information, introducing expensive annotation costs. This short article examine this problem and then discusses how type classes, an alternative approach to practice generic programming, can address many of the issues presented by subtyping through inheritance.

Disclaimer:

@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]
@arturaz
arturaz / Bounds1.scala
Created October 10, 2022 18:25
Code for "Scala =:= and implicits demystified " video (https://www.youtube.com/watch?v=4jrHAmKx7YE)
package app.implicit_constraints
object Bounds1 {
case class Container[A](a: A)
implicit class IntContainerExtensions(container: Container[Int]) {
def addWithExtension(other: Int): Int = container.a + other
}
val intContainer: Container[Int] = Container(5)