just enough to get you started and leave you confused

QuickLinks vom 30. Juli bis zum 28. August

| Comments

Meine vom 30. Juli bis zum 28. August:

  • Pollen - is a publishing system that helps authors create beautiful and functional web-based books. Pollen includes tools for writing, designing, programming, testing, and publishing.
  • A Soft Murmur - Ambient sounds to wash away distraction. A Soft Murmur uses HTML5 audio with jQuery and jQuery Mobile. It should work in most modern web browsers. It will not work in Safari on iOS (iPhones and iPads) due to limited support for HTML5 audio.
  • The best part of playing Solitaire - is the Solitaire effect.
  • Übersicht - lets you run system commands and display their output on your desktop in little containers, called widgets. Widgets are written using HTML5, which means theyare easy to write and customize, can show data in tables, charts, graphs … you name it, can react to different screen sizes.
  • nemex - is a tiny app that helps you to track and curate ideas and projects. It’s self-hosted and based on markdown.
  • Quassel IRC - is a modern, cross-platform, distributed IRC client, meaning that one (or multiple) client(s) can attach to and detach from a central core – much like the popular combination of screen and a text-based IRC client such as WeeChat, but graphical. In addition to this unique feature, we aim to bring a pleasurable, comfortable chatting experience to all major platforms (including Linux, Windows, and MacOS X as well as Android smartphones), making communication with your peers not only convenient, but also ubiquitous available.
  • Comskip - is a free mpeg commercial detector. It is a windows console application that reads a mpeg file and analyses the content based on a large amount of configurable parameters. After analysis it generates a file in various possible formats containing the location of the commercials inside the mpeg file.
  • Glowing Bear - is an HTML5 web frontend for WeeChat that strives to be a modern and slick interface. It relies on WeeChat to do all the heavy lifting (connections, servers, history, etc) and then provides some nice features on top of that, like content embedding (images, video) and desktop notifications. The main advantage, though, is that you can access it from any modern internet device without having to worry about ssh connections or terminal emulators.
  • flappyvird - by Yasuhiro Matsumoto is a version of Flappy Bird for Vim. To play it, type :FlappyVird, and then press space to jump. It’s an exquisite work of ASCII art, complete with a Japanese-style emoticon for the bird.
  • Streisand - sets up a new server running L2TP/IPsec, OpenSSH, OpenVPN, Shadowsocks, Stunnel, and a Tor bridge. Either locally or on your favourite cloud host. It also generates custom configuration instructions for all of these services. At the end of the run you are given an HTML file with instructions that can be shared with friends, family members, and fellow activists.

Raubtier Tyrannosaurus Rex

| Comments

Der Sohn und ich betrachteten verschiedene Dinosaurier in einem Prospekt der Firma Schleich und unterhielten uns über deren Einordnung in Herbivoren und Karnivoren1. Es entspann sich bei der Betrachtung der oben stehenden Seite in etwa2 der folgende Dialog:

  • Linus: Das ist ein Pflanzenfresser. Weil er Pflanzen frisst.
  • Dennis: Ja, genau. Wie eine Kuh.
  • Linus: Ja, wie eine große Kuh! Mit großen Hörnern!
  • Dennis: Richtig.
  • Linus: Und wie heißt der?
  • Dennis: Das ist ein Tyrannosaurus Rex.
  • Linus: Und das ist ein Fleischfresser. Ein Raubtier!
  • Dennis: Ja, da hast du Recht.
  • Linus: Weil, der frisst nämlich Raupen!
  • Dennis:

Kinder sind das allercoolste…

  1. Seit dieser Szene aus Jurassic Park nenne ich die aber eigentlich immer Vegetarosaurier und Fleischosaurier. Auch die menschlichen Ausgaben, stets ein großer Spaß…

  2. Dies ist ein Gedächtnisprotokoll…

QuickLinks vom 06. Juni bis zum 30. Juli

| Comments

Meine vom 06. Juni bis zum 30. Juli:

  • Git-ftp - is a FTP client using Git to determine which local files to upload or which files should be deleted on the remote host. It saves the deployed state by uploading the SHA1 hash in the .git-ftp.log file. There is no need for Git to be installed on the remote host.
  • CSVfix - If you have any dealings at all with data and databases, then you almost certainly will have to deal with comma-separated values (CSV) data. Unfortunately, the CSV files you are given, or are required to produce, never seem to be in quite the right format for your particular business application. And because of the structure of CSV records, using standard text processing tools like sed, awk and perl is not as simple as it might be. CSVfix aims to provide a solution to these problems. It is a command-line stream editor specifically designed to deal with CSV data.
  • Hyperion - is an opensource ‘AmbiLight’ implementation controlled using the RaspBerry Pi running Raspbmc.
  • daemonize - runs a command as a Unix daemon. As defined in W. Richard Stevens’ 1990 book, UNIX Network Programming (Addison-Wesley, 1990), a daemon is “a process that executes ‘in the background’ (i.e., without an associated terminal or login shell) either waiting for some event to occur, or waiting to perform some specified task on a periodic basis.”
  • AirSonos - is a small server written in node.js to add AirPlay support to a Sonos network.
  • Gitblit - is an open-source, pure Java stack for managing, viewing, and serving Git repositories. It’s designed primarily as a tool for small workgroups who want to host centralized repositories.
  • Pixel Winch - is a screen measurement app with a unique approach. Rather than overlaying complicated controls on top of your existing workflow, it combines aspects of a traditional image editor with the quick access of a modal interface (similar to OS X’s Launchpad or Dashboard).
  • Babun - is a Windows shell you will love. Would you like to use a linux-like console on a Windows host without a lot of fuzz? Try out babun!
  • XKeymacs - is a keyboard utility to realize emacs like-useability on all windows applications. With XKeymacs you can use emacs keybindings with any windows application. You can create a keyboard macro and assign any shortcut key too. You also get bash-like command completion in your DOS shell. If you do not know Emacs, Xemacs, Mule or Meadow, you probably want nothing to do with XKeymacs.
  • osxc - installs software on your mac and configures it automatically, just by writing a few lines of code. Lost everything on your hard drive? osxc got your back, don’t waste your time reinstalling your dev environment. Want to experiment new configuration? just try it, your configuration repository is versioned.

MacBook Pro mit einer SSD aufrüsten: Speed Baby!

| Comments

Mein Computer ist ein Apple MacBook Pro (early 2011) mit hochauflösendem 15” AntiGlare Display, einer 2 GHz Intel Core i7 CPU und 8 GB RAM. Das ist auf dem Papier so weit immer noch eine schnelle Maschine.

In der Praxis wird das Gesamtsystem allerdings durch die verbaute 500 GB Toshiba-Festplatte mit 5400 RPM ausgebremst. Und zwar nicht zu knapp.

Die Messung mit dem Black Magic Disk Speed Test ergibt auch sehr wohlwollend betrachtet lediglich schlappe 40 Megabyte/s im Lesen und so gerade eben 28 Megabyte/s im Schreiben.

Die Festplatte nutzt die verfügbaren 6 Gigabit/s Bandbreite1 des internen SATA 3 Anschlusses also nicht wirklich aus…

Gerade bei Vorgängen die auf viele, relativ kleine Dateien auf der Platte zurückgreifen, dreht die CPU Däumchen während sie auf die Anlieferung der Datenhäppchen wartet. Das sind bei mir vor allem:

Insbesondere dann, wenn Arbeit mit dem Fotoarchiv und ein2 gleichzeitiger Backuplauf zusammenkamen, war eine angemessene Schwuppdizität in egal welchem Programm kaum mehr zu erzielen.

Glücklicherweise ist der Festplatte als Flaschenhals relativ einfach beizukommen: Man ersetze sie schlicht mit einer SSD. Diese auf Flash-Speicher basierenden Laufwerke sind Festplatten in allen technischen Belangen, vor allem aber bei der Zugriffsgeschwindigkeit, überlegen. Dafür sind Festplatten, besonders wenn man Kapazitäten ab 500 GB betrachtet, um Größenordnungen billiger.

Alternativ hätte ich natürlich eine günstigere, kleinere SSD mit ca. 128-256 GB erwerben können und dann sehr mit meinen Daten haushalten3. Oder die Festplatte mit einem OptiBay-Adapter anstelle des Superdrives in das MacBook Pro einbauen und dort die großen Daten, also in meinem Fall vor allem das Fotoarchiv, lagern. Das erschien mir aber wie eine unvollständige Lösung des Problems, ich wollte gerne alle Daten auf schnellem Flash-Speicher liegen haben.

Nach einigen Jahren4 der Marktbeobachtung habe ich mich nun bei nur ganz knapp über 200 € für eine 500 GB große Samsung 840 evo SSD entschieden. Und ich bin mit diesem Stück Hardware sehr glücklich.

Um es tl;dr-kurz zu machen: Alles was die Leute über SSDs sagen ist wahr. Hat man einmal an einem SSD-basierten System gearbeitet, so gibt es kein Zurück mehr. Never ever will ich noch mal mit einem Computer arbeiten, dessen OS auf rotierenden, magnetischen Scheiben liegt5. Die SSD ist meiner Meinung nach das beste und sinnvollste singuläre Hardware-Upgrade für Computer seit den seeligen Zeiten der 3D-Beschleuniger-Karten anno 1995. Yes, it’s that good.

Wie glücklich genau eine SSD macht, wie die SSD in das MacBook kam und wie meine Daten von den magnetischen Scheiben in die Flash-Zellen übertragen wurden, das alles folgt nach dem Klick…

QuickLinks vom 10. April bis zum 06. Juni

| Comments

Meine vom 10. April bis zum 06. Juni:

  • Cloudmarks - is a Safari extension that works with cloud bookmarking services Pinboard, Delicious, Kippt, and Google Bookmarks. Cloudmarks lets you access your cloud bookmarks in a convenient popover window without interrupting your browsing.
  • contacts - gives you access to view and search all your records in the AddressBook database.
  • OpenRefine - is a power tool that allows you to load data, understand it, clean it up, reconcile it to master database, and augment it with data coming from Freebase or other web sources. All with the comfort and privacy of your own computer.
  • cliutils - is a library of functionality designed to alleviate common tasks and headaches when developing command-line (CLI) apps in Ruby.
  • GitBook - is a command line tool (and Node.js library) for building beautiful programming books and exercises using GitHub/Git and Markdown. An editor is available for Windows, Mac and Linux.
  • Fuck Off As A Service (FOAAS) - provides a modern, RESTful, scalable solution to the common problem of telling people to fuck off.
  • DynaHack - A NetHack variant with UnNetHack’s new content/challenges, NitroHack’s UI, GruntHack’s random magical items, and more.
  • play - is an employee-powered iTunes-based client-driven distributed music server for your office. Also it can prepare your taxes.
  • iTunes-Volume-Control - This app allows you to control the iTunes volume using volume up and volume down hotkeys.
  • Tumult Hype - Using Tumult Hype, you can create beautiful HTML5 web content. Interactive content and animations made with Tumult Hype work on desktops, smartphones and iPads. No coding required.


| Comments

Heute vor vier Jahren haben Kathi und ich geheiratet.

Ich wünsche der besten Ehefrau der Welt und mir eine wundervolle seidene Hochzeit1 und freue mich auf das nächste Jahr im aufregenden Hafen der Ehe.

  1. Es gibt wirklich wunderliche Listen im Internet…

QuickLinks vom 17. März bis zum 09. April

| Comments

Meine vom 17. März bis zum 09. April:

  • dategrep - searches the named input files for lines matching a date range and prints them to stdout. If dategrep works on a seekable file, it can do a binary search to find the first and last line to print pretty efficiently. dategrep can also read from stdin if one the filename arguments is just a hyphen, but in this case it has to parse every single line which will be slower.
  • Normbrief mit Markdown - Mit diesem Stylesheet (CSS) kann man mittels Markdown private Briefe oder auch Geschäftsbriefe verfassen. Dabei wird das Anschriftsfenster von Briefumschlägen berücksichtigt. Der Briefkopf mit Bank- und Kontaktdaten erscheint in einer zweiten Spalte.
  • Comic Neue - Comic Sans wasn’t designed to be the world’s most ubiquitous casual typeface1. Comic Neue aspires to be the casual script choice for everyone including the typographically savvy. The squashed, wonky, and weird glyphs of Comic Sans have been beaten into shape while maintaining the honesty that made Comic Sans so popular. It’s perfect as a display face, for marking up comments, and writing passive aggressive office memos.
  • TreeSheets - is the ultimate replacement for spreadsheets, mind mappers, outliners, PIMs, text editors and small databases. Suitable for any kind of data organization, such as Todo lists, calendars, project management, brainstorming, organizing ideas, planning, requirements gathering, presentation of information, etc.
  • AltDrag - gives you the ability to move and resize your windows in a new way. When running, you can simply keep the Alt key depressed and then click and drag any window. Besides just moving windows, you can resize, maximize and close them too. AltDrag simply allows you to do more with less mouse movements.
  • Tabula - is a tool for liberating data tables trapped inside PDF files. If you’ve ever tried to do anything with data provided to you in PDFs, you know how painful this is - you can’t easily copy-and-paste rows of data out of PDF files. Tabula allows you to extract that data in CSV format, through a simple interface.
  • fzf - is a general-purpose fuzzy finder for your shell.
  • wkline - is a WebKit-based statusline utility for tiling window managers. It displays a HTML-based statusline in a WebKit web view. It provides a smooth looking statusline with CSS transitions and effects, and the possibility of having a transparent background with effects without a desktop compositor running.
  • After Dark in CSS - Do you longingly reminisce about the days when flying toasters graced your screen? Do words like “Confetti Factory” and “Daredevil Dan” make your heart skip a beat? If so, then never fear — CSS is here! Using modern CSS techniques like animations and transforms, we can imitate several of your favorite After Dark(tm) screensavers.
  • httpie - is a command line HTTP client. Its goal is to make CLI interaction with web services as human-friendly as possible. It provides a simple http command that allows for sending arbitrary HTTP requests using a simple and natural syntax, and displays colorized responses. HTTPie can be used for testing, debugging, and generally interacting with HTTP servers.

Nina ist da

| Comments

Nina ist heute morgen um 05:15 Uhr auf die Welt gekommen. Das Tochterkind ist 51 cm und 3170 g pure Magie und reines Wunder.

Wir sind schon wieder zuhause, Linus ist ein großer Bruder, Kathi und ich das zweite mal Eltern. Es ist so verrückt und so schön.

Auf zu neuen Abenteuern, wir freuen uns drauf!

Das Foto bei Flickr.

QuickLinks vom 06. Februar bis zum 17. März

| Comments

Meine vom 06. Februar bis zum 17. März:

  • HTML-XML-utils - are a number of simple utilities for manipulating HTML and XML files. Including the incredibly handy hxpipe, which converts HTML to a line-by-line format that plays nicely with awk, grep, sed, …
  • MkDocs - is a fast, simple and downright gorgeous static site generator that’s geared towards building project documentation. Documentation source files are written in Markdown, and configured with a single YAML configuration file.
  • Steg - is a cross-platform and portable software, written in C++. It use steganography and cryptography techniques to hide information inside uncompressed and compressed images. JPEG (JPG), TIFF, PNG, BMP image formats are supported. With it’s easy graphical user interface is possible to fine tune steganography parameters, evaluates image’s artifacts and uses both symmetric-key and asymmetric-key cryptography. Arbitrary data can be hidden as compressed archive file and it’s also possible to add a text comment.
  • ctrlp.vim - Full path fuzzy file, buffer, mru, tag, … finder for Vim.
  • Log Parser Studio - is a utility that allows you to search through and create reports from your IIS, Event, EXADB and others types of logs. It builds on top of Log Parser 2.2 and has a full user interface for easy creation and management of related SQL queries.
  • Massren - is a command line tool that can be used to rename multiple files using your own text editor. Multiple-rename tools are usually difficult to use from the command line since any regular expression needs to be escaped, and each tool uses its own syntax and flavor of regex. The advantage of massren is that you are using the text editor you use every day, and so can use all its features.
  • iotop - is a Python program with a top like UI used to show of behalf of which process is the I/O going on.
  • LAN Speed Test (Lite) - is a FREE utility designed from the ground up to be a simple but powerful tool for measuring file transfer, hard drive, USB Drive, and Local Area Network (LAN) speeds (wired & wireless).  It does this by building a file in memory, then transfers it both ways (without effects of windows file caching) while keeping track of the time, and then does the calculations for you.
  • Dropbox Uploader - is a BASH script which can be used to upload, download, list or delete files from Dropbox
  • Faker - is a Rubygem that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.

Markdown Footnotes with Vim

| Comments

When I sit in front of an old school, regular computer1, writing happens in Vim. Mails, code, blogposts, my diploma thesis, ToDo-lists, comments on random web pages2 - everything.

And I love Markdown. And footnotes3. So the usage of MultiMarkdown-footnotes is a natural fit.

There is no real standard for the notation, but most people tend to use numbers or words or a combination of these two. As long as the footnote marker is preceded by a caret (^) and enclosed by square brackets ([]) and the matching footnote reference starts at the beginning of a line and is followed by a colon (:), MultiMarkdown is a happy camper. The resulting Markdown-source is easy to read and really flexible:

MultiMarkdown Footnotes
This is an example text containig footnotes[^1]. These can be made of numbers
or almost any other character[^anotherfootnote]. 

Of course, one can use a combination[^fn5].

[^1]: This is a footnote...

[^anotherfootnote]: Therefore, this is also a footnote...

[^fn5]: This is also a footnote...

Trouble is, all these brackets and carets for the footnote links are kind of hard to type. The best practice for the footnote references is to keep them at the end of the file, so additional cursor movement is necessary. If you just want to insert a footnote as fast as possible and keep your writing flow, all this key pressing gets boring really soon.

vim-markdownfootnotes to the rescue

Luckily, I use Vim. Vim loves text automation. And Vim is used by lots of smart people like David Sanson who forked the venerable vimfootnotes, named it vim-markdownfootnotes and tweaked it for use with the extended Markdown markup as shown above.

The vim-markdownfootnotes plugin can easily be installed with Pathogen and defines two mappings:

vim-markdown mappings
<Leader>f    Insert new footnote 
<Leader>r    Return from footnote

From now on, you just type <Leader>f whenever you want to insert a footnote marker. The mapping works in normal and in insert mode which results in almost no friction while writing. This simple command inserts a footnote marker like [^1] after the cursor and a matching footnote reference like [^1]: gets inserted all the way down at the end of the file. Impressive, but the wonder does not stop here:

Vim opens a new buffer in a split window at the bottom of the current window and places your cursor right behind the empty space after the colon. This way you can just keep on typing your footnote and hit <Leader>r to close the split and return to the place in the main text where you left off. And you just keep on typing, leaving behind only a beautifully formatted MultiMarkdown footnote and no wasted thoughts.

It looks a lot like this:

The plugin also keeps track of the number of footnotes it inserted so the second footnote marker gets inserted as [^2], the third as [^3] and so on…

It’s a really good solution and includes some nice bells and whistles. If, for example, you don’t like the use of the default arabic numerals you are free to change the format by setting the variable vimfootnotetype to one of the following:

  • arabic: 1, 2, 3…
  • alpha: a, b, c, aa, bb…, zz, a…
  • Alpha: A, B, C, AA, BB…, ZZ, A…
  • roman: i, ii, iii… (displayed properly up to 89)
  • Roman: I, II, III…
  • star: *, **, ***…

Because we can. Crazy stuff. Totally cool if you think about it.

My footnote counter pet peeve

I installed the plugin in spring 2012 and slightly changed the sourcecode to use [^fn23] as footnote markup4 to make it more distinguishable from regular numbered Markdown reference style links. I kept on using it ever since, despite one minor gripe which kept on itching me:

The footnote counter only works for one session. Whenever I opened a file which already contained some footnotes, I had to check5 for the number of the last added footnote and use the FootnoteNumber command to set the counter to the correct starting point.

I usually write my blogposts in small chunks, so typing :FootnoteNumber 5 after finding out that the last footnote was [^fn4] was also kinda boring. And of course I always inserted a [^fn1] when footnotes were already present in the file before remembering I had to adjust the counter. So I had to undo the last footnote, close the split by hand, reset the counter and start again…

I don’t want to do this little footnote-counter-adjusting-dance every time I open a file. My computer should do this for me. I mean, seriously how hard can it be?

Luckily, another smart Vim-user named Nick Coleman, solved the problem for the automatic insertion of HTML-footnotes which are magnitudes harder to type than their Markdown counterparts. He wrote his own footnote.vim script which6 does not include fancy stuff like key mappings or splits but had a working footnote counter implemented in VimL.

So I did what every self respecting geek would do:

I ripped the code apart and changed the regular expression to match against my style of Markdown footnotes. The result worked fine on it’s own but I missed the easy writing flow of <Leader>f and <Leader>r.

Naturally, I forked vim-markdownfootnotes on Github and cobbled the counter code directly into the function s:VimFootnotes(appendcmd). Now, whenever I hit <Leader>f the script counts the occurences of the footnote references, adds 1 and sets the global variable g:vimfootnotenumber to the result.

The FootnoteNumber, FootnoteNumberRestore and FootnoteUndo functions are still present in the code, but whatever they set the variable to gets overridden by the automatic counter which, by the way, even works with non arabic numerals. So people who prefer their footnotes numbered with roman numerals or stars can also use this.

No more thinking about the current footnote counter, more thinking about my words. Excellent.

Sorting Markdown footnotes

Now, because I tend to edit my posts in small chunks it is not uncommon at all, that I insert a footnote somewhere in the text. Maybe even at the very beginning. This can lead to a situation like this7:

Unordered Footnotes
Well, the way they make shows is, they make one show. That show's called
a pilot[^fn2]. Then they show that show to the people who make shows, and on the
strength of that one show they decide if they're going to make more shows. Some
pilots get picked and become television programs. Some don't, become nothing.
She starred in one of the ones that became nothing.

Now that there is the Tec-9[^fn1], a crappy spray gun from South Miami. This gun is
advertised as the most popular gun in American crime. Do you believe that shit?
It actually says that in the little book that comes with it: the most popular
gun in American crime. Like they're actually proud of that shit[^fn3]. 

[^fn1]: This is a footnote concerning the Tec-9, it was the first that was written...

[^fn2]: This is the second footnote I added, it's marker appears in the text before the marker of the first footnote...

[^fn3]: This is the third footnote I added, it's marker is the last in the text...

The second footnote is added to the beginning of the text, 2 appears before 1. The footnote references are numbered 1, 2, 3 but the footnote markers are 2, 1, 3.

This is, and I may overreact here, totally wrong

Markdown does not care a bit about the order in which the footnotes appear in the text. The text above and the following, nicely tidied up text render to the exact same HTML.

Sorted footnotes by appearance in the text
Well, the way they make shows is, they make one show. That show's called
a pilot[^fn1]. Then they show that show to the people who make shows, and on the
strength of that one show they decide if they're going to make more shows. Some
pilots get picked and become television programs. Some don't, become nothing.
She starred in one of the ones that became nothing.

Now that there is the Tec-9[^fn2], a crappy spray gun from South Miami. This gun is
advertised as the most popular gun in American crime. Do you believe that shit?
It actually says that in the little book that comes with it: the most popular
gun in American crime. Like they're actually proud of that shit[^fn3]. 

[^fn1]: This is the second footnote I added, it's marker appears in the text before the marker of the first footnote...

[^fn2]: This is a footnote concerning the Tec-9, it was the first that was written...

[^fn3]: This is the third footnote I added, it's marker is the last in the text...

So nobody but me would notice any difference. But really, this bothered me. So again, I turned to the Internet to see if I could find a solution for my problem. And sure enough, in a thread on the MultiMarkdown Google group I found a hint8 that the document converter Pandoc could do this by converting from Markdown to Markdown like this:

pandoc conversion
cat example.mmd | pandoc --from markdown --to markdown > tidied-example.mmd

Indeed, this works fine but strips my beloved fn-addition from each and every footnote… And I’m so used to my beloved fn-additions…

I considered diving into the source of Pandoc to fix this behaviour and learn some Haskell along the way but decided against it. I thought of formd, which I use to convert Markdown links from inline to reference style9 and wondered, why this fine software does not work with footnotes. After all, they are not that different from regular reference links, aren’t they?

Soon I found out that Seth Brown aka Dr. Bunsen altered the code of formd to ignore footnotes. As requested by Martin Kopischke and, ahem, me

I tried to find out if I could alter the behaviour of formd to sort footnotes as effortless into a nice order as links. But my Python-fu was too weak.

With some more looking at the Internet I found a promising looking post by yet another Dr., Dr. Drang. He wrote a Python-script to tidy up Markdown reference links.

More importantly, he explained the inner workings of the script in great detail, so even I could figure out10 how this was supposed to work. Just like formd, the script made sure to exclude footnotes. I changed the two regular expressions to match against footnote markers and references and ignore regular markdown links. The inner logic remained the same and some more adjustments to the string replacement parts later the new sort_footnotes script worked surprisingly well. It looks like this:


import sys
import re

Read a Markdown file via standard input and tidy the containing
Multimarkdown footnotes. The reference links will be numbered in
the order they appear in the text and placed at the bottom
of the file.

Based on "Tidying Markdown reference links" by Dr. Drang available at:

Do *not* place footnote reference links at the start of a line, bad things will
happen, your footnotes will be eaten by a grue.

# The regex for finding footnote reference links in the text. 
link = re.compile(r'[^(?<=\n)](\[\^fn([\d]+)\])')

# The regex for finding the footnote labels with the text.
label = re.compile(r'(?<=\n)\[\^fn([\d]+)]:\s?(.*)')

def refrepl(m):
    # Rewrite reference links with the reordered link numbers. Insert the first
    # character from the footnote reference link right before the new link.
    return '%s[^fn%d]' % ([:1], order.index( + 1)

# Read in the file and find all the footnote-links and -references.
text =
links = link.findall(text)
labels = dict(label.findall(text))

# Determine the order of the footnote-links in the text. If a link is used
# more than once, its order is its first position.
order = []
for i in links:
    if order.count(i[1]) == 0:

# Make a list of the footnote-references in order of appearance.
newlabels = [ '[^fn%d]: %s \n' % (i + 1, labels[j]) for (i, j) in enumerate(order) ]

# Remove the old footnote-references and put the new ones at the end of the text.
text = label.sub('', text).rstrip() + '\n'*3 + '\n'.join(newlabels)

# Rewrite the footnote-links with the new footnote-reference numbers.
text = link.sub(refrepl, text)

print text

The script is also available in it’s own Github repository.

Like the original by Dr. Drang, sort_footnotes is by no means foolproof. In fact, it does not work with footnote links at the start of a line and fails horrible if one is found in a file. The alternate way to differentiate between footnote links and footnote references would have been the colon. I figured it is much more probable that a footnote link appears right before a colon, than it’s appearance at the start of a line. After all, footnotes should appear after words or, even better, sentences and not before them11. Even stranger things might occur if two footnotes have the same number or if one marker misses it’s reference or vice versa. This kind of stuff should of course never happen if you use the automatic insertion of footnotes as described above but YMMV

This script also does not work with roman numerals or stars so fans of these footnote markers will have to port the numeral converter from VimL to Python and insert it into my script12

Because the script was designed to work via standard input it is easy to create a small Vim macro, assign a mapping like <Leader>fs and pipe the content of the current buffer through it. For good measure I also defined a <Leader>fx mapping to use formd and sort_footnotes in one fell swoop on the current buffer.

The mappings are defined in my .vimrc as follows:

My .vimrc Markdown reformating mappings
" Use formd to transfer markdown from inline to reference links and vice versa
" Use the vim mark m to jump back to the position from where formd was invoked.
" see:
nnoremap <leader>fr mm :%! ~/bin/formd -r<CR> `m :delmarks m<CR>
nnoremap <leader>fi mm :%! ~/bin/formd -i<CR> `m :delmarks m<CR>
" Sort footnotes into order of appearance
nnoremap <leader>fs mm :%! ~/bin/sort_footnotes<CR> `m :delmarks m<CR>
" Reformat with formd to reference style and sort the footnotes. The whole
" enchilada...
nnoremap <leader>fx mm :%! ~/bin/formd -r <bar> ~/bin/sort_footnotes<CR> `m :delmarks m<CR>

And this is pretty much it.

Without worrying about cursor movement, bracket typing and keeping footnote counters up to date it is much easier to type at the speed of thought. It is one mental barrier less when I jump into a draft for a 20 minute editing session after a long day. And the nicely ordered lists of links and footnotes at the end of my markdown source files make me feel all warm and cozy inside.

  1. As in, not an iOS device…

  2. Thanks to the wonderful QuickCursor

  3. Oh boy, do I love me some footnotes…

  4. This is just my personal preference, you can use just about anything or leave it as is…

  5. as in manually…

  6. on purpose…

  7. Sample text produced by the awesome Samuel L. Ipsum

  8. From the already mentioned David Sanson…

  9. formd sorts the reference style links exactly like I want my footnotes sorted…

  10. After poking around in the code with a long stick and some print statements…

  11. At least according to the English and German Wikipedia…

  12. Well, maybe, one of those days…