Skip to content

Instantly share code, notes, and snippets.

View fmayer's full-sized avatar

Florian Mayer fmayer

View GitHub Profile
### 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:
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("-")
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
>>> class A(object):
... def __add__(self, o): return "add"
...
... class B(A):
... def __radd__(self, o): return "radd"
>>> A() + B()
0: 'radd'
>>>
>>> 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
>>>
>>> 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]
>>>
>>> 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
def bin(x):
s = ""
while True:
s += str(x & 1)
x >>= 1
if not x:
break
return '0b' + s[::-1]
import time
import threading
def nothing():
while True: time.sleep(1000)
threading.Thread(target=nothing).start()
>>> 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])