Skip to content

Instantly share code, notes, and snippets.

@a-recknagel
a-recknagel / .py
Created August 20, 2018 10:16
assex test, 3.8 pre alpha
>>> f = lambda x: (max(x) - y := min(x)) / y
File "<stdin>", line 1
SyntaxError: can't assign to operator
>>> f = lambda x: (max(x) - (y := min(x))) / y
>>> f([1, 2, 3, 4, 5])
4.0
@a-recknagel
a-recknagel / .py
Created August 20, 2018 10:49
assex leaking listcomp
>>> total = 0
>>> [total := total + v for v in [1, 2, 3]]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <listcomp>
UnboundLocalError: local variable 'total' referenced before assignment
>>> total # ?!?!
0 # D=
>>> [(total := total + v) for v in values] # parantheses don't solve the problem
Traceback (most recent call last):
@a-recknagel
a-recknagel / .py
Created September 7, 2018 11:30
Why? D:
class Immortal:
def __del__(self):
global x
x = self
x = Immortal()
del x
del x
del x # NameError: name 'x' is not defined
@a-recknagel
a-recknagel / .py
Created November 8, 2018 18:31
shifted image similarity feature
image_a = [
[1,0,0,0,1,0,1],
[0,1,0,1,0,0,1],
[0,1,0,0,0,1,1],
[0,0,1,1,1,0,0],
[0,0,0,0,1,1,1],
[0,1,0,0,0,1,1],
[0,0,0,1,1,1,0],
]
image_b = [
@a-recknagel
a-recknagel / .py
Created December 12, 2018 20:00
Context manager with __exit__ having access __enter__'s returned value
from functools import lru_cache
class File:
def __init__(self, filename, mode):
self.filename = filename
self.mode = mode
@lru_cache(1)
def __enter__(self):
@a-recknagel
a-recknagel / AoC data
Created December 17, 2018 14:50
my custom input for AoC day 17
y=1230, x=524..528
y=977, x=460..462
y=1757, x=566..584
y=849, x=500..502
y=1269, x=413..418
y=1045, x=469..473
x=574, y=475..495
y=1349, x=395..404
x=470, y=689..699
y=484, x=444..447
@a-recknagel
a-recknagel / AoC result
Created December 17, 2018 14:51
My buggy result, score = 30746
...................................................................................................................................+.....................................................................................
...................................................................................................................................|.....................................................................................
...................................................................................................................................|.....................................................................................
...................................................................................................................................|.....................................................................................
...................................................................................................................................|....................
2019-05-28 10:10:02,431 - waitress - ERROR - Exception while serving /root/pypi/+simple/
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pyramid/tweens.py", line 13, in _error_handler
response = request.invoke_exception_view(exc_info)
File "/usr/local/lib/python3.7/site-packages/pyramid/view.py", line 779, in invoke_exception_view
raise HTTPNotFound
pyramid.httpexceptions.HTTPNotFound: The resource could not be found.
During handling of the above exception, another exception occurred:
@a-recknagel
a-recknagel / Dockerfile
Created June 12, 2019 13:44
build protobuf from master on docker/ubuntu
FROM ubuntu
RUN apt update
RUN apt install -y git make autoconf automake libtool curl make g++ unzip zlib1g-dev build-essential libncursesw5-dev libreadline-gplv2-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev libbz2-dev libffi-dev
RUN git clone https://github.com/python/cpython.git
RUN cd /cpython && git checkout 3.8 && \
./configure && make && make install
RUN git clone https://github.com/protocolbuffers/protobuf.git
RUN cd /protobuf && git submodule update --init --recursive && ./autogen.sh && ./configure && make && make install
RUN cd /protobuf/python/ && python3 setup.py build && python3 setup.py test
@a-recknagel
a-recknagel / installations.sh
Last active July 5, 2019 11:24
Dynamic module reload from given site package
# This script contains instructions that can be used to showcase how the reloader.py script is suppsoed to be used.
# The module reloading itself cotnains only pure python, so the only thing you'll need to run it is a working
# python3 interpreter
# setup start:
$ python3 -m venv env_0_12 # version 0.12 is going to be installed in here ...
$ python3 -m venv env_0_13 # ... and version 0.13 in here
$ env_0_12/bin/python3 -m pip install pyarrow==0.12
[...]
Successfully installed numpy-1.16.4 pyarrow-0.12.0 six-1.12.0