Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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
@waylan
waylan / bat_python_and_errors.bat
Created November 28, 2012 18:10
How to stop cmd window from closing when running a script from a bat file. This way, you can read any errors and simple hit [enter] when you are done and the window will close then.
C:\Python27\python.exe myscript.py
set /p variable= "Hit enter to continue"
from xml.etree import ElementTree as etree
class _ElementInterface(etree._ElementInterface):
""" Add a 'parent' property to ElementTree Elements. Defaults to None. """
parent = None
etree._ElementInterface = _ElementInterface
def SubElement(parent, tag, attrib={}, **extra):
""" Replace SubElement factory func with one that also sets an Element's parent. """
@waylan
waylan / html_tidy.py
Created March 13, 2013 14:28
Archive of the Python-Markdown HTML Tidy Extension.
# HTML Tidy Extension for Python-Markdown
# =======================================
#
# Runs [HTML Tidy][] on the output of Python-Markdown using the [uTidylib][]
# Python wrapper. Both libtidy and uTidylib must be installed on your system.
#
# [HTML Tidy]: http://tidy.sourceforge.net/
# [uTidylib]: http://utidylib.berlios.de/
#
# Note than any Tidy [options][] can be passed in as [extension configs][]. So,
@waylan
waylan / knockback-relations.html
Created April 29, 2013 16:52
An attempt at backbone-relational with knockback. Not sure why this isn't working. What am I missing?
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Sample</title>
<link rel="stylesheet" href="base.css">
</head>
<body>
@waylan
waylan / .vimrc
Created August 13, 2013 16:12
A very basic .vimrc file
" whitespace
set tabstop=4
set shiftwidth=4
set smarttab
set expandtab
set softtabstop=4
set autoindent
" Search settings
set incsearch