docs(knowledge): reorganize knowledge base and add new guides
Restructure the knowledge/ directory by sorting guides into domain-specific subdirectories to improve vault organization and scannability: - devenv/: environments and shell configurations - dsa/: data structures and algorithms (hashmaps) - python/: language features (enumerate, zip) - tools/: containerization and utilities (docker, tmux) - skills/: backend competencies (auth, sql, testing, and new pydantic guide) Update relative links in SKILLS.md and knowledge guides to track unpacking and, track Obsidian vault configurations.
This commit is contained in:
1 parent
34af421925
commit
bd069cc275
18 files changed
+268
-18
No files matched your search
+2
-1
@@ -1,3 +1,4 @@
|
||||
.envrc
|
||||
.agents/
|
||||
.obsidian/workspace.json
|
||||
.obsidian/
|
||||
.venv/
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"alwaysUpdateLinks": true
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{}
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"file-explorer": true,
|
||||
"global-search": true,
|
||||
"switcher": true,
|
||||
"graph": true,
|
||||
"backlink": true,
|
||||
"canvas": true,
|
||||
"outgoing-link": true,
|
||||
"tag-pane": true,
|
||||
"footnotes": false,
|
||||
"properties": true,
|
||||
"page-preview": true,
|
||||
"daily-notes": true,
|
||||
"templates": true,
|
||||
"note-composer": true,
|
||||
"command-palette": true,
|
||||
"slash-command": false,
|
||||
"editor-status": true,
|
||||
"bookmarks": true,
|
||||
"markdown-importer": false,
|
||||
"zk-prefixer": false,
|
||||
"random-note": false,
|
||||
"outline": true,
|
||||
"word-count": true,
|
||||
"slides": false,
|
||||
"audio-recorder": false,
|
||||
"workspaces": false,
|
||||
"file-recovery": true,
|
||||
"publish": false,
|
||||
"sync": true,
|
||||
"bases": true,
|
||||
"webviewer": false
|
||||
}
|
||||
@@ -4,13 +4,13 @@ Use this matrix to track your confidence and interview readiness for key backend
|
||||
|
||||
| Skill | Confidence | Interview Ready | Linked Notes |
|
||||
| :--- | :---: | :---: | :--- |
|
||||
| **Python** | 3/5 | 🟨 | [[knowledge/testing]] |
|
||||
| **Python** | 3/5 | 🟨 | [[testing]] |
|
||||
| **Git & GitHub** | 4/5 | 🟩 | - |
|
||||
| **FastAPI** | 2/5 | 🟥 | [[knowledge/auth]] |
|
||||
| **SQL & PostgreSQL** | 2/5 | 🟥 | [[knowledge/sql]] |
|
||||
| **Docker & Compose** | 2/5 | 🟥 | [[knowledge/docker]] |
|
||||
| **Testing (pytest)** | 1/5 | 🟥 | [[knowledge/testing]] |
|
||||
| **JWT & RBAC** | 1/5 | 🟥 | [[knowledge/auth]] |
|
||||
| **FastAPI** | 2/5 | 🟥 | [[auth]] |
|
||||
| **SQL & PostgreSQL** | 2/5 | 🟥 | [[sql]] |
|
||||
| **Docker & Compose** | 2/5 | 🟥 | [[docker]] |
|
||||
| **Testing (pytest)** | 1/5 | 🟥 | [[testing]] |
|
||||
| **JWT & RBAC** | 1/5 | 🟥 | [[auth]] |
|
||||
|
||||
*Status Legend:*
|
||||
- 🟥 Not Ready (Cannot explain under interview pressure)
|
||||
|
||||
File renamed without changes.
File renamed without changes.
@@ -185,7 +185,7 @@ for fruit, quantity in inventory.items():
|
||||
# Today we have 8 oranges
|
||||
```
|
||||
|
||||
When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the [`enumerate()`](./enumerate) function.
|
||||
When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the [`enumerate()`](../python/enumerate.md) function.
|
||||
|
||||
```python
|
||||
for i, (fruit, quantity) in enumerate(inventory.items(), start=1):
|
||||
@@ -9,4 +9,5 @@ Topics worth studying after they become relevant.
|
||||
- [ ] Robin Hood hashing
|
||||
- [ ] Skip Lists
|
||||
|
||||
|
||||
## Python Features
|
||||
- [ ] Sequence and Dictionary unpacking (`*`, `**`)
|
||||
@@ -4,8 +4,6 @@ If you spend enough time writing Python, you will eventually find yourself needi
|
||||
|
||||
Imagine you are building a simple command-line application and you want to print a numbered menu of options:
|
||||
|
||||
Python
|
||||
|
||||
```python
|
||||
fruits = ["apple", "banana", "orange"]
|
||||
```
|
||||
@@ -118,8 +116,6 @@ If the answer is yes, `enumerate` is usually the right choice. Here are a few co
|
||||
|
||||
Displaying human-readable lists to users.
|
||||
|
||||
|
||||
|
||||
```Python
|
||||
for number, option in enumerate(menu, start=1):
|
||||
print(f"Press {number} for {option}")
|
||||
@@ -129,7 +125,6 @@ for number, option in enumerate(menu, start=1):
|
||||
|
||||
Searching for a specific element and returning its index.
|
||||
|
||||
|
||||
```Python
|
||||
for index, user in enumerate(users):
|
||||
if user.id == target_id:
|
||||
@@ -140,8 +135,6 @@ for index, user in enumerate(users):
|
||||
|
||||
When you need to modify the original list based on the items currently inside it.
|
||||
|
||||
|
||||
|
||||
```Python
|
||||
for i, value in enumerate(numbers):
|
||||
numbers[i] = value * 2
|
||||
@@ -162,8 +155,6 @@ Imagine someone walking beside your list carrying a mechanical tally clicker. Ev
|
||||
3. You receive both together.
|
||||
|
||||
|
||||
|
||||
|
||||
```Plaintext
|
||||
apple ← the item
|
||||
0 ← the click
|
||||
@@ -0,0 +1,181 @@
|
||||
# Quick Guide to Python's `zip()`
|
||||
If you spend enough time writing Python, you will eventually find yourself needing to loop over two or more related lists at the same time.
|
||||
|
||||
Imagine you are processing user data and have two separate lists—one for names and one for test scores:
|
||||
|
||||
```python
|
||||
names = ["Luisa", "Nathalia", "Daniela", "Elizabeth", "Camila", "Jennifer"]
|
||||
scores = [90, 72, 92, 82, 84, 40]
|
||||
```
|
||||
|
||||
You want the output to match them up logically:
|
||||
|
||||
```text
|
||||
Luisa scored 90
|
||||
Nathalia scored 72
|
||||
Daniela scored 92
|
||||
...
|
||||
```
|
||||
|
||||
Naturally, the first question is: *"How do I pull items from both lists simultaneously?"*
|
||||
|
||||
## The First Solution Most People Write
|
||||
If you are coming from a language like C, C++ or Java, your instinct is to use an index to keep track of your position, then ask both lists for the item at that position:
|
||||
|
||||
```python
|
||||
for i in range(len(names)):
|
||||
print(f"{names[i]} scored {scores[i]}")
|
||||
```
|
||||
|
||||
This works, and it's logically correct. However, it introduces unnecessary complexity. You are forcing yourself to manage the mechanics of an index `i` that you do not actually care about. The index is merely a middleman to get the data you want. Furthermore, if `names` and `scores` happen to be of unequal lengths, this approach risks throwing an `IndexError`.
|
||||
|
||||
What if Python could weave these lists together for you?
|
||||
|
||||
## Introducing `zip()`
|
||||
|
||||
Python provides the built-in function `zip()` exactly for this scenario. Instead of managing an index, you hand the lists directly to `zip()`, which pairs them up.
|
||||
|
||||
If we convert the iterator to a list to peek inside, we obtain:
|
||||
|
||||
```python
|
||||
list(zip(names, scores))
|
||||
# [('Luisa', 90), ('Nathalia', 72), ('Daniela', 92), ('Elizabeth', 82), ('Camila', 84), ('Jennifer', 40)]
|
||||
```
|
||||
|
||||
This reinforces the idea that `zip()` is lazy—it returns an iterator, which we must cast to a list to view all at once.
|
||||
|
||||
If we loop over the `zip()` iterator directly, we see that every iteration yields a paired tuple:
|
||||
|
||||
```python
|
||||
for pair in zip(names, scores):
|
||||
print(pair)
|
||||
```
|
||||
|
||||
Output:
|
||||
```text
|
||||
('Luisa', 90)
|
||||
('Nathalia', 72)
|
||||
('Daniela', 92)
|
||||
...
|
||||
```
|
||||
|
||||
## The Role of Tuple Unpacking
|
||||
|
||||
Only after seeing that `zip()` yields tuples does it become clear how we can use **tuple unpacking** to clean up the loop. Python can split the tuple directly in the loop header:
|
||||
|
||||
```python
|
||||
for name, score in zip(names, scores):
|
||||
print(f"{name} scored {score}")
|
||||
```
|
||||
|
||||
Every time the loop spins, Python instantly splits the yielded tuple into the individual variables you defined:
|
||||
|
||||
```txt
|
||||
('Luisa', 90)
|
||||
↓
|
||||
name = "Luisa"
|
||||
score = 90
|
||||
```
|
||||
|
||||
This completely removes the need for an index variable or bracket notation like `names[i]`. You are interacting directly with the data elements themselves.
|
||||
|
||||
## The Magic of Unzipping with `*` (Iterable unpacking)
|
||||
One question beginners often have is how to reverse the operation.
|
||||
|
||||
Suppose you have a list of paired records from a database query, and you need to split them back into two separate lists:
|
||||
|
||||
```python
|
||||
records = [("Luisa", 85), ("Nathalia", 92), ("Angie", 78)]
|
||||
```
|
||||
|
||||
You can use `zip()` in conjunction with the unpacking operator `*` to pull them apart:
|
||||
|
||||
```python
|
||||
names, scores = zip(*records)
|
||||
|
||||
print(names)
|
||||
# ('Luisa', 'Nathalia', 'Angie')
|
||||
print(scores)
|
||||
# (85, 92, 78)
|
||||
```
|
||||
|
||||
**How does this work?** The `*` operator (unpacking operator) unpacks the `records` iterable into separate positional arguments before `zip()` executes. If you're coming from JavaScript, you'll notice the resemblance to the spread operator (`...`): they take a collection of items and "blast them out" into their individual elements.
|
||||
|
||||
```python
|
||||
numbers = [2, 5, 1]
|
||||
print(numbers)
|
||||
# [2, 5, 1]
|
||||
print(*numbers)
|
||||
# 2 5 1
|
||||
```
|
||||
|
||||
Writing `zip(*records)` is exactly equivalent to writing:
|
||||
|
||||
```python
|
||||
zip(records[0], records[1], records[2])
|
||||
|
||||
# which means:
|
||||
zip(("Luisa", 85), ("Nathalia", 92), ("Angie", 78))
|
||||
```
|
||||
|
||||
`zip()` takes the first item from every tuple (`"Luisa"`, `"Nathalia"`, `"Angie"`), and groups them. Then it takes the second item from every tuple (`85`, `92`, `78`) and groups them. The result is two separate tuples.
|
||||
|
||||
## When should I use it?
|
||||
To decide whether `zip()` is the right tool, ask yourself:
|
||||
|
||||
> ***Do I need to process multiple sequences in parallel?***
|
||||
|
||||
If the answer is yes, `zip()` is the correct choice. Here a few common scenarios:
|
||||
|
||||
**1. Creating Dictionaries:**
|
||||
Fusing two lists into a key-value mapping. This avoids manual iteration entirely.
|
||||
```python
|
||||
keys = ["username", "email", "role"]
|
||||
values = ["kiskaadee", "admin@system.local", "superadmin"]
|
||||
|
||||
user_profile = dict(zip(keys, values))
|
||||
```
|
||||
|
||||
**2. Multi-Variable Calculation**:
|
||||
Calculating results from corresponding elements in multiple data sets.
|
||||
```python
|
||||
prices = [10.00, 15.00, 20.00]
|
||||
quantities = [2, 1, 4]
|
||||
|
||||
total_cost = sum(price * qty for price, qty in zip(prices, quantities))
|
||||
```
|
||||
|
||||
**3. Transposing Matrices**:
|
||||
Pivoting rows into columns (or vice versa) in a 2D grid.
|
||||
```python
|
||||
matrix = [
|
||||
[1, 2, 3],
|
||||
[4, 5, 6]
|
||||
]
|
||||
|
||||
transposed = list(zip(*matrix))
|
||||
```
|
||||
|
||||
## The Mental Picture
|
||||
To fully grasp `zip()`, visualize a literal zipper on a jacket.
|
||||
1. One sequence represents the teeth on the left
|
||||
2. The other sequence represents the teeth on the right
|
||||
3. As you pull the slider down, it locks the corresponding left and right teeth together into a single unit.
|
||||
|
||||
Like `enumerate()`, `zip()` is lazy. It does not construct a massive list of tuples in memory all at once. It yields one pair at a time, making it highly efficient for processing massive files or data streams.
|
||||
|
||||
## The Shortest-Length Trade-Off
|
||||
A real jacket zipper stops working if one side is missing teeth. Python's `zip()` behaves similarly: it stops as soon as the *shortest* iterable is exhausted. Any remaining items in the longer list are silently ignored.
|
||||
|
||||
If losing data silently is a risk for your application, you have two options to manage this trade-off:
|
||||
- Use `zip(a, b, strict=True)` (Python 3.10+), which intentionally throws an error if the lists are different lengths.
|
||||
- Use `itertools.zip_longest()`, which pads the missing spaces with `None` (or a filler value) instead of truncating.
|
||||
|
||||
## One Principle to Remember
|
||||
You do not need to memorize edge cases to start using this tool. Rely on this heuristic:
|
||||
|
||||
Whenever you find yourself writing `[i]` multiple times inside a loop to access elements from different lists, pause and ask yourself:
|
||||
|
||||
> ***"Am I trying to move through these lists at the same time?"***
|
||||
|
||||
If the answer is yes, consider using `zip()`.
|
||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,39 @@
|
||||
# Introduction to Pydantic
|
||||
Notes during my Pydantic documentation review;
|
||||
## Why does Pydantic exist?
|
||||
|
||||
↓
|
||||
|
||||
## What problem does it solve?
|
||||
|
||||
↓
|
||||
|
||||
## What is a BaseModel?
|
||||
|
||||
↓
|
||||
|
||||
## How does validation work?
|
||||
|
||||
↓
|
||||
|
||||
## How does FastAPI use Pydantic?
|
||||
|
||||
↓
|
||||
|
||||
## Input models vs output models
|
||||
|
||||
↓
|
||||
|
||||
## Field validation
|
||||
|
||||
↓
|
||||
|
||||
## Custom validators
|
||||
|
||||
↓
|
||||
|
||||
## Serialization
|
||||
|
||||
↓
|
||||
|
||||
## Configuration
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user