Skip to content

Commit 577befb

Browse files
Reorg
Move bulk of README.md to markdown directory, update TOC and relative URLs
1 parent 362400f commit 577befb

File tree

14 files changed

+586
-586
lines changed

14 files changed

+586
-586
lines changed

README.md

Lines changed: 6 additions & 586 deletions
Large diffs are not rendered by default.

markdown/asdf.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
### asdf
2+
3+
* Install from the [Setup](../README.md#setup) section
4+
* WSL/Ubuntu Linux dependencies
5+
```bash
6+
sudo apt update && sudo apt install \
7+
make build-essential libssl-dev zlib1g-dev \
8+
libbz2-dev libreadline-dev libsqlite3-dev wget \
9+
curl llvm libncursesw5-dev xz-utils tk-dev \
10+
libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
11+
```
12+
* Fedora dependencies
13+
```bash
14+
sudo dnf install -y bzip2-devel libsqlite3x-devel
15+
```
16+
* All operating systems
17+
```bash
18+
# add python plugin
19+
asdf plugin-add python
20+
21+
# install stable python
22+
asdf install python latest
23+
24+
# uninstall version
25+
asdf uninstall python 3.9.6
26+
27+
# refresh symlinks for installed python runtimes
28+
asdf reshim python
29+
30+
# set stable to system python
31+
asdf global python latest
32+
33+
# optional: local python (e.g., python 3.9.10)
34+
cd $work_dir
35+
asdf list-all python 3.9
36+
asdf install python 3.9.10
37+
asdf local python 3.9.10
38+
39+
# verify python shim in use
40+
asdf current
41+
42+
# check installed python
43+
asdf list python
44+
```
45+
46+
#### Debugging
47+
**No version set for command python**
48+
* Make sure `python` or `python3` isn't aliased in `~/.bashrc` or `~/.zshrc`
49+
50+
[bash - Is it possible to check where an alias was defined? - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/322459/is-it-possible-to-check-where-an-alias-was-defined/544970#544970)
51+
52+
##### PATH
53+
* `asdf`, `poetry`, and `python` all need to be sourced in your shell `$PATH` in a specific order
54+
* `asdf` stores its Python shims in `~/.asdf/shims`
55+
* `poetry` lives in `~/.local/bin`
56+
```bash
57+
export ASDF_DIR="$HOME/.asdf"
58+
export PATH="$ASDF_DIR/shims:$HOME/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
59+
```
60+
* Furthermore, any aliases or alias files need to be sourced as well
61+
```bash
62+
. "$ASDF_DIR/asdf.sh"
63+
. "$ASDF_DIR/completions/asdf.bash"
64+
. /usr/local/etc/profile.d/poetry.bash-completion
65+
```

markdown/django.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
### Django
2+
3+
* Follow the official [Django Docker Compose article](https://docs.docker.com/samples/django/)
4+
* `cd django`
5+
* Generate the server boilerplate code
6+
```bash
7+
docker-compose run web django-admin startproject composeexample .
8+
```
9+
* Fix upstream import bug and whitelist all hosts/localhost
10+
```bash
11+
$ vim composeexample/settings.py
12+
import os
13+
...
14+
ALLOWED_HOSTS = ["*"]
15+
```
16+
* Profit
17+
```bash
18+
docker-compose up
19+
```
20+
* **Optional**: Comment out Django exclusions for future commits
21+
* Assumed if extracting Django boilerplate from template and creating a new repo
22+
```bash
23+
# .gitignore
24+
# ETC
25+
# django/composeexample/
26+
# django/data/
27+
# django/manage.py
28+
```

markdown/docker.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
### Docker
2+
3+
* Install from the [Setup](../README.md#setup) section
4+
* Usage
5+
```bash
6+
# clean build (remove `--no-cache` for speed)
7+
docker-compose build --no-cache --parallel
8+
9+
# start container
10+
docker-compose up --remove-orphans -d
11+
12+
# exec into container
13+
docker attach hello
14+
15+
# run command inside container
16+
python hello.py
17+
18+
# stop container
19+
docker-compose stop
20+
21+
# destroy container and network
22+
docker-compose down
23+
```
24+
25+
#### Debugging
26+
* Watch logs in real-time: `docker-compose logs -tf --tail="50" hello`
27+
* Check exit code
28+
```bash
29+
$ docker-compose ps
30+
Name Command State Ports
31+
------------------------------------------------------------------------------
32+
docker_python python manage.py runserver ... Exit 0
33+
```

markdown/gh_actions.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
### GitHub Actions
2+
3+
#### Update submodules recursively
4+
* Add the submodule to the downstream repo
5+
```bash
6+
git submodule add https://github.com/pythoninthegrass/automate_boring_stuff.git
7+
git commit -m "automate_boring_stuff submodule"
8+
git push
9+
```
10+
* Create a personal access token called `PRIVATE_TOKEN_GITHUB` with `repo` permissions on the downstream repo
11+
* `repo:status`
12+
* `repo_deployment`
13+
* `public_repo`
14+
* Add that key to the original repo
15+
* Settings > Security > Secrets > Actions
16+
* New repository secret
17+
* Setup a new Action workflow
18+
* Actions > New Workflow
19+
* Choose a workflow > set up a workflow yourself
20+
```bash
21+
# main.yml
22+
# SOURCE: https://stackoverflow.com/a/68213855
23+
name: Send submodule updates to parent repo
24+
25+
on:
26+
push:
27+
branches:
28+
- main
29+
- master
30+
31+
jobs:
32+
update:
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- uses: actions/checkout@v2
37+
with:
38+
repository: username/repo_name
39+
token: ${{ secrets.PRIVATE_TOKEN_GITHUB }}
40+
41+
- name: Pull & update submodules recursively
42+
run: |
43+
git submodule update --init --recursive
44+
git submodule update --recursive --remote
45+
- name: Commit
46+
run: |
47+
git config user.email "actions@github.com"
48+
git config user.name "GitHub Actions - update submodules"
49+
git add --all
50+
git commit -m "Update submodules" || echo "No changes to commit"
51+
git push
52+
```

markdown/kubernetes.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
### Kubernetes (k8s)
2+
3+
* Easiest way to set up a local single node cluster is via one of the following:
4+
* [Rancher Desktop](https://docs.rancherdesktop.io/getting-started/installation)
5+
* [minikube](https://minikube.sigs.k8s.io/docs/start/)
6+
* Incidentally, `minikube` ships with the Kubernetes Dashboard
7+
```bash
8+
minikube dashboard
9+
```
10+
* The boilerplate [Terraform plan](#terraform) below hasn't been tested against `minikube`
11+
* [multipass](https://multipass.run/) with [microk8s](https://ubuntu.com/tutorials/getting-started-with-kubernetes-ha#1-overview)
12+
* Add aliases to `~/.bashrc` or `~/.zshrc`
13+
```bash
14+
# k8s
15+
alias k="kubectl"
16+
alias kc="kubectl config use-context"
17+
alias kns='kubectl config set-context --current --namespace'
18+
alias kgns="kubectl config view --minify --output 'jsonpath={..namespace}' | xargs printf '%s\n'"
19+
KUBECONFIG="$HOME/.kube/config:$HOME/.kube/kubeconfig:$HOME/.kube/k3s.yaml"
20+
```
21+
* CLI/TUI (terminal user interface) management of k8s
22+
* [k9s](https://github.com/derailed/k9s#installation)
23+
* Built-in help: type `?`
24+
* Main Screen: `:pod`
25+
![Main screen](img/k9s_main.png)
26+
* Describe a pod: `d`
27+
![Describe a pod](img/k9s_describe.png)
28+
* Delete a pod:
29+
* `ctrl-d`
30+
* Replicas rebuild
31+
![Delete a pod](img/k9s_delete_pod.png)
32+
* Remove resource (permanent)
33+
* `:deploy`
34+
* `ctrl-d`
35+
![Remove resource](img/k9s_remove_res.png)
36+
* [POC](https://itnext.io/simplest-minimal-k8s-app-tutorial-with-rancher-desktop-in-5-min-5481edb9a4a5)
37+
```bash
38+
git clone https://github.com/jwsy/simplest-k8s.git
39+
k config get-contexts # should have `rancher-desktop` selected
40+
kc rancher-desktop # switch to rancher context if not
41+
k create namespace simplest-k8s
42+
k apply -n simplest-k8s -f simplest-k8s
43+
k delete -n simplest-k8s -f simplest-k8s
44+
k delete namespace simplest-k8s
45+
```
46+
* Navigate to https://jade-shooter.rancher.localhost/ in Chrome
47+
* Allow self-signed cert
48+
* Profit 💸

markdown/mongo.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
### MongoDB
2+
3+
* See [Docker](#docker) section above
4+
* Setup empty DB as a detached container with port 27017 mapped
5+
```bash
6+
# start mongodb docker container
7+
docker run --name mongodb -d -p 27017:27017 mongo
8+
9+
# stop container
10+
docker stop mongodb
11+
```
12+
* Access DB
13+
* **GUI**: Install [MongoDB Compass](https://www.mongodb.com/try/download/compass)
14+
![compass](img/compass.png)
15+
* **Shell**
16+
```bash
17+
# install mongo client
18+
asdf install mongodb latest
19+
20+
# open client with defaults (mongodb://localhost:27017)
21+
mongo
22+
23+
# list databases
24+
show dbs
25+
```
26+
* **Python** (ayyyy)
27+
```python
28+
# ./nosql/mongo/mongo_mvp.py
29+
import pymongo
30+
31+
client = pymongo.MongoClient('mongodb://localhost:27017/')
32+
db = client["music"]
33+
collection = db["albums"]
34+
data = { "artist": "Grimes", "album": "Miss Anthropocene" }
35+
collection.insert_one(data)
36+
client.close()
37+
```

markdown/pip.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
### pip
2+
3+
If a basic virtual environment (`venv`) and `requirements.txt` are all that's needed, can use built-in tools.
4+
```bash
5+
# create a virtual environment via python
6+
## built-in
7+
python3 -m venv .venv
8+
9+
## faster
10+
python3 -m pip install virtualenv # _or_ pipx install virtualenv
11+
virtualenv .venv
12+
13+
# activate virtual environment
14+
source .venv/bin/activate
15+
16+
# install dependencies
17+
python3 -m pip install requests inquirer
18+
19+
# generate requirements.txt
20+
python3 -m pip freeze > requirements.txt
21+
22+
# exit virtual environment
23+
deactivate
24+
```

markdown/pipx.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
### Pipx
2+
3+
* Install
4+
```bash
5+
# macOS
6+
brew install pipx
7+
pipx ensurepath
8+
9+
# Linux
10+
python3 -m pip install --user pipx
11+
python3 -m pipx ensurepath
12+
13+
# ~/.bashrc
14+
eval "$(register-python-argcomplete pipx)"
15+
export PIPX_DEFAULT_PYTHON="$ASDF_DIR/shims/python"
16+
```
17+
18+
* Usage
19+
```bash
20+
# install package
21+
pipx install pycowsay
22+
23+
# list packages
24+
pipx list
25+
26+
# run without install (i.e., npx)
27+
pipx run pycowsay moooo!
28+
29+
# install a package then add a dependency
30+
pipx install nox
31+
pipx inject nox nox-poetry
32+
```
33+
34+
[pipx](https://pypa.github.io/pipx/)

markdown/playwright.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### Playwright
2+
3+
* Install from the [Setup](../README.md#setup) section
4+
* Usage
5+
```bash
6+
# install
7+
pip install --upgrade pip
8+
pip install playwright
9+
playwright install
10+
11+
# download new browsers (chromedriver, gecko)
12+
npx playwright install
13+
14+
# generate code via macro
15+
playwright codegen wikipedia.org
16+
```
17+
* If `asdf` gives you lip
18+
```bash
19+
# No preset version installed for command playwright
20+
asdf reshim python
21+
```

0 commit comments

Comments
 (0)