Skip to content

Instantly share code, notes, and snippets.

View arosien's full-sized avatar

Adam Rosien arosien

View GitHub Profile
@arosien
arosien / logback.xml
Last active January 9, 2024 19:40
scala-cli script to show inserting an otel4s span into a log4cats logger
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="CONSOLE"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%X{traceId} %X{spanId} - %m%n</Pattern>
</layout>
</appender>
//> using scala 2
//> using toolkit typelevel:latest
// https://practicalocaml.com/how-to-build-type-safe-state-machines-using-type-state/
// type 'state fsm = { state: 'state }
case class Fsm[State](state: State)
/*
type id
@arosien
arosien / daffodil-1.3.1-external-jar-schema-breakpoint.md
Created August 31, 2023 04:10
Daffodil extension v.1.3.1 external jar schema breakpoint
  • I set a breakpoint in pcap.dfdl.xsd on line 168 (first use of the Ethernet element).
  • I start the debug session. This pauses at the beginning of the parse, and I hit "Continue" which then breaks on line 168 (Ethernet element).
  • I open the ethernetIP.dfdl.xsd file via normal VSCode File->Open commands. I add a breakpoint to line 68 (declaration of MACDest element).
  • I press "Continue" and the ethernet breakpoint is hit.
  • If I click on the Call Stack where MACDest is at the top of the stack, a different view of MACDest is shown: it is from within the ethernetIP jar file. I suspect this is from a plugin I have installed locally (https://marketplace.visualstudio.com/items?itemName=wmanth.jar-viewer ?), but I'm not sure and would need external validation for.

I am surprised that the separately-opened xsd breakpoint is correctly mapped, but it seems to work for me.

import cats.Applicative
import cats.arrow.Arrow
import cats.implicits._
/**
Theorem 1.1 (Cayley representation for (Set) monoids)
Every monoid (M,⊕,e) is a sub-monoid of the monoid of endomorphisms on M.
Notions of Computation as Monoids
EXEQUIEL RIVAS, MAURO JASKELIOFF
Tag Implication Expectation
(no tag specified) Free form, interpret it as you will. Context dependent.
Bug Reviewer is concerned that the code in question could cause problems in production. Reviewer’s expectation is that the bug will be acknowledged, corrected or explained in some form.
Question Reviewer has general questions that may warrant addressing before a merge. Reviewer’s expectation is that the question will be acked or answered in some form.
Concern This is something to consider an important issue and a response would be appreciated. Reviewer’s expectation is that there will be a response most of the time.
Suggestion Reviewer thinks code could be improved, but change is not necessary. Reviewer expects submitter to consider if change is desirable/worthwhile and respond appropriately.
Nit This is a weakly held opinion, I'm putting it out there, but if you ignore it, no big deal. Reviewer has no expectatio
@arosien
arosien / SafePassword.scala
Last active September 6, 2020 22:16
Variation of https://alexn.org/snippets/2020/08/27/safe-password.scala.html using cats-effect concurrency primitives.
final case class PasswordValue(value: String) {
override def toString = "PasswordValue(****)"
}
object SafePassword {
def resource[F[_]: Sync](value: String): F[Resource[F, PasswordValue]] =
for {
used <- Ref.of[F, Boolean](false)
chars = value.toCharArray
givePasswordAndNullify = Sync[F].delay {
import cats._
import cats.implicits._
import cats.effect.IO
import scala.io.StdIn
// Port of https://gist.github.com/danidiaz/112c5de83dc9c9b2ece1bf4d3581da24 to Scala
/** An algebraic data type for expressions to add and multiply integers. */
sealed trait Exp
@arosien
arosien / withOut.scala
Last active May 21, 2020 18:37
Console.withOut
import cats.effect.IO
import java.io.ByteArrayOutputStream
val out = new ByteArrayOutputStream
val cookies = IO(println("cookies"))
Console.withOut(out) { cookies.unsafeRunSync() }
out.toString // "cookies\n"
@arosien
arosien / 20200519.md
Last active May 20, 2020 18:20
"Functional Programming Demystification" @ Scala at the Sea, 19 May 2020

Functional Programming Demystification

Functional programming is full of Fancy Words™. Let's collect a list of them to demystify together. Adam will facilitate with live-coding, and will also try to make good jokes.

Here's some terms to bootstrap us: effect, free monad, functor, property-based testing, refinement type, stream, etc. >

case class RoseF[V, A](root: V, children: List[A])
object RoseF {
type Fixed[V] = Fix[RoseF[V, ?]]
implicit def traverse[V]: Traverse[RoseF[V, ?]] =
new DefaultTraverse[RoseF[V, ?]] {
def traverse[G[_]: Applicative, A, B](
fa: RoseF[V, A]
)(f: A => G[B]): G[RoseF[V, B]] =