Skip to content

Instantly share code, notes, and snippets.

<!doctype html>
<!-- http://taylor.fausak.me/2015/01/27/ios-8-web-apps/ -->
<html>
<head>
<title>iOS 8 web app</title>
<!-- CONFIGURATION -->
#!/usr/bin/env sh
# https://code.claude.com/docs/en/statusline
json=$( cat )
directory=$( basename "$( printf '%s' "$json" | jq --raw-output .workspace.current_dir )" )
branch=$( git --no-optional-locks symbolic-ref --short HEAD 2>/dev/null || printf null )
model=$( printf '%s' "$json" | jq --raw-output .model.id )
@tfausak
tfausak / Main.hs
Created April 8, 2026 15:50
Benchmark for generating Core directly when deriving Generic.
#!/usr/bin/env cabal
{- cabal:
build-depends: base, directory, process
ghc-options: -Wall
-}
-- https://gitlab.haskell.org/ghc/ghc/-/issues/27130
import qualified Control.Exception as Exception
import qualified Control.Monad as Monad
#!/usr/bin/env bash
# Unified Generic deriving benchmark
# Tests compile-time (allocations + time) and runtime (to . from round-trip)
# for record types (N fields) and sum types (N constructors),
# comparing -fdirect-core-generic-deriving vs -fno-direct-core-generic-deriving.
set -euo pipefail
GHC="${GHC:-./_build/stage1/bin/ghc}"
OPT="${OPT:--O0}"
@tfausak
tfausak / invertible-syntax-descriptions.markdown
Last active September 8, 2025 19:51
Survey of invertible syntax description libraries for Haskell.

Invertible syntax descriptions

An "invertible syntax description" is something that can be used to both parse and generate a syntax. For example, instead of defining separate toJson and fromJson functions for a given data type, an invertible syntax description could be used to provide both. There are many Haskell libraries that provide this functionality or something close to it. As far as I can tell most of them are at least inspired by Invertible syntax descriptions by Tillmann Rendel and Klaus Ostermann.

Personally I am interested in using these for HTTP routing. I frequently want to be able to define a route such as /episodes/:id.json, dispatch based on that route, and generate links to that route. Doing so manually is tedious and error prone.

@tfausak
tfausak / balatro-daily-seed.hs
Created January 12, 2025 18:25
Generates a random seed for Balatro every day.
#! /usr/bin/env cabal
{- cabal:
build-depends: base, random, time
-}
import qualified Data.Time as Time
import qualified System.Random as Random
main :: IO ()
main =
putStrLn
@tfausak
tfausak / Witch.hs
Last active November 6, 2024 17:46
Deriving `From` instances using `Generically`. https://github.com/tfausak/witch/issues/107
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
@tfausak
tfausak / UUIDv7.hs
Last active August 21, 2024 14:11
UUID v7 generator in Haskell.
#! /usr/bin/env cabal
{- cabal:
build-depends:
base,
bytestring,
entropy,
tasty-bench,
time,
uuid,
ghc-options:
@tfausak
tfausak / buoy.hs
Last active May 2, 2024 19:34
keywords: Haskell applicative lift liftA liftA2 liftAN ap hoist raise boost
-- This whole thing is shamelessly stolen from:
-- <https://doisinkidney.com/snippets/nary-uncurry.html>.
-- Without flexible instances, GHC complains about the `HasApply` instances:
--
-- > Illegal instance declaration for `HasApply a Z`. All instance types must
-- > be of the form `(T a1 ... an)` where `a1 ... an` are *distinct type
-- > variables*, and each type variable appears at most once in the instance
-- > head.
--
@tfausak
tfausak / normalize-csv.hs
Last active April 2, 2024 20:16
Normalize CSV with Haskell.
#!/usr/bin/env stack
-- stack --resolver lts-8.6 --install-ghc script
import Data.ByteString
import Data.Conduit
import Data.Conduit.Binary
import Data.CSV.Conduit
import System.IO
main = transformCSV
defCSVSettings