Skip to content

Instantly share code, notes, and snippets.

View barrucadu's full-sized avatar

Michael Walker barrucadu

View GitHub Profile
@barrucadu
barrucadu / CSVParser.hs
Created May 27, 2013 17:44
A gentle introduction to parsec (in particular, applicative parsec), by constructing a parser for CSV files http://blog.barrucadu.co.uk/2013/05/27/a-gentle-introduction-to-parsec/
-- Example code for a CSV file parser using Parsec. Some parts are
-- repeated, with differing functionality. To avoid name conflicts,
-- comment out the versions you don't want to play with.
module CSVParser (parseCSV, parseCSV') where
import Control.Applicative ((<$), (<*), (*>), liftA)
import Data.Char (chr)
import Data.Either (either)
import Text.Parsec
@barrucadu
barrucadu / nginx.conf
Created June 14, 2013 12:51
Flexible nginx config Read "vhosts-aur.conf" and "vhosts-lists.conf" as "vhosts/aur.conf" and "vhosts/lists.conf", I can't have subdirectories in a gist.
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
@barrucadu
barrucadu / output
Last active December 22, 2015 02:18
Spirit: Like Djinn, but different.
id :: TVar 1 :-> TVar 1
\a -> a
const :: TVar 1 :-> (TVar 2 :-> TVar 1)
\a -> \b -> a
fst :: TVar 1 :.: TVar 2 :-> TVar 1
\a@(b,c) -> b
snd :: TVar 1 :.: TVar 2 :-> TVar 2
"""Markov Chain.
Pass input to stdin.
Usage:
markov <len> [-n <n>] [-p <p>] [-c] [-s <s>]
markov -h | --help
Options:
<len> The length (in tokens) of the output to generate
@barrucadu
barrucadu / stack.ll
Created January 13, 2014 12:00
Stack implementation in LLVM IR
; The stack pointer is going to be an index into the stack, and the
; stack is an array of words. The alternative would be to have the
; stack pointer me a pointer to memory, but this is perhaps a bit
; nicer, as where the stack actually lives is totally irrelevant.
@stack = global [1000 x i64] undef
@sp = global i64 undef;
; Now we have the basic stack operations: push, pop, and peek. As can
; be seen from the definitions, LLVM is typed, which is really nice as
-- Initial 179e.cabal generated by cabal init. For further documentation,
-- see http://haskell.org/cabal/users-guide/
name: 179e
version: 0.1.0.0
-- synopsis:
-- description:
homepage: http://www.reddit.com/r/dailyprogrammer/comments/2ftcb8/9082014_challenge_179_easy_you_make_me_happy_when/
-- license:
license-file: LICENSE
#!/bin/zsh
export PATH="/home/barrucadu/.cabal/bin:$PATH"
export LANG=en_GB.UTF-8
export LC_ALL=en_GB.UTF-8
export LC_CTYPE=en_GB.UTF-8
WEBDIR=/srv/http/barrucadu.co.uk/.build
export GIT_WORK_TREE=$WEBDIR
----------------------------------------------------
-- The 'Find' monad
-- | A 'Find' computation of type represents a search problem which may result in an 'a' (or nothing at all) operating in a monad 'm'. The contract is that if there are any 'a's which could be returned, then one must be.
newtype Find m a = Find { unFind :: m (Maybe a) }
instance MonadConc m => Functor (Find m) where
fmap f (Find ma) = Find $ fmap (fmap f) ma
instance MonadConc m => Applicative (Find m) where
@barrucadu
barrucadu / results_table_all.tex
Created February 18, 2015 19:30
GP2 benchmark results on office machine
Acyclicity test
& 2x2 grid & 6 & 1 & 0 & 4 & $<0.01$ & &
& 3x3 grid & 19770 & 1 & 0 & 12 & 7.58 & &
& 4x4 grid & - & - & - & - & $>5m$ & & - & - \\
& cyclic 1000 & 0 & 0 & 1000 & 0 & 1.38 & &
& cyclic 100 & 0 & 0 & 100 & 0 & 0.03 & &
& cyclic 500 & 0 & 0 & 500 & 0 & 0.36 & &
\hline
Rooted 2 colouring
& 2x2 grid & 0 & 0 & 0 & 0 & $<0.01$ & &
module Main where
import Control.Applicative
import Control.Concurrent.Find
import Control.DeepSeq
import Data.List
import Debug.Trace
data BinTree = Leaf | Branch Int BinTree BinTree deriving Eq