Skip to content

Instantly share code, notes, and snippets.

@erantapaa
erantapaa / schemers-monads.hs
Created May 27, 2015 15:50
Haskell version of "A Schemer's View of Monads"
module Foo where
-- This is a translation to Haskell of parts of the paper
-- "A Schemer's View of Monads" by Adam C. Foltzer & Daniel P. Friedman:
--
-- https://cgi.soic.indiana.edu/~c311/lib/exe/fetch.php?media=manymonads.pdf
import Control.Monad.State
-- `Tree a` is a way of describing only those S-exps which are trees
@erantapaa
erantapaa / hse-pprint.hs
Created May 28, 2015 05:17
pretty print the AST generated by Language.Haskell.Exts
{- Simple pretty printer for the AST created by Language.Haskell.Exts.
-
- Usage: program source.hs
-
-}
import qualified Language.Haskell.Exts as E
import Language.Haskell.Exts.Parser (ParseResult(..))
import Data.List
import System.Environment
@erantapaa
erantapaa / build-notes.md
Last active August 29, 2015 14:22
haskell.org site build notes

Some notes on building hl (the haskell.org website) on an Unbuntu box.

  1. Follow the instructions at https://www.stackage.org/install#ubuntu to install the GHC tool chain.

  2. Install the following packages:

    sudo apt-get install -y libicu-dev

  3. Run:

@erantapaa
erantapaa / annotate
Last active August 29, 2015 14:22
annotate - annotate output with time elapsed
#!/usr/bin/perl
use POSIX qw(strftime);
$| = 1;
sub annotate_handle {
my ($handle) = @_;
my $start = time();
while (<$handle>) {
@erantapaa
erantapaa / start-light
Created June 17, 2015 07:41
start a static web server with lighttpd
#!/usr/bin/env python
#
# Provision a static lighttpd server in $HOME/.lighttpd/config-<port>
import os
import re
import sys
from os.path import expanduser
CONF_TEMPLATE='''
@erantapaa
erantapaa / gist:4fe5baf90ba58bd0bcc5
Created July 2, 2015 06:18
Auto derive aeson ToJSON instance
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module Lib
where
import Data.Aeson
import GHC.Generics (Generic)
import Data.Stringable
@erantapaa
erantapaa / rahkana-example.hs
Last active August 29, 2015 14:27
pipes server-client example
-- Example of using the Rakhana libraries.
-# LANGUAGE NoMonomorphismRestriction #-}
module Foo
where
import Data.Rakhana
import Control.Monad.Trans (liftIO)
import qualified Data.ByteString.Char8 as B
@erantapaa
erantapaa / build-new-haddock.md
Last active September 8, 2015 17:36
build new haddock instructions
  1. Download and build the newest haddock. The build instructions are in README.md.

    git clone https://github.com/haskell/haddock.git cd haddock

    cabal sandbox init cabal sandbox add-source haddock-library cabal sandbox add-source haddock-api cabal install --dependencies-only

@erantapaa
erantapaa / redirect-io.hs
Created September 8, 2015 17:38
Redirect stdout for an IO action
module Misc
( withOutputTo
) where
import System.IO
import GHC.IO.Handle
import Control.Exception
-- | Run an IO action with stdout redirected to a file.
-- Restores stdout upon completion of the action.
@erantapaa
erantapaa / SplitFile.hs
Created September 8, 2015 18:00
split line oriented file into equal parts on line boundaries
module SplitFile
( splitFile, splitFileOn, splitHandle, splitHandleOn, findNext, findNewLine
) where
import System.IO
import qualified Data.ByteString.Char8 as B
splitFileOn :: (Char -> Bool) -> Int -> FilePath -> IO [Integer]
splitFileOn find parts path = do
h <- openBinaryFile path ReadMode