Skip to content

Instantly share code, notes, and snippets.

@erantapaa
erantapaa / gnuplot-example.hs
Created September 17, 2015 23:29
using Graphics.Gnuplot.Simple
module Lib
where
import Graphics.Gnuplot.Simple
import qualified Graphics.Gnuplot.Terminal.SVG as SVG
foo = do
let zs = [ (x,x) | x <- [1..10] ]
plotList [Key Nothing
,YRange (0,maximum (map snd zs) + 1)
@erantapaa
erantapaa / parser-ghc-7.10.hs
Created September 8, 2015 20:24
Parser Combinators by Hutton and Meijer
-- Updated for GHC 7.10
{---------------------------------------------------------------------
A HASKELL LIBRARY OF MONADIC PARSER COMBINATORS
17th April 1997
Graham Hutton Erik Meijer
University of Nottingham University of Utrecht
@erantapaa
erantapaa / 0_reuse_code.js
Last active September 8, 2015 18:02
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@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
@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 / 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 / setup-tuf.sh
Created August 27, 2015 15:27
Setting up keys for a new hsackage-server
#!/bin/sh
#
# Script to populate a TUF directory with a new set of private keys.
#
# Note: Need to install the hackage-repo-tool package from Hackage.
REPO_TOOL=hackage-repo-tool
KEYS_DIR=/tmp/keys
DATA_DIR=./datafiles
@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 / 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 / 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='''