This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am segfaulthunter on github. | |
* I am segfaulthunter (https://keybase.io/segfaulthunter) on keybase. | |
* I have a public key whose fingerprint is 718A C057 CD9D 2A25 DF8A 1242 E382 DD8D 04F4 9981 | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProgressBar(object): | |
def __init__(self, n, current=0, width=40, output=sys.stdout): | |
self.n = n | |
self.current = current | |
self.width = width | |
self.step = self.n / self.width | |
self.output = output | |
def draw_one(self): | |
self.output.write("-") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mine(object): | |
def __init__(self, id_, x, y, r): | |
self.neighbours = set() | |
self.id_ = id_ | |
self.x = x | |
self.y = y | |
self.r = r | |
self.dead = False | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class A(object): | |
... def __add__(self, o): return "add" | |
... | |
... class B(A): | |
... def __radd__(self, o): return "radd" | |
>>> A() + B() | |
0: 'radd' | |
>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import itertools | |
>>> X = range(8) | |
>>> S = set() | |
... for x, y in itertools.combinations(X, 2): | |
... S |= set(itertools.product([x, y], repeat=8)) | |
>>> len(S) | |
86: 7120 | |
>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def foo(lst): | |
... last = object() | |
... for e in lst: | |
... if e != last: | |
... yield e | |
... last = e | |
>>> list(foo([1,1,1,2,4,1])) | |
0: [1, 2, 4, 1] | |
>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class Yes(str): | |
... def __eq__(self, o): return True | |
>>> "__main__" == Yes("foo") | |
True | |
>>> "__main__".__eq__(Yes("foo")) | |
False | |
>>> class Str(str): | |
... pass | |
>>> Str("__main__") == Yes("foo") | |
False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bin(x): | |
s = "" | |
while True: | |
s += str(x & 1) | |
x >>= 1 | |
if not x: | |
break | |
return '0b' + s[::-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import threading | |
def nothing(): | |
while True: time.sleep(1000) | |
threading.Thread(target=nothing).start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import numpy as np | |
>>> np.array([1, 2, 3]) / 2 | |
array([0, 1, 1]) | |
>>> | |
>>> from __future__ import division | |
>>> import numpy as np | |
>>> np.array([1, 2, 3]) / 2 | |
array([ 0.5, 1. , 1.5]) |
NewerOlder