Skip to content

Instantly share code, notes, and snippets.

View CKAN data model
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<graphml xmlns="" xmlns:xsi="" xmlns:y="" xmlns:yed="" xsi:schemaLocation="">
<!--Created by yEd 3.12.2-->
<key for="graphml" id="d0" yfiles.type="resources"/>
<key for="port" id="d1" yfiles.type="portgraphics"/>
<key for="port" id="d2" yfiles.type="portgeometry"/>
<key for="port" id="d3" yfiles.type="portuserdata"/>
<key"url" attr.type="string" for="node" id="d4"/>
<key"description" attr.type="string" for="node" id="d5"/>
<key for="node" id="d6" yfiles.type="nodegraphics"/>
View gist:a22b65aeee409283c0b9
>>> timeit.timeit("np.array([42]*10000, dtype=float)", "import numpy as np", number=15000)
>>> timeit.timeit("np.ones(10000, dtype=float) * 42", "import numpy as np", number=15000)
>>> timeit.timeit("np.multiply(np.ones(10000, dtype=float), 42)", "import numpy as np", number=15000)
View gist:19bd4ecb17cdaa896c83
>>> dis.dis(lambda: 10000/2 + 1)
1 0 LOAD_CONST 1 (10000)
3 LOAD_CONST 2 (2)
7 LOAD_CONST 3 (1)
View gist:744d3bb721b0009df9b5
#!/usr/bin/env python
import urwid
thing_to_wrap = urwid.Text(' '.join(str(n) for n in range(1000, 1115)))
right_shadow = urwid.Pile([
(1, urwid.SolidFill(' ')),
bottom_shadow = urwid.Columns([
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('\\\\', '\\')
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 /
Last active Dec 14, 2015
fun with dots
D = """
xx xxxx
xxxxxxxxxxxx xxx
xxxxxxxxxxxxx xxxx
xxxxxxxxxxxxx xxxx
xxxx xxxx
xxxx xxxxxxxxxxxxx
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()
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 / gist:8337153
Created Jan 9, 2014
urwid text layout that fills with underscores on the right (works with wide and combining characters too!)
View gist:8337153
import urwid
class UnderscoreRight(urwid.StandardTextLayout):
def layout(self, text, width, align, wrap):
s = urwid.StandardTextLayout.layout(self, text, width, align, wrap)
out = []
last_offset = 0
for row in s:
used = 0
for seg in row: