Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xmlns:yed="http://www.yworks.com/xml/yed/3" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
<!--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 attr.name="url" attr.type="string" for="node" id="d4"/>
<key attr.name="description" attr.type="string" for="node" id="d5"/>
<key for="node" id="d6" yfiles.type="nodegraphics"/>
>>> timeit.timeit("np.array([42]*10000, dtype=float)", "import numpy as np", number=15000)
14.971487045288086
>>> timeit.timeit("np.ones(10000, dtype=float) * 42", "import numpy as np", number=15000)
0.5964510440826416
>>> timeit.timeit("np.multiply(np.ones(10000, dtype=float), 42)", "import numpy as np", number=15000)
0.5582938194274902
>>> dis.dis(lambda: 10000/2 + 1)
1 0 LOAD_CONST 1 (10000)
3 LOAD_CONST 2 (2)
6 BINARY_DIVIDE
7 LOAD_CONST 3 (1)
10 BINARY_ADD
@wardi
wardi / gist:744d3bb721b0009df9b5
Created July 9, 2015 22:40
drop shadow in urwid
#!/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(' ')),
urwid.SolidFill('X')])
bottom_shadow = urwid.Columns([
@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('\\\\', '\\')
@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 / 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 / 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()
#...
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 / gist:8337153
Created January 9, 2014 16:30
urwid text layout that fills with underscores on the right (works with wide and combining characters too!)
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: