Skip to content

Instantly share code, notes, and snippets.

View pyCanLII.py
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 = "http://api.canlii.org/v1/"
@wardi
wardi / clean_tags.py
Last active Dec 15, 2015
clean up tags for ckan
View clean_tags.py
# -*- 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
wardi / braille_paint.py
Last active Dec 14, 2015
fun with dots
View braille_paint.py
D = """
xxxxxx
xx xxxx
xxxxxxxx
xxxx
xxxxxxxxxxxx xxx
xxxxxxxxxxxxx xxxx
xxxxxxxxxxxxx xxxx
xxxx xxxx
xxxx xxxxxxxxxxxxx
@wardi
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
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('\\\\', '\\')