Skip to content

Instantly share code, notes, and snippets.

@coltfred
coltfred / load_env.ps1
Created September 11, 2023 20:16
Load env files on windows in powershell.
$ori = @{}
Try {
$i = 0
# Loading .env files
if(Test-Path $args[0]) {
foreach($line in (Get-Content $args[0])) {
if($line -Match '^\s*$' -Or $line -Match '^#') {
continue
}
{
"keymap": [
{
"keyCode": 65535,
"label": "",
"verbose": "Transparent"
},
{
"keyCode": 30,
"label": "1"
@coltfred
coltfred / gist:3dcb07aa4a7133019f8667958afe3c7a
Created October 5, 2019 20:47
Exceptions in tests when upgrading > Java 8
WARNING: HK2 service reification failed for [org.glassfish.jersey.message.internal.DataSourceProvider] with an exception:
MultiException stack 1 of 2
java.lang.NoClassDefFoundError: javax/activation/DataSource
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3137)
at java.base/java.lang.Class.getDeclaredConstructors(Class.java:2357)

Revisiting Tagless Final Interpreters

Tageless Final interpreters are an alternative to the traditional Algebraic Data Type (and generalized ADT) based implementation of the interpreter pattern. This document presents the Tageless Final approach with Scala, and shows how Dotty with it's recently added implicits functions makes the approach even more appealing. All examples are direct translations of their Haskell version presented in the Typed Tagless Final Interpreters: Lecture Notes (section 2).

The interpreter pattern has recently received a lot of attention in the Scala community. A lot of efforts have been invested in trying to address the biggest shortcomings of ADT/GADT based solutions: extensibility. One can first look at cats' Inject typeclass for an implementation of [Data Type à la Carte](http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesA

-- The meta-circular interpreter from section 5 of Reynolds's Definitional
-- Interpreters for Higher Order Programming Languages
-- (http://www.cs.uml.edu/~giam/91.531/Textbooks/definterp.pdf)
data EXP
= CONST Const
| VAR Var
| APPL Appl
| LAMBDA Lambda
| COND Cond
@coltfred
coltfred / Advent1.hs
Created December 18, 2016 06:33
Advent1 of 2016's Advent of Code
-- Problem and flavor text is here: http://adventofcode.com/2016/day/1
module Advent1 where
import Prelude hiding(Right, Left)
import qualified Data.Set as Set
data Turn = Right Int | Left Int deriving (Eq, Show)
--east positive/west negative, south positive, north negative
newtype Position = Position { unPosition :: (Int,Int) } deriving (Eq, Show, Ord)
data Direction = North | East | South | West deriving (Eq, Show, Ord)
@coltfred
coltfred / CommsExample.scala
Created November 2, 2016 20:06 — forked from tel/CommsExample.scala
Comms example
// Given an interface like
sealed trait Mult
sealed trait One extends Mult
sealed trait ZeroOrOne extends Mult
sealed trait Many extends Mult
case class NoParam()
@coltfred
coltfred / ColtFree.scala
Created October 7, 2016 15:11
Straightforword Free Monad implementation using Xor
package com.coltfred
import cats._, cats.data._, cats.implicits._, cats.free._, cats.arrow._
case class ColtFree[F[_]: Functor, A](resume: A Xor F[ColtFree[F, A]]) {
def map[B](f: A => B): ColtFree[F, B] = resume match {
case Xor.Left(a) => ColtFree(Xor.Left(f(a)))
case Xor.Right(nested) => ColtFree(Xor.Right(nested.map(_.map(f))))
}

Keybase proof

I hereby claim:

  • I am coltfred on github.
  • I am coltfred (https://keybase.io/coltfred) on keybase.
  • I have a public key whose fingerprint is C461 3538 53FB 4AC0 9EEA 78B5 8F8C 1B8D 4E23 FC33

To claim this, I am signing this object:

package freedom
import scala.collection.JavaConverters._
import java.awt.{ Color, Graphics2D }
import java.awt.image.BufferedImage
import cats.data.{ Coproduct, Xor }
import cats.free.{ Free, Inject }