Skip to content

Instantly share code, notes, and snippets.

View mpickering's full-sized avatar

Matthew Pickering mpickering

  • Well Typed LLP
  • Sheffield, UK
View GitHub Profile
@mpickering
mpickering / gist:b9fceb4cf9f11e116b49
Created December 8, 2014 17:41
Pandoc filter to remove comments
module Main where
import Text.Pandoc.JSON
import Data.List
main = toJSONFilter removeComments
removeComments :: Block -> [Block]
removeComments e@(RawBlock (Format "html") s) = if isComment s then [] else [e]
removeComments e = [e]
@mpickering
mpickering / gist:0fce7cf3124fee8b38a1
Created December 8, 2014 17:43
Pandoc filter to remove footnotes
module Main where
import Text.Pandoc.JSON
main = toJSONFilter removeFootnote
removeFootnote :: Inline -> [Inline]
removeFootnote (Note _) = []
removeFootnote e = [e]
@mpickering
mpickering / gist:fdc747b9c8306659cb43
Created December 17, 2014 22:32
Pandoc filter to insert non-breaking spaces.
module Main where
import Text.Pandoc.JSON
import Data.List (isPrefixOf)
import Data.Char (isAlphaNum)
main = toJSONFilter insertSpaces
insertSpaces :: Inline -> Inline
insertSpaces l@(Link [Str x] (url, tit))
@mpickering
mpickering / client.hs
Last active October 18, 2015 16:33 — forked from jaspervdj/client.hs
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Main
( main
) where
--------------------------------------------------------------------------------
import Control.Concurrent (forkIO)
import Control.Applicative ((<$>))
@mpickering
mpickering / HTML.hs
Created December 31, 2014 01:32
Servant HTML Combinator
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
import Data.ByteString.Lazy ()
import Text.Blaze.Html (Html)
import Text.Blaze.Renderer.Utf8 (renderMarkup)
import Control.Monad.Trans.Either (EitherT, runEitherT)
import Data.Proxy (Proxy (Proxy))
import Servant.Server.Internal (HasServer (..), RouteMismatch (WrongMethod, NotFound),
@mpickering
mpickering / gist:c518863fa193ac075042
Created January 4, 2015 01:52
Pandoc filter to render frames around content
{-# LANGUAGE OverloadedStrings #-}
module Main where
-- https://groups.google.com/d/msgid/pandoc-discuss/45a32eb9-23b9-4df1-8c6e-2e08073df166%40googlegroups.com?utm_medium=email&utm_source=footer
import Text.Pandoc.JSON
import Text.Pandoc.Definition
import Text.Printf
import Data.Maybe
@mpickering
mpickering / gist:fe079e41a9f30f9e683f
Created January 4, 2015 21:59
Simple servant example
{-# LANGUAGE DataKinds, TypeFamilies, TypeOperators, OverloadedStrings #-}
module M where
import Servant.Server
import Servant
import Data.Text (Text)
import Network.Wai.Handler.Warp
import Data.Proxy
myApi :: Proxy MyApi
@mpickering
mpickering / scrub.hs
Created January 19, 2015 23:36
Pandoc filter where headers at levels lower than 3 are not numbered.
module Filter where
import Text.Pandoc.JSON
import Text.Pandoc.Definition
main :: IO ()
main = toJSONFilter scrub
scrub :: Block -> Block
scrub h@(Header level (uid, cs, kvs) title)
@mpickering
mpickering / gist:99d62ccdb73f49840220
Last active August 4, 2016 01:05
Native idiom brackets
-- https://wiki.haskell.org/Idiom_brackets
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleContexts, FlexibleInstances, UndecidableInstances #-}
import Control.Applicative
import Control.Monad.Identity
class Applicative i => Idiomatic i f g | g -> f i where
idiomatic :: i f -> g
iI :: Idiomatic i f g => f -> g
module RepListMin where
repListMin :: [Int] -> [Int]
repListMin xs = res
where
(m, res) = repListMin' m xs
repListMin' :: Int -> [Int] -> (Int, [Int])
repListMin' m [x] = (x, [m])