Sunday, March 19, 2017

Command-line Docker tip

If you're developing/running command line tools in Docker containers, you'll probably want the tool to know from what folder you're running the tool. To do this, you'll want to pass the "-v `pwd`:/source" option, where:
  • "pwd" (surrounded by backticks) is aliased to the working directory within the container
  • "/source" is the internal working directory within the container

For this (above and below) example, I'm using the Pandoc container, developed by jagregory. If I save the script (below) as "md2pdf", the syntax to run it would be something like:

  md2pdf result.pdf

My Script:



# following must be "beamer" or "latex"
# note: use beamer when producing PDF slides 
#       and latex when producing papers

#$format = "beamer";
$format = "latex";

if($format eq "latex") {
 $margin="-V geometry:margin=1in";
 $toc = "--toc";
 $highlight = "--listings --highlight-style=tango";

system("sudo docker run --rm -v `pwd`:/source pg/pandoc $toc $margin \
  $highlight -f markdown -t $format $src -o $tgt");

Sunday, March 12, 2017

Oops! Fixed.

While posting about Pandoc, I noticed that the February reading list was missing (it was still in draft status). I've finished the content and have post-dated it.

How to install Pandoc in Docker and convert Markdown to PDF

Pandoc is described as the Swiss Army knife of document converters. Following are my notes describing how to combine Docker and Pandoc, with a bit of Perl, to implement a command line utility that converts from one format to another (in this case, Markdown to PDF).

Note: Following assumes that you already have a working instance of Docker and that you can either: configure Docker to run as a normal user or can configure sudo to allow the user to run Docker.


1) Create a working directory and navigate into it:

  mkdir work
  cd work

2) Pull in J. A. Gregory's Dockerfile by running:


3) Create the Docker container by running:

  docker build -t pg/pandoc .

Note the period at the end. The above will take a few minutes to build so take a bio break, make a cup of coffee, or do something else that takes about 5 minutes.

4) In a "/bin" directory (I use /home/tim/bin and have added that to my $PATH), create a file called "md2pdf", containing the following:

  # declare the output
  $format = "latex";
  # edit the following to tweak your output
  $margin="-V geometry:margin=1in";
  $toc = "--toc";
  # following should all be on a single line
  # use "sudo docker..." if your Docker can't be called by 
  # a normal user
  system("sudo docker run -v `pwd`:/source pg/pandoc $toc \
    $margin -f markdown -t $format $src -o $tgt");

In the above, "-v `pwd`:/source" allows you to convert a Markdown file in whichever directory you happen to be working in, when calling pandoc. Effectively, you're temporarily linking your current working directory to the "/source" folder in the container.

5) Make "md2pdf" executable by running:

  chmod a+x md2pdf

In the above, the $margin variable redefines the margins for the output. Without the declaration, the output's margins are a bit excessive. The $toc variable causes the output to have a table of contents. If you use that, you'll probably also want to use \newpage or \pagebreak in your Markdown code, to trigger a new-page in the output.

6) Test your instance by creating a file called "", containing:

  # This is a test
  Just want to see if this works

    #sample code
    blah blah

  Hopefully it worked.

7) Test the file conversion by running:

  md2pdf mine.pdf

8) Open the new file in Google Chrome or your favorite PDF reader.


Wednesday, March 1, 2017

What was I reading in February 2017?


- OpenScope An Open Source Multi-function Board - Electronics-Lab
- Stop Disabling SELinux: A Real-World guide
- Typing Practice for Programmers SpeedCoder
- CoVim - Collaboration in Vim!


- Using tmux properly
- Terrible Ideas in Git
- Military Reading List
- Shaarli


- House Passes E-mail Privacy Act
- oxford-cs-deepnlp-2017/lectures
- Op-ed: Windows 10 0day exploit goes wild and so do Microsoft marketers
- Learn C Programming With 9 Excellent Open Source Books


- Windows Subsystem for Linux: Wine runs on it! No idea why but...


- What Vizio was doing behind the TV screen


- muesli/beehive - An event/agent system
- marcan/ - Wipe and reinstall a running Linux system via SSH, without rebooting.
- Keybase's end-to-end encrypted chat
- Oracle refuses to accept pro-Google fair use verdict in API battle - Means there's more of the shambling horror to come...


- I Do Not Know C
- Now sites can fingerprint you online even when you use multiple browsers
- Fuzzing PCI express: security in plaintext


- a discussion of Fedora's legal state []
- Getting Started with Deep Learning - Silicon Valley Data Science
- A rift in the NTP world []


- Neuromancer - Audio Book : William Gibson : Free Download & Streaming : Internet Archive
- Toward the Discovery of Citation Cartels in Citation Networks
- Tsundoku - One man's libary is another's OCD. You decid(Never mind that! None of your business! Go away!)


- Getting started with Vim


- Google Site Search - Google Enterprise Search
- World of Tanks streamer dies during 24-hour Twitch marathon
- The Hidden History of the Laundry Chute
- The PMP - How it Ruined Project Management


- Encryption Primer


- Is Your Child A Hacker? - I'd thought this meme was dead, years ago.


- Why Nothing Works Anymore
- Secondhand Smoke Is Not Nearly As Dangerous As We Thought. Shouldn't That Matter?

Above was generated by a homegrown bolt-on script for Wallabag, which is a free utility for capturing web content so that it can be read later.