Skip to content

Instantly share code, notes, and snippets.

waylan /
Created May 12, 2011
The shlex module does not support Unicode input. Which workaround is faster?
import shlex
import re
# Testing shlex with Unicode.
# The shlex module does not support Unicode input. Which workaround is faster?
# Sample string. Using an Attribute List from Maruku's syntax:
t = u'.foo #bar class=foo ref title="Foo \xc3 bar."'
waylan /
Created Jun 9, 2011
Test the speed of a few different regex methods to escape a known set of chars (as per markdown syntax).
import re
# This is using html entities. Not sure if I want to use these.
# But this shouldn't effect the times.
escape_table = {
'\\': '\', # backslash
'`' : '`', # backtick
'*' : '*', # asterisk
'_' : '_', # underscore
waylan /
Created Feb 22, 2012
Math extension for Python-Markdown
#!/usr/bin/env python
Math extension for Python-Markdown
Copied from for preservation.
The following description was attached by the author:
> This is a quick and dirty implementation of allowing <math> LaTeX </math> to do
waylan /
Created Mar 28, 2012
Edit text in the system default text editor (using Envrion vars if set)
from __future__ import print_function
import os
import sys
from tempfile import mkstemp
from subprocess import call
def run_editor(txt):
""" Edit the given text in the system default text editor. """
waylan / gist:2286857
Created Apr 2, 2012
Parsing github repo urls.
View gist:2286857
import urlparse
formats = [
'', # ssh read/write
'git://', # ssh read
'', # http read/write
'' # http read
for format in formats:
waylan /
Created Apr 10, 2012
Writing to a python subprocess pipe

Here's a few things I tried to write output to a python subprocess pipe.

from subprocess import Popen, PIPE

p = Popen('less', stdin=PIPE)
for x in xrange(100):
    p.communicate('Line number %d.\n' % x)
waylan /
Created May 31, 2012
Marking up Code. Originally authored March 2011 - but never published until now.

#Marking up Code

In reviewing syntax highlighters, I have observed that there are as many different ways to mark up a code fragment in HTML as there are highlighting tools. In other words, every tool seems to define a different syntax. Some use pre tags, some use 'code' tags, some use both, and then there are those that use other elements like div tags.

The most obvious problem with this is that if you want to switch to a different tool, you need to change all your old HTML documents to use the new syntax; which could be a real time suck. Sure the process could be automated, but writing a bug-free script could become just as painful as making the changes manually.

Another, perhaps less obvious issue is the semantics of the markup used. Does the markup accurately convey what the content actually is? For example, many people use pre tags around code. Of course, the pre element is specifically for "preformatted text" which code often is. However, some have argued that preformatted text is presentatio

waylan /
Created Aug 27, 2012
My proposal for an Admonition Extension to Markdown

Admonition Extension

! Note
    This is a paragraph in a "Note"

    This is a second paragraph.

! Warning
    This has not been implemented. This is only a demonstration of the syntax.
View .gitignore
# Byte-compiled / optimized / DLL files
# C extensions
# Distribution / packaging
waylan / gh-pages_subtree_example.txt
Created Nov 9, 2012
Bash session testing the creation of a git repo and using subtree to extract the /docs dir as the gh-pages branch.
View gh-pages_subtree_example.txt
waylan@dev:~$ mkdir foo
waylan@dev:~$ cd foo
waylan@dev:~/foo$ git init
Initialized empty Git repository in /home/waylan/foo/.git/
waylan@dev:~/foo$ echo "foo" > README
waylan@dev:~/foo$ git add README
waylan@dev:~/foo$ git commit -m 'Added README'
[master (root-commit) 1f31bb3] Added README
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 README