Skip to content

Instantly share code, notes, and snippets.

import urllib, urllib2, json
class CanLIIException(Exception):
def __str__(self):
return repr(self.args)
class CanLII(object):
def __init__(self, api_key, language = 'en'):
self.address = ""
wardi /
Last active Dec 15, 2015
clean up tags for ckan
# -*- coding: UTF-8 -*-
N = u"skjfhaslkdjfh lèdf&^%*sdklfjh alskjdJHGKjÄfh ()"
import re
def clean(x):
return u''.join(re.findall(u'[\w\-.]+ ?', x, re.UNICODE)).rstrip()
wardi /
Last active Dec 14, 2015
fun with dots
D = """
xx xxxx
xxxxxxxxxxxx xxx
xxxxxxxxxxxxx xxxx
xxxxxxxxxxxxx xxxx
xxxx xxxx
xxxx xxxxxxxxxxxxx
wardi / gist:4113436
Created Nov 19, 2012
An incomplete toy RTL text layout class for Urwid
View gist:4113436
import urwid
from urwid.util import calc_width
class RTLTextLayout(urwid.TextLayout):
A toy text layout that arranges all characters from
right to left.
Only works with unicode strings and narrow characters
Currently fails if text is too long for the line
wardi / gist:4098030
Created Nov 17, 2012
splitting on | with escaped \|'s and escaped \\'s
View gist:4098030
def split_bars(v):
i = iter(v.split('|'))
while True:
part = next(i)
while part.endswith('\\'):
part = part[:-1] + '|' + next(i)
yield part.replace('\\\\', '\\')