Skip to content

Instantly share code, notes, and snippets.

//> using scala 3.3.1
//> using dep org.typelevel::cats-parse:1.0.0
//> using dep org.typelevel::kittens:3.1.0
import cats.parse.Rfc5234.*
import cats.parse.{Parser, Parser0, Numbers}
import cats.Monoid
import cats.syntax.all.*
import cats.derived.*
case class Cubes(blue: Int, red: Int, green: Int) derives Monoid:
@mpilquist
mpilquist / Example.scala
Created April 9, 2023 13:24
Example of twiddle lists that work on Scala 2 (via aliases to shapeless HLists) and Scala 3 (using built-in tuples)
package examples
import org.typelevel.twiddles._
import cats.Applicative
object Example {
trait Json
trait Decoder[A] {
def decode(s: Json): Option[A]
@mpilquist
mpilquist / CheckerAsserting2.scala
Created March 17, 2023 00:32
Example of integrating scalacheck-effect and scalatest
/*
* Copyright 2001-2013 Artima, Inc.
*
* 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
*
* Unless required by applicable law or agreed to in writing, software
@mpilquist
mpilquist / rom.sc
Created December 6, 2022 03:57
LED flasher from Ben Eater's 6502 part 2 video
//> using scala "3.2.1"
//> using lib "org.scodec::scodec-bits:1.1.34"
//> using lib "co.fs2::fs2-io:3.4.0"
import scodec.bits.*
import cats.effect.IO
import cats.effect.unsafe.implicits.global
import fs2.{Stream, Chunk}
import fs2.io.file.{Files, Path}
➜ ~/.ivy2/local/com.indoorvivants/bindgen_native0.4_3/0.0.10+3-e5a1879b-SNAPSHOT/jars/bindgen_native0.4_3-osx-x86_64.jar --header /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/pcap.h --clang-include "/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include" --package pcap --scala --info > pcap.scala
[bindgen] info Using following clang flags: List(-I/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include)
[bindgen] warn clang: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)
[bindgen] warn clang: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)
[bindgen] warn clang: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)
[bindgen] warn clang: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)
[bindgen] warn clang: warning: pointer is missing a nullability type specifie
//> using scala "3.1.2"
//> using lib "co.fs2::fs2-io:3.2.11"
//> using lib "co.fs2::fs2-protocols:3.2.11"
//> using lib "com.monovore::decline::2.2.0"
import cats.data.NonEmptyList
import cats.effect.{ExitCode, IO, IOApp}
import cats.syntax.all.*
import com.comcast.ip4s.*
import com.monovore.decline.*
@mpilquist
mpilquist / veryfreemonads.scala
Created January 17, 2022 19:39
Demonstrates free monad composition using Scala 3 union types and a Free monad that's covariant in its effect
// using scala 3.1.1-RC2
trait Monad[F[_]]:
def unit[A](a: => A): F[A]
extension [A](fa: F[A])
def flatMap[B](f: A => F[B]): F[B]
def map[B](f: A => B): F[B] =
flatMap(a => unit(f(a)))
object Monad:
given function0Monad: Monad[Function0] with
// using scala 3.1.0
import scala.deriving.Mirror
object Mirrors:
extension [A <: Product](a: A)(using m: Mirror.ProductOf[A])
def toTuple: m.MirroredElemTypes = Tuple.fromProductTyped(a)
extension [T <: Tuple](t: T)
/*
* Copyright 2020 Daniel Spiewak
*
* 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
*
* Unless required by applicable law or agreed to in writing, software
sbt:root> release
[info] Starting release process off commit: 6b15fef26819736b722c1e46e26ef7347062f094
[info] Checking remote [origin] ...
[info] Setting scala version to 2.11.12
[info] set current project to root (in build file:/Users/MPilqu0037e/Development/oss/scodec-bits/)
[info] Setting scala version to 2.12.11
[info] set current project to root (in build file:/Users/MPilqu0037e/Development/oss/scodec-bits/)
[info] Setting scala version to 2.13.2
[info] set current project to root (in build file:/Users/MPilqu0037e/Development/oss/scodec-bits/)
[info] Setting scala version to 0.26.0-RC1