This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import opcode | |
import struct | |
OPNAME = struct.Struct('B') | |
ARG = struct.Struct('H') | |
class Symbol(object): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IN, OUT = object(), object() | |
def parse(raw): | |
state = OUT | |
parsed = [] | |
count = 0 | |
for c in raw: | |
if c == '(': | |
if state is OUT: |
NewerOlder