Skip to content

Instantly share code, notes, and snippets.

View patrl's full-sized avatar

Patrick Elliott patrl

View GitHub Profile
@patrl
patrl / inweb.nix
Created October 7, 2023 17:26
A derivation for Graham Nelson's inweb and intest
{ pkgs ? import <nixpkgs> {} }:
pkgs.stdenv.mkDerivation {
pname = "inweb";
version = "7.2.0";
srcs = [ ./inweb-7.2.0.tar.gz ./intest-2.1.0.tar.gz ];
setSourceRoot = ''
mkdir work
mv inweb-7.2.0 ./work/inweb
mv intest-2.1.0 ./work/intest
@patrl
patrl / eds.hs
Last active June 29, 2023 10:12
Partial DS
{-# LANGUAGE OverloadedLists #-}
import Data.IntMap ((!?)) -- safe lookup
import qualified Data.IntMap as M -- data structure for assignments
import qualified Data.Set as S
import Control.Applicative
import Data.Maybe
import Control.Monad (replicateM)
newtype E = E Char deriving (Eq,Show,Ord) -- type for individuals
@patrl
patrl / cnf.hs
Created May 22, 2023 05:10
Conjunctive normal form (for seminar)
data PropL = PVar String | PNot PropL | PropL `PAnd` PropL | PropL `POr` PropL deriving Eq
instance Show PropL where
show (PVar s) = s
show (PNot p) = "~" ++ show p
show (p `PAnd` q) = "(" ++ show p ++ " & " ++ show q ++ ")"
show (p `POr` q) = "(" ++ show p ++ " | " ++ show q ++ ")"
-- recursive de Morgan's
@patrl
patrl / Xp.hs
Last active February 16, 2023 10:31
Simple program for decoding .xp files (REXPaint)
{-# LANGUAGE TemplateHaskell #-}
-- Xp format specification: https://steveasleep.com/rexpaint_manual.html#appendix-b:-.xp-format-specification-(and-import-libraries)
module Data.Xp where
import Data.Colour.RGBSpace
import qualified Codec.Compression.GZip as GZip
import qualified Data.ByteString.Lazy as BL
import Data.Binary.Get
@patrl
patrl / shadowcast.hs
Created January 17, 2023 16:17
Recursive symmetric shadowcasting by quadrant in Haskell
computeQ :: TileMap -> Transform -> Slope -> Slope -> Int -> Visible ()
computeQ m t s e y = do
let xmin = roundTiesUp (fromIntegral y * s) -- compute the initial x coordinate bounded by the starting slope
let xmax = roundTiesDown (fromIntegral y * e) -- compute the ending x coordinate bounded by the ending slope
let xys = (coord . (,y)) <$> [xmin..xmax] -- create a list of coordinates to recurse through by pairing xs with the depth
-- a helper function to recurse through a list of coordinates, and potentially create branching row computations
-- the first argument is a Maybe Bool which tracks whether the previous coordinate was a wall
-- Nothing indicates that there was no previous coordinate (we're at the beginning of the list)
-- s indicates the starting slope; this can change as the recursion proceeds.
#!/bin/sh
# exit as soon as any line in the script fails, print each command that's going to be executed
set -ex
# wipe disk
sgdisk --zap-all ${DISK}
# create GPT partition table
parted ${DISK} -- mklabel gpt
@patrl
patrl / org-gb4e.el
Created January 5, 2022 15:56
Hack to make org special blocks work with gb4e
(defun patrl/org-latex-special-block (special-block contents info)
"Transcode a SPECIAL-BLOCK element from Org to LaTeX.
CONTENTS holds the contents of the block. INFO is a plist
holding contextual information."
(let ((type (org-element-property :type special-block))
(opt (org-export-read-attribute :attr_latex special-block :options))
(caption (org-latex--caption/label-string special-block info))
(caption-above-p (org-latex--caption-above-p special-block info)))
(if
(equal (format "%s" type) "exe")
@patrl
patrl / minion.tex
Created October 4, 2021 00:01
Fontspec settings for minion
\RequirePackage{microtype}
\RequirePackage{fontspec}
\defaultfontfeatures{Scale=MatchLowercase}
\setmainfont[%
UprightFeatures={
SizeFeatures={
{Size={-8.4},Font=MinionPro-Capt},
{Size={8.4-13},Font=MinionPro-Regular},
{Size={13-19.9},Font=MinionPro-Subh},
@patrl
patrl / Final.hs
Last active January 28, 2021 14:27
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ParallelListComp #-}
{-# LANGUAGE OverloadedLists #-}
module Data.Logic.Final where
import Control.Applicative ( Applicative(liftA2) )
import Control.Monad ( replicateM )
import Data.Biapplicative ( (<<*>>)
@patrl
patrl / Update.hs
Created July 29, 2020 17:39
A GSV-style update semantics that validates double-negation elimination
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
type E = Int
type G = [Int]
newtype W = W Int deriving (Integral,Real,Enum,Num,Ord,Eq,Show)
type T = Bool