Skip to content

Instantly share code, notes, and snippets.

@erdeszt
erdeszt / zats.scala
Last active January 9, 2023 23:57
ZIO flavored CE error handling
package zats
import cats.effect.{IO, IOApp}
import cats.effect.std.Console
import cats.{Applicative, Functor, MonadError}
import cats.syntax.functor.*
import cats.syntax.flatMap.*
import scala.annotation.implicitNotFound
type App[F[_]] = MonadError[F, Throwable]
@erdeszt
erdeszt / SafeServiceWith.scala
Last active December 19, 2022 23:34
Safe ZIO.serviceWith
trait ZIO[-R, +E, +A] {
}
object ZIO {
def serviceWithZIO[S]: SWZIOP[S] = new SWZIOP[S]
def serviceWith[S]: SWP[S] = new SWP[S]
@erdeszt
erdeszt / editAgreement.dot
Last active November 25, 2022 09:42
graph
digraph {
editAgreement [shape=box];
addCoInsureeToAgreement [fillcolor=aquamarine, style=filled];
updateRelatedUser [fillcolor=aquamarine, style=filled];
addAgreementCoInsuree [fillcolor=aquamarine, style=filled];
updateAgreementCoInsuree [fillcolor=aquamarine, style=filled];
@erdeszt
erdeszt / RichNewtypeScala3.scala
Last active November 14, 2022 21:31
Scala 3 zio rich newtype improvements
import zio.prelude.Newtype
import cats.Contravariant
import cats.Functor
import cats.syntax.contravariant.*
import cats.syntax.functor.*
import io.circe.*
import io.circe.syntax.*
import io.circe.parser.decode
@erdeszt
erdeszt / gpio.zig
Last active March 8, 2021 15:28
Zig on AVR demo
const Direction = packed enum (u1) {
Output = 0,
Input = 1,
};
const Level = packed enum(u1) {
Low = 0,
High = 1,
};
@erdeszt
erdeszt / Invariant.idr
Last active December 15, 2020 22:27
Idris datatype invariant
module Main
import Data.String
data CorrectSize : Nat -> Nat -> Nat -> Type where
SmallerThan150 : (x : Nat) -> (y : Nat) -> (z : Nat) -> {auto prf : x + y + z <= 150 = True} -> CorrectSize x y z
Show (CorrectSize x y z) where
show (SmallerThan150 x y z) = "CorrectSize " ++ show (x, y, z)
showPrec _ size = show size
@erdeszt
erdeszt / Intro.v
Last active June 6, 2020 14:48
Coq intro
Module Datatypes.
Inductive bool : Type := true | false.
(* Scala:
sealed trait Bool
case class True() extends Bool
case class False() extends Bool
*)
@erdeszt
erdeszt / etest.h
Created February 8, 2020 16:02
Single header C test framework
#ifndef _E_TEST_H_
#define _E_TEST_H_
#include <stdint.h>
#include <stdio.h>
#define TEST(suite, name) \
if (_etest_is_test_included_in_run(#suite, #name, test_context)) { \
_etest_register_running_test(#suite, #name, test_context); \
} \
@erdeszt
erdeszt / GDP.scala
Last active April 15, 2019 09:02
Ghosts of departed proofs in scala (https://github.com/matt-noonan/gdp-paper/releases)
trait Coercible[A, B] {
def coerce(a: A): B
}
def coerce[A, B](a: A)(implicit coerceAB: Coercible[A, B]): B = {
coerceAB.coerce(a)
}
trait Newtype[+T] {
val value: T
@erdeszt
erdeszt / IndexedResourceT.hs
Last active May 10, 2018 20:11
Indexed ResourceT monad (repl.it link: https://repl.it/repls/EsteemedDeficientArea)
{-# LANGUAGE KindSignatures
, PolyKinds
, DataKinds
, TypeFamilies
, TypeOperators
, GADTs
#-}
module IxResourceT where