Python Data Science Snippets

This article needs update! Jupyter Installation pip in venv mkdir newdir && cd newdir python -m venv .venv (1) source .venv/bin/activate (2) pip install jupyter numpy pandas sqlalchemy (3) pip freeze > requirements.txt (4) python -m jupyter lab (5) deactivate (6) 1 create a new virtual environment 2 activate the environment 3 install several libraries into the activated environment 4 create a list with all dependencies install for sharing or reinstallation later 5 start jupyter 6 having finished we might want to exit the virtual environment ...

July 8, 2020 · 2 min · 244 words · Micha Kops

Docker Snippets

Restrict Network Can be useful when using a third-party image that we do not trust Run with no network docker run --network none <image> Run with private isolated network At least containers attached to this network can talk with another docker network create --internal my_isolated_network docker run --network my_isolated_network <image> Block using firewall e.g. using iptables or ipfw # Get container's IP docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name> # Block all outbound connections from that IP sudo iptables -I DOCKER-USER -s <container_ip> -j DROP ...

March 1, 2010 · 3 min · 452 words · Micha Kops

Java Snippets

Remote Debug a Pod’s Java Process Simple steps for remote debugging a Java process running on a k8 pod: Edit deployment and add the following parameters to the Java start line: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005 Also add the following port mapping at the section container → ports in the deployment: - containerPort: 5005 protocol: TCP Safe, wait for the new pods and then add a port forward for port 5005 for this pod: kubectl port-forward podname 5005 ...

March 1, 2010 · 13 min · 2599 words · Micha Kops

Linux Snippets

These are not only linux snippets but also bash snippets and snippets using tools that run under Linux, *nix or sometimes even MacOSX, I should reorder this article someday ;) Settings for more reliable bash scripts set -euo pipefail this gives us …​ -e: exit script if a single command fails -u: exit script if an unset variable is used -o pipefail: return value of a pipeline is the status of the last command to exit with a non-zero status, or zero if no command exited with a non-zero status ...

March 1, 2010 · 17 min · 3541 words · Micha Kops