Skip to content

Instantly share code, notes, and snippets.

@waylan
waylan / shlex_with_unicode.py
Created May 12, 2011 18:42
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:
# http://maruku.rubyforge.org/proposal.html#attribute_lists
t = u'.foo #bar class=foo ref title="Foo \xc3 bar."'
@waylan
waylan / test_escape.py
Created June 9, 2011 20:08
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
waylan / mdx_math.py
Created February 22, 2012 16:59
Math extension for Python-Markdown
#!/usr/bin/env python
"""
Math extension for Python-Markdown
Copied from http://freewisdom.org/projects/python-markdown/mdx_math 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
waylan / editor.py
Created March 28, 2012 16:49
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
waylan / gist:2286857
Created April 2, 2012 20:04
Parsing github repo urls.
import urlparse
formats = [
'git@github.com:org-or-user/project.git', # ssh read/write
'git://github.com/org-or-user/project.git', # ssh read
'https://username@github.com/org-or-user/project.git', # http read/write
'https://github.com/org-or-user/project.git' # http read
]
for format in formats:
@waylan
waylan / subprocess_pipe.md
Created April 10, 2012 19:12
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
waylan / marking_up_code.md
Created May 31, 2012 17:22
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
waylan / admonition.md
Created August 27, 2012 15:11
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.
@waylan
waylan / .gitignore
Last active November 7, 2023 14:26
See an updated version at <https://github.com/Python-Markdown/dingus>.
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
@waylan
waylan / gh-pages_subtree_example.txt
Created November 9, 2012 20:55
Bash session testing the creation of a git repo and using subtree to extract the /docs dir as the gh-pages branch.
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