Skip to content

Instantly share code, notes, and snippets.

{ lib }:
# this exposes a function, which is exported from lib/default.nix as toTOML,
# from attrset to string. It transforms a nix attribute set into the TOML
# format.
with lib;
let
tomlEscape = escape [ "\b" "\t" "\n" "\f" "\r" "\"" "\\" ];
@Taneb
Taneb / Sat.hs
Created January 15, 2020 14:58
Basic SAT solver
module Sat where
-- A variable, e.g. p, q, r...
type Var = Int
-- A parity, either False (¬) or True (not ¬)
type Parity = Bool
-- A literal, e.g. ¬p, q, ¬r
type Literal = (Int, Bool)
-- A sequence of literals, which are combined by ||
type Clause = [Literal]
@Taneb
Taneb / Aligned.hs
Created December 28, 2019 20:53
Attempt at type-aligned finger trees
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
module FingerTree.Aligned where
import Control.Category
import Prelude hiding ((.), id)
import qualified Aligned.Internal as A
@Taneb
Taneb / Main.hs
Created November 25, 2019 09:49
Simple image viewer in Haskell
module Main where
import qualified Data.ByteString.Char8 as B -- bad
import qualified Graphics.UI.Gtk as Gtk
import System.Environment
import qualified System.GIO as GIO
updateImage :: Gtk.ImageClass o => o -> Maybe GIO.File -> Maybe GIO.File -> GIO.FileMonitorEvent -> IO ()
updateImage image (Just file) _ GIO.FileMonitorEventChanged = do
pixbuf <- Gtk.pixbufNewFromFile . B.unpack $ GIO.filePath file
@Taneb
Taneb / bf.jq
Created July 9, 2019 10:39
brainfuck interpreter in jq
# invoke as jq -f bf.jq -rS --arg program [PROGRAM] -
# interactivity is not supported
# try:
# $ echo "" | jq -f bf.jq -RrS --arg program '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'
def increment: .tape.head+=1;
def decrement: .tape.head-=1;
def shiftleft:
.tape.left=[.tape.head]+.tape.left |
@Taneb
Taneb / Group.hs
Created July 6, 2019 09:46
Union find with groups! (completely untested)
module Data.UnionFind.Group where
import Control.Monad
import Control.Monad.Primitive
import Data.Group
import Data.Primitive
data UFG' m g = UFG'
{ operator :: g
, root :: UFG m g
@Taneb
Taneb / NixRSS.hs
Created March 28, 2019 19:06
Generate RSS feed from list of Git references and timestamps
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}
module Main where
import Data.Maybe
import Data.Time.Clock
import Data.Time.Clock.POSIX
import Network.URI
import Text.RSS
@Taneb
Taneb / Bogosort.hs
Created February 24, 2019 00:02
Bogosort and Bogobogosort in Haskell
module Bogosort where
import Control.Monad.Primitive
import Control.Monad.ST
import Control.Monad.ST.Unsafe
import Control.Monad.Trans.State.Strict
import Data.Monoid
import qualified Data.Vector as V
import qualified Data.Vector.Generic.Mutable as VGM
import Data.Vector.Generic.Mutable (MVector)
@Taneb
Taneb / Foo.hs
Created September 26, 2018 15:33
Haddock failing example - fails on GHC 8.4.3 cabal-install 2.2.0.0 haddock 2.20.0
module Foo where
import Paths_haddock_fail (getDataDir)
{-# ANN module (const () getDataDir) #-}
@Taneb
Taneb / Cat.agda
Created September 10, 2018 19:22
Category theory in Agda!
module Cat where
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Level
record Category (o a ℓ : Level) : Set (suc (o ⊔ a ⊔ ℓ)) where
infix 4 _≈_
infixr 9 _∘_
field