Skip to content

Instantly share code, notes, and snippets.

@waylan
waylan / shlex_with_unicode.py
Created May 12, 2011
The shlex module does not support Unicode input. Which workaround is faster?
View shlex_with_unicode.py
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 Jun 9, 2011
Test the speed of a few different regex methods to escape a known set of chars (as per markdown syntax).
View test_escape.py
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 Feb 22, 2012
Math extension for Python-Markdown
View mdx_math.py
#!/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 Mar 28, 2012
Edit text in the system default text editor (using Envrion vars if set)
View editor.py
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 Apr 2, 2012
Parsing github repo urls.
View gist:2286857
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 Apr 10, 2012
Writing to a python subprocess pipe
View subprocess_pipe.md

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
Marking up Code. Originally authored March 2011 - but never published until now.
View marking_up_code.md

#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 Aug 27, 2012
My proposal for an Admonition Extension to Markdown
View admonition.md

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
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
@waylan
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