Skip to content

Instantly share code, notes, and snippets.

View markrwilliams's full-sized avatar

Mark Williams markrwilliams

View GitHub Profile
import re
urldecoder = re.compile('%([0-9a-fA-F]{2})')
def urldecode(s):
bs = bytearray(s)
offset = 0
for encoded in urldecoder.finditer(s):
start, end = encoded.span()
bs[start + offset:end + offset] = chr(int(encoded.group(1), 16))
import re
URL = re.compile('^((?P<scheme>[^:/?#]+):)?'
'(//(?P<authority>[^/?#]*))?'
'(?P<path>[^?#]*)'
'(\?(?P<query>[^#]*))?'
'(#(?P<fragment>.*))?')
print URL.match('http://fake.com:8080/search?q=123&business=Nothing%20Special').groupdict()
import sys
import opcode
import struct
OPNAME = struct.Struct('B')
ARG = struct.Struct('H')
class Symbol(object):
(defun python-swap-quotes ()
(interactive)
(save-excursion
(let ((state (syntax-ppss)))
(when (eq 'string (syntax-ppss-context state))
(let* ((left (nth 8 state))
(right (1- (scan-sexps left 1)))
(newquote (if (= ?' (char-after left))
?\" ?')))
(dolist (loc (list left right))
IN, OUT = object(), object()
def parse(raw):
state = OUT
parsed = []
count = 0
for c in raw:
if c == '(':
if state is OUT: