Skip to content

Instantly share code, notes, and snippets.

View evanrelf's full-sized avatar

Evan Relf evanrelf

View GitHub Profile
@evanrelf
evanrelf / Makefile
Last active February 3, 2021 00:41
Generic Makefile for C++ assignments at Saddleback College
# USER SETTINGS
production = false
dir = .make-work
CXX = @clang++
CXXFLAGS = -std=c++17 -Wall
ifeq ($(PRODUCTION),true)
CXXFLAGS += -Werror -O3
else
CXXFLAGS += -g -O0
endif
@evanrelf
evanrelf / record-dot-syntax.cabal
Created April 4, 2020 01:16
How to try `RecordDotSyntax` with Neil Mitchell's preprocessor/plugin https://github.com/ndmitchell/record-dot-preprocessor
common record-dot-syntax-preprocessor
build-depends: record-dot-preprocessor, record-hasfield
ghc-options: -F -pgmF=record-dot-preprocessor
common record-dot-syntax-plugin
build-depends: record-dot-preprocessor, record-hasfield
default-extensions:
DataKinds
DuplicateRecordFields
FlexibleContexts
@evanrelf
evanrelf / main.hs
Last active February 3, 2021 00:38
Contrived example of `concurrency` and `polysemy` libraries
#!/usr/bin/env nix-shell
#!nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (p: with p; [ concurrency dejafu polysemy polysemy-plugin ])" -I https://github.com/nixos/nixpkgs/archive/a7ceb2536ab11973c59750c4c48994e3064a75fa.tar.gz
{-# OPTIONS_GHC -fplugin=Polysemy.Plugin #-}
{-# OPTIONS_GHC -Wall -Werror #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeApplications #-}
@evanrelf
evanrelf / README.md
Last active October 9, 2023 20:45
Install NixOS on ZFS With Opt-In State

Install NixOS on ZFS With Opt-In State

Commands

# nvme0n1
# ├─nvme0n1p1    BOOT
# └─nvme0n1p2    LUKS CONTAINER
#   └─cryptroot  LUKS MAPPER
#     └─vg-swap  SWAP
-- Error message with scoping annotation
newtype Error (s :: k) = Error Text
deriving newtype IsString
-- Explicitly opt-in to bubbling up unhandled errors
rethrowError
:: Functor f
=> ExceptT (Error s1) f a
-> ExceptT (Error s2) f a
rethrowError = Except.withExceptT coerce
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Aeson.StripPrefix (StripPrefix (..)) where
@evanrelf
evanrelf / effects-with-free.hs
Last active March 10, 2021 22:30
Building a toy effect system with the free monad. And then doing the same thing but with the freer monad, which provides some advantages when writing effect data types.
#!/usr/bin/env nix-shell
#!nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [])"
#!nix-shell -i "ghci"
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
module Smoosh
( Smoosh (..)
)
where
import Control.Monad (join)
@evanrelf
evanrelf / ifd.nix
Created June 18, 2021 20:20
Simple example of "import from derivation" in Nix
{ expr }:
let
pkgs = import <nixpkgs> { };
drv =
pkgs.runCommand "script" { } ''
echo 'Building during evaluation to generate a Nix expression!'
${pkgs.cowsay}/bin/cowsay '${expr}'
echo '${expr}' > $out
module Main where
import Prelude hiding (show)
import Prelude as Prelude
import Data.Foldable (fold)
import Effect (Effect)
import TryPureScript (p, text, render)