Skip to content

Instantly share code, notes, and snippets.

@fommil
fommil / retrostart.sh
Last active July 28, 2025 14:05
RetroStart: kid-friendly gaming UX for raspberry pi 500s
#!/bin/bash
# Copyright 2025 Sam Halliday
# License BSD-3
# This allows for a kid-friendly UX to a Raspberry Pi 500 whereby you plug in a
# colour coded USB thumbdrive to start a specific game. If no drive is present
# it powers off, and a parent drive can be used to eenter the desktop.
# I bought the cheapest colour coded drives I could find at
# https://www.amazon.co.uk/dp/B074DWKG7Q but be aware that they have an
package shapely
import scala.annotation._
sealed trait Shape[A]
sealed trait CaseClass[A] extends Shape[A] { def value(i: Int): Any }
sealed trait SealedTrait[A] extends Shape[A] { def value: A ; def index: Int }
final case class CaseClass0[A]() extends CaseClass[A] { def tuple: Unit = () ; override def value(i: Int): Any = throw new IllegalArgumentException }
case object CaseClass0 { def untuple[A](): CaseClass0[A] = apply[A]() }
@fommil
fommil / mtl.md
Last active February 23, 2019 19:26
Local Capabilities with MTL

MTL is a popular approach to writing applications in Haskell. Monad constraints provide capabilities such as error handling (MonadError), writable state (MonadState), and environmental context (MonadReader). An application typically has one monad stack, implemented as a monad transformer.

However, a common problem with MTL is that the capabilities are global and the requirements of individual components may conflict. For example, an HTTP component may require a MonadError ServantError whereas a DB component may require something else. A typical workaround is to introduce a monolithic error ADT, and an unfortunate level of coupling. The problem repeats for other capabilities.

In this post, we will demonstrate a way to encode capabilities that remain local to a single component. Our example builds on the Servant Tutorial and will also show how Servant client endpoints can be mocked out for unit testing. This post is a transcript

@fommil
fommil / broken
Created June 19, 2018 07:57
X logs: keyboard not working
[ 8.219]
X.Org X Server 1.20.0
X Protocol Version 11, Revision 0
[ 8.219] Build Operating System: Linux Arch Linux
[ 8.219] Current Operating System: Linux Samurai 4.17.2-1-ARCH #1 SMP PREEMPT Sat Jun 16 11:08:59 UTC 2018 x86_64
[ 8.219] Kernel command line: initrd=\intel-ucode.img initrd=\initramfs-linux.img root=PARTUUID=dad2fe1c-e20e-4ddd-b108-08db7e7a1270 rw amdgpu.dc=0
[ 8.219] Build Date: 17 June 2018 05:28:05AM
[ 8.219]
[ 8.219] Current version of pixman: 0.34.0
[ 8.219] Before reporting problems, check http://wiki.x.org
package net.cakesolutions
import scala.util.Try
import scala.sys.process._
import sbt._
import sbt.Keys._
import com.typesafe.sbt.packager.Keys._
import com.typesafe.sbt.packager.docker._
import scalaz._
def foo(x: String \/ Int) = {
x match {
case -\/(s) => println("I'm a String")
case \/-(i) => println("I'm an Int")
case _ => println("I cannot be anything else 'cuz compiler guarantees it!")
}
}
// Copyright: 2017 Sam Halliday
// License: http://www.gnu.org/licenses/gpl.html
package scalaz
import scala.Option
import Scalaz._
sealed abstract class /~\[F[_], C[_]] {
type T
package com.example
import cats._, data._, effect._
import doobie.hikari.imports._
import doobie.imports._
import fs2.interop.cats._
import fs2.util.{ Catchable, Suspendable }
import Fragments._
package net.cakesolutions
import scala.sys.process._
import scala.util.Try
import sbt._
import sbt.Keys._
import com.typesafe.sbt.packager.Keys._
import com.typesafe.sbt.packager.docker._
val `shapeless.LabelledGeneric` = {
def `shapeless.LabelledGeneric.Aux` = scala.Predef.???
shapeless.LabelledGeneric[Bar]
}
implicit val `shapeless.LabelledGeneric.Aux`
: shapeless.LabelledGeneric.Aux[Bar, `shapeless.LabelledGeneric`.Repr] =
`shapeless.LabelledGeneric`
....