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 = "http://api.canlii.org/v1/"
@wardi
wardi / clean_tags.py
Last active December 15, 2015 00:28
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
wardi / braille_paint.py
Last active December 14, 2015 18:48
fun with dots
D = """
xxxxxx
xx xxxx
xxxxxxxx
xxxx
xxxxxxxxxxxx xxx
xxxxxxxxxxxxx xxxx
xxxxxxxxxxxxx xxxx
xxxx xxxx
xxxx xxxxxxxxxxxxx
@wardi
wardi / gist:4113436
Created November 19, 2012 19:56
An incomplete toy RTL text layout class for Urwid
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 November 17, 2012 17:41
splitting on | with escaped \|'s and escaped \\'s
def split_bars(v):
i = iter(v.split('|'))
while True:
part = next(i)
while part.endswith('\\'):
part = part[:-1] + '|' + next(i)
yield part.replace('\\\\', '\\')