Skip to content

Instantly share code, notes, and snippets.

@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: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([
>>> 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
>>> 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
<?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"/>