Skip to content

Instantly share code, notes, and snippets.

@lierdakil
lierdakil / docx-toc.hs
Last active August 29, 2015 14:08
Pandoc filter to insert toc openxml in the beginning of document
import Text.Pandoc.JSON
tocXml :: String
tocXml = "<w:sdt><w:sdtPr><w:docPartObj>"++
"<w:docPartGallery w:val=\"Table of Contents\" /><w:docPartUnique />"++
"</w:docPartObj></w:sdtPr><w:sdtContent><w:p><w:pPr>"++
"<w:pStyle w:val=\"TOCHeading\" /></w:pPr><w:r>"++
"<w:t>Table of Contents</w:t></w:r></w:p><w:p><w:r>"++
"<w:fldChar w:fldCharType=\"begin\" w:dirty=\"true\" />"++
"<w:instrText xml:space=\"preserve\"> TOC \\o \"1-3\" \\h \\z \\u "++
@lierdakil
lierdakil / pandoc-svg.hs
Last active August 29, 2015 14:17
Pandoc filter to convert svg to pdf with inkscape (useful for pdf output)
import Text.Pandoc.JSON
import Network.Mime
import Data.Text as T
import Data.ByteString.Char8 as BS
import System.Process
go :: Inline -> IO Inline
go (Image alt (src,title)) =
case BS.unpack $ defaultMimeLookup $ T.pack src of
"image/svg+xml" -> do
import Codec.Picture
import Codec.Picture.Types
import Graphics.PDF
import Codec.Picture.Saving
import Data.ByteString.Lazy as B
import System.IO (hClose)
import System.IO.Temp
import System.Environment
main :: IO ()
Root directory: /home/livid/github/pandoc-crossref
Current directory: /home/livid/github/pandoc-crossref
GHC Package flags:
-hide-all-packages -no-user-package-db -package-db
/home/livid/github/pandoc-crossref/.cabal-sandbox/x86_64-linux-ghc-7.10.2-packages.conf.d
-package-id base-4.8.1.0-4f7206fd964c629946bb89db72c80011
-package-id bytestring-0.10.6.0-2362d1f36f1255e85478e7793e15b170
-package-id containers-0.5.6.2-2de75421d746ab474b330e43191bb31b
-package-id data-default-0.5.3-4c3290e8e96ed6070337a2a566c7dc89
-package-id mtl-2.2.1-d47f97102c5df05a46949da5cc90a7f3 -package-id
import Text.Pandoc.JSON
import System.Process
import Text.HTML.TagSoup
main :: IO ()
main = toJSONFilter dotToSvg
dotToSvg :: Block -> IO Block
dotToSvg x@(CodeBlock (_, cls, _) text)
| "dot" `elem` cls = do
@lierdakil
lierdakil / common.h
Created February 13, 2016 19:21
Source-level singleton plugins for C++
struct registry {
static std::map<const char*,Plugin*> plugins;
registry(const char* name, Plugin* plugin) {
plugins[name]=plugin;
}
};
#define REGISTER(name) \
registry name ## _register(#name, new name());
{-# LANGUAGE Rank2Types, TypeOperators, ConstraintKinds, MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances, FlexibleContexts, UndecidableInstances #-}
import XMonad
import Data.Constraint
import XMonad.Layout.LayoutModifier (LayoutModifier, ModifiedLayout)
import XMonad.Layout.NoBorders
type IsLayout l a = (Read (l a), LayoutClass l a)
@lierdakil
lierdakil / xmonad.hs
Last active May 5, 2016 16:45
A toy implementation of fully monadic config
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# OPTIONS_GHC -Wall #-}
@lierdakil
lierdakil / stack.log
Created August 21, 2016 06:17
GHCJS install error
Version 1.1.2 x86_64 hpack-0.14.1
2016-08-21 09:16:54.646365: [debug] Checking for project config at: /home/livid/github/atom-haskell-utils/hs/stack.yaml @(5BJ0oDzTifWLpSS0yqiJ1g:Stack.Config src/Stack/Config.hs:811:9)
2016-08-21 09:16:54.646627: [debug] Loading project config file stack.yaml @(5BJ0oDzTifWLpSS0yqiJ1g:Stack.Config src/Stack/Config.hs:829:13)
2016-08-21 09:16:54.648320: [debug] Checking whether stack was built with libgmp4 @(5BJ0oDzTifWLpSS0yqiJ1g:Stack.Config src/Stack/Config.hs:326:5)
2016-08-21 09:16:54.648458: [debug] Run process: ldd /usr/bin/stack @(5BJ0oDzTifWLpSS0yqiJ1g:System.Process.Read src/System/Process/Read.hs:283:3)
2016-08-21 09:16:54.667295: [debug] Stack was not built with libgmp4 @(5BJ0oDzTifWLpSS0yqiJ1g:Stack.Config src/Stack/Config.hs:330:14)
2016-08-21 09:16:54.667742: [debug] Trying to decode /home/livid/.stack/build-plan-cache/x86_64-linux/lts-5.12.cache @(5BJ0oDzTifWLpSS0yqiJ1g:Data.Binary.VersionTagged src/Data/Binary/VersionTagged.hs:55:5)
2016-08-21 09:16:54.674994:
@lierdakil
lierdakil / test-grammar.cson
Last active September 4, 2016 15:05
Grammar with indentation blocks
fileTypes: []
name: 'TestGrammar'
scopeName: 'source.test-grammar'
patterns: [
{include: '#indent-block'}
]
repository:
'indent-block': {
name: 'indent-block.test-grammar'
begin: '^(\\s+)(?=\\S)'