Skip to content

Instantly share code, notes, and snippets.

@rpglover64
Created August 18, 2015 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpglover64/356cbb405d5fcab8b8c9 to your computer and use it in GitHub Desktop.
Save rpglover64/356cbb405d5fcab8b8c9 to your computer and use it in GitHub Desktop.
Example script using turtle
#!/usr/bin/env stack
-- stack --install-ghc runghc --package turtle
{-# LANGUAGE OverloadedStrings #-}
import Turtle
import qualified Data.Text as T
import Data.Traversable
import Data.Foldable
import Data.Either
substLevel = sed ("BookmarkLevel: " <> ("1" *> pure "2"))
normalizeLines x = T.lines x & map pure & foldl (<|>) empty
addBookmark title contents =
normalizeLines =<< sed pat contents
where pat =
"NumberOfPages" <> chars <> pure ("\n" <> T.intercalate "\n"
[ "BookmarkBegin"
, "BookmarkTitle: " <> title
, "BookmarkLevel: 1"
, "BookmarkPageNumber: 1"])
getInfo filename = inproc "pdftk" [filename, "dump_data"] empty
mungeInfo title = addBookmark title . substLevel
main = sh $ for_ list $ \(filename, title) -> do
proc "pdftk" [filename, "update_info", "-", "output", "out-" <> filename] $ mungeInfo title (getInfo filename)
-- -- Didn't work for reasons unknown; the temp file was empty
-- -- possibly related to issue #98
-- main = sh $ for_ list $ \(filename, title) ->
-- using (mktemp "." (filename <> "-.info")) >>= \(tmpFilename, h) -> do
-- outhandle h $ mungeInfo title $ getInfo filename
-- let name = unsafeToText tmpFilename
-- proc "echo" [filename, "update_info", name, "output", "out-" <> filename] empty
-- proc "echo" ["foo"] empty
-- proc "cat" [name] empty
-- proc "echo" ["bar"] empty
-- proc "pdftk" [filename, "update_info", name, "output", "out-" <> filename] empty
-- -- Found a workaround
-- unsafeToText = either undefined id . toText
list =
-- produced by:
-- paste -d, pdfs titles | sed -e 's/,/","/' -e 's/^/ ,("/' -e 's/$/")/' -e '$ a \ \ ]' -e '0,/,/s/,/[/'
[("01-judgments.pdf","Judgments and Propositions")
,("02-pap.pdf","Proofs as Programs")
,("03-categorical.pdf","Categorical Judgments")
,("04-compmodal.pdf","Computational Interpretations of Modalities")
,("05-pml.pdf","Classical Modal Logic")
,("07-cor.pdf","Soundness and Correspondence")
,("08-seqcalc.pdf","Sequent Calculus")
,("09-combinators.pdf","Combinatory Modal Logic")
,("10-modtab.pdf","Modal Tableaux")
,("11-tabsound.pdf","Soundness of Modal Tableaux")
,("12-foml.pdf","First-Order Modal Logic")
,("13-folreduction.pdf","First-Order Logic and First-Order Modal Logic")
,("13-z-noncor.pdf","Noncorrespondence")
,("14-reconcil.pdf","Reconciliation")
,("15-ikripke.pdf","Intuitionistic Kripke Semantics")
,("16-vkripke.pdf","Kripke Semantics for Validity")
,("17-tethered.pdf","Tethered Semantics")
,("18-modck.pdf","Model Checking")
,("19-PDL.pdf","Dynamic Logic")
,("20-complete.pdf","Completeness and Canonical Models")
,("21-decidable.pdf","Decidability and Filtrations")
,("23-linlog.pdf","Linear Logic")
,("24-ressemantics.pdf","Resource Semantics")
,("25-DLtheo.pdf","Dynamic Logic Theory")
]
01-judgments.pdf
02-pap.pdf
03-categorical.pdf
04-compmodal.pdf
05-pml.pdf
07-cor.pdf
08-seqcalc.pdf
09-combinators.pdf
10-modtab.pdf
11-tabsound.pdf
12-foml.pdf
13-folreduction.pdf
13-z-noncor.pdf
14-reconcil.pdf
15-ikripke.pdf
16-vkripke.pdf
17-tethered.pdf
18-modck.pdf
19-PDL.pdf
20-complete.pdf
21-decidable.pdf
23-linlog.pdf
24-ressemantics.pdf
25-DLtheo.pdf
Judgments and Propositions
Proofs as Programs
Categorical Judgments
Computational Interpretations of Modalities
Classical Modal Logic
Soundness and Correspondence
Sequent Calculus
Combinatory Modal Logic
Modal Tableaux
Soundness of Modal Tableaux
First-Order Modal Logic
First-Order Logic and First-Order Modal Logic
Noncorrespondence
Reconciliation
Intuitionistic Kripke Semantics
Kripke Semantics for Validity
Tethered Semantics
Model Checking
Dynamic Logic
Completeness and Canonical Models
Decidability and Filtrations
Linear Logic
Resource Semantics
Dynamic Logic Theory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment