Skip to content

Instantly share code, notes, and snippets.

@erantapaa
erantapaa / Timed.hs
Last active April 14, 2024 15:31
non-blocking I/O examples in Haskell
import System.Environment
import System.Timeout (timeout)
import Control.Concurrent
import Control.Concurrent (forkIO, threadDelay, killThread)
import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar)
import System.Process
import System.IO
-- blocking IO
@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 / rubiks-cube.hs
Last active July 9, 2022 19:32
Rubik's Cube Daily Programmer Challenges
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE ViewPatterns #-}
import Control.Monad
import Data.Array.IO
import Data.List.Split (chunksOf)
type Point = (Int,Int,Int)
-- basic rotations
@erantapaa
erantapaa / bibparse.py
Last active October 14, 2021 20:44
BibTeX file parsing Python
#
# Simple BibTeX file parsing in python.
#
# See `bibtest1` for an example of usage.
#
# This is a good overview of how to correctly parse a bibtex file:
#
# http://maverick.inria.fr/~Xavier.Decoret/resources/xdkbibtex/bibtex_summary.html
import string
@erantapaa
erantapaa / enigma.lhs
Last active May 10, 2021 15:04
enigma in Haskell
Emulating an Enigma machine
===
In this gist I'll go over the development of an Enigma machine encoder
in Haskell.
Here are some useful background info about how the Enigma machine works:
- Enigma Simulator: http://enigmaco.de/enigma/enigma.html
- "How Enigma Machines Work" http://enigma.louisedade.co.uk/howitworks.html
@erantapaa
erantapaa / NOTES.md
Last active September 29, 2020 23:31
building cgit on OS X
brew install gettext

git clone git://git.zx2c4.com/cgit
cd cgit
git submodule init
git submodule update

Then modify the definitions of CFLAGS and LDFLAGS in git/Makefile:

@erantapaa
erantapaa / nested.x
Created January 26, 2015 02:09
alex nested comment example
{
module Nested where
import Control.Monad
}
%wrapper "monadUserState"
$whitespace = [\ \t\b]
$digit = 0-9 -- digits
@erantapaa
erantapaa / bonus 1 solution
Last active December 3, 2019 02:29
Daily Programmer 2017-09-22 Solution
iniital board:
1 3 2 5 4 2 2 3
1 12345678 .....6.. 12345678 12345678 ....5... 12345678 1....... 12345678 3
4 12345678 .2...... 1....... 12345678 12345678 12345678 12345678 12345678 2
3 .2...... 12345678 12345678 12345678 .....6.. 12345678 ..3..... 12345678 5
3 12345678 12345678 12345678 12345678 12345678 .......8 12345678 12345678 2
2 12345678 12345678 .....6.. 12345678 12345678 ..3..... ......7. 12345678 3
2 12345678 12345678 ....5... 12345678 12345678 12345678 12345678 12345678 1
4 12345678 12345678 12345678 12345678 12345678 12345678 12345678 ..3..... 3
3 12345678 12345678 12345678 12345678 ..3..... 12345678 12345678 12345678 3
@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 / U32.hs
Last active December 5, 2017 02:51
BF DSL code
{-# LANGUAGE FlexibleContexts #-}
module U32 where
import BF
import Control.Monad
data U32 = U32 (Pair,Pair,Pair,Pair)
deriving (Read, Show)