Collision detection of boxes / patterns

This is brilliant: collision detection - What is the fastest way to work out 2D bounding box intersection? - Game Development Stack Exchange

return !(r2.left > r1.right
    || r2.right < r1.left
    || r2.top < r1.bottom
    || r2.bottom > r1.top);

The idea is to capture all possible conditions upon which the rectangles will not overlap, and then negate the answer to see if they are overlapped

Originally from here: Rectangle Intersection – Determine if two given rectangles intersect each other or not « Technical Interview Questions

Doing it straight-forwardly would require more conditions.

Surprisingly intuitive and shows once more that when finding the answer is too hard, trying to find the answer to an opposite question might help you out.

python moving virtualenv makes it use the system default python/pip paths

Python venv (virual environment) uses wrong version of Python - Stack Overflow:

As an addition to the accepted answer, be also aware that changing the directory name where your venv is located causes using the default python and pip paths of your system, instead of using the venv one.

This explains so much!

To make an existing virtualenv movable

not included in the new venv. :( 1

No easy official way, reinstalling is much easier.

To find out where a certain package is installed, pip list -v.

Basic Slack bot

import os
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError

client = WebClient(token=os.environ['SLACK_BOT_TOKEN'])

try:
    response = client.chat_postMessage(channel='vision-trainings', text="Hello world!")
    assert response["message"]["text"] == "Hello world!"
except SlackApiError as e:
    # You will get a SlackApiError if "ok" is False
    assert e.response["ok"] is False
    assert e.response["error"]  # str like 'invalid_auth', 'channel_not_found'
print(f"Got an error: {e.response['error']}")

Intellij idea applying only some changes from commit in another branch

Find that branch in git log, right click on the file(s) you want, “Apply selected changes”. 2 (“Cherry-pick selected changes” according to Help)

matplotlib add colorbar

fig = plt.figure(figsize=(20, 15))
ax = plt.subplot(132)

#plt.gcf().tight_layout(rect=[0, 0, 1, 0.90])
plt.gcf().tight_layout()

fig.subplots_adjust(right=0.9)
cbar_ax = fig.add_axes([0.92, 0.10, 0.04, 0.8])
if heatmap is not None:
	fig.colorbar(heatmap, cax=cbar_ax)

Confluence page info

Shows incoming and outgoing links, useful to look for other places with similar info.