Skip to content

Instantly share code, notes, and snippets.

module BF where
data Token : Set where
Plus : Token
Minus : Token
Less : Token
More : Token
Period : Token
Comma : Token
Open : Token
warning: Nix search path entry ‘/home/nathan/.nix-defexpr/channels/nixpkgs’ does not exist, ignoring
these derivations will be built:
/nix/store/7rxarwnalkax5v5fvf1hxrnwql0y3dl9-python2.7-pytest-3.0.7.drv
/nix/store/268bwg3nylw2f0v895231msmqxrpknpl-python2.7-Babel-2.3.4.drv
/nix/store/g10lnnhpq883v5x7dhrlylqvnpy2377b-python2.7-six-1.10.0.drv
/nix/store/1d404igglldx5n0qmdr2m3ccmhz6lw3j-python2.7-unittest2-1.1.0.drv
/nix/store/cp6j75wd7wkgi16i23pls9qrdjxc0mkd-python2.7-funcsigs-1.0.2.drv
/nix/store/ji8ljdzkqsgvxw5s5kl6fz7h04pzjc68-python2.7-mock-2.0.0.drv
/nix/store/5h39f0abz2rbzm97igw8z1b14mhlhmwb-python2.7-apipkg-1.4.drv
/nix/store/x77ysrxl9m7vw7bjzj469mvm6v0xsivf-python2.7-execnet-1.4.1.drv
{-# LANGUAGE PostfixOperators #-}
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Control.Lens
import Control.Monad.State
import Prelude hiding ((++))
(++) :: (Num a, MonadState s m) => LensLike' ((,) a) s a -> m a
@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
@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 / 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 / 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 / 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 / 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 / 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