Skip to content

Commit 6b0e6a9

Browse files
committed
CI/CD automation 🔁 🚀
1 parent 6d91c45 commit 6b0e6a9

27 files changed

Lines changed: 1367 additions & 0 deletions

.github/workflows/deploy-hugo.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# .github/workflows/deploy-hugo.yml
2+
name: Build and Deploy Hugo Site with External Content
3+
4+
on:
5+
push:
6+
branches:
7+
- main # Trigger on push to the main branch of your Hugo site repo
8+
repository_dispatch: # Allows triggering from other repositories
9+
types: [content-updated] # Custom event type to listen for
10+
workflow_dispatch: # Allows manual trigger from GitHub Actions tab
11+
12+
jobs:
13+
build_and_deploy:
14+
runs-on: ubuntu-latest # Or macos-latest, windows-latest
15+
16+
steps:
17+
- name: Checkout Hugo Site Repository
18+
uses: actions/checkout@v4
19+
with:
20+
# If your Hugo site repo itself has submodules (e.g., for themes), enable this
21+
submodules: true
22+
23+
- name: Clone External Content Repository
24+
# This step clones your content repo into the designated content path
25+
# IMPORTANT: Replace 'your-github-username' and 'my-hugo-content'
26+
# You might need a Personal Access Token (PAT) if the content repo is private
27+
# or if you're hitting rate limits for unauthenticated clones.
28+
run: |
29+
echo "Cloning content into content/blog..."
30+
git clone https://github.com/pinnotes/notes.git content/blog
31+
# env:
32+
# If 'my-hugo-content' is private, create a PAT with 'repo' scope
33+
# and add it as a repository secret named 'CONTENT_REPO_PAT'
34+
# GH_TOKEN: ${{ secrets.CONTENT_REPO_PAT }} # Uncomment if content repo is private
35+
36+
- name: Setup Hugo
37+
uses: peaceiris/actions-hugo@v3
38+
with:
39+
hugo-version: 'latest' # Or a specific version like '0.127.0'
40+
extended: true # Essential for SASS/SCSS and some advanced features
41+
42+
- name: Build Hugo Site
43+
# Add any custom build flags, e.g., baseURL if deploying to a subdirectory
44+
run: hugo --minify --baseURL "/" # Adjust baseURL if needed for your hosting
45+
46+
- name: Deploy to GitHub Pages (Example)
47+
# This step assumes you want to deploy to GitHub Pages
48+
# The 'public' directory will be pushed to the 'gh-pages' branch of THIS repo.
49+
uses: peaceiris/actions-gh-pages@v4
50+
if: github.ref == 'refs/heads/main' # Only deploy from main branch pushes
51+
with:
52+
github_token: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub Actions
53+
publish_dir: ./public # Directory containing your built Hugo site
54+
# This will create/update the 'gh-pages' branch for your site.
55+
# If your repo is `user/user.github.io`, it deploys to main branch.
56+
# cname: example.com # Uncomment and set if using a custom domain
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
3+
## 🧮 Function: `is_positive_odd_or_negative_even`
4+
5+
Let's build a Python function that checks if a number is either a **positive odd** or a **negative even**. 🎯
6+
7+
### 🚩 Function Definition
8+
9+
```python
10+
def is_positive_odd_or_negative_even(n):
11+
# Check for positive odd OR negative even
12+
return (n > 0 and n % 2 == 1) or (n < 0 and n % 2 == 0)
13+
```
14+
15+
16+
### 📝 Step-by-Step Explanation
17+
18+
1. **Positive Odd Number:**
19+
- Condition: `n > 0 and n % 2 == 1`
20+
- *Checks if the number is positive AND odd.*
21+
2. **Negative Even Number:**
22+
- Condition: `n < 0 and n % 2 == 0`
23+
- *Checks if the number is negative AND even.*
24+
3. **Logical OR:**
25+
- The function returns `True` if any one of the above conditions is met.
26+
27+
### 🧪 Practice Questions
28+
29+
#### Practice 1
30+
31+
```python
32+
print(is_positive_odd_or_negative_even(7)) # _______
33+
```
34+
35+
- 7 is **positive** and **odd**.
36+
- Output: `True`
37+
38+
39+
#### Practice 2
40+
41+
```python
42+
print(is_positive_odd_or_negative_even(-4)) # _______
43+
```
44+
45+
- -4 is **negative** and **even**.
46+
- Output: `True`
47+
48+
49+
#### Practice 3
50+
51+
```python
52+
print(is_positive_odd_or_negative_even(-3)) # _______
53+
```
54+
55+
- -3 is **negative** and **odd**.
56+
- Output: `False`
57+
58+
59+
#### Practice 4
60+
61+
```python
62+
print(is_positive_odd_or_negative_even(8)) # _______
63+
```
64+
65+
- 8 is **positive** and **even**.
66+
- Output: `False`
67+
68+
69+
#### Practice 5
70+
71+
```python
72+
print(is_positive_odd_or_negative_even(0)) # _______
73+
```
74+
75+
- 0 is neither positive nor negative (and it's even).
76+
- Output: `False`
77+
78+
79+
### ✨ Key Points
80+
81+
- **Odd number:** Remainder when divided by 2 is 1 (`n % 2 == 1`).
82+
- **Even number:** Remainder when divided by 2 is 0 (`n % 2 == 0`).
83+
- **Positive Odd or Negative Even:** Only one of these is needed for `True`.
84+
- **Zero case:** 0 is not positive or negative, so always returns `False`.
85+
86+
Happy Coding! 🚀
87+
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
3+
## 📝 Function: `within_and_has_double_quotes`
4+
5+
Let's build a Python function to check if a string:
6+
7+
- **Starts and ends with double quotes** (`"`)
8+
- **Has at least one double quote** somewhere inside (not including the first and last characters)
9+
10+
11+
### 🧑‍💻 Function Implementation
12+
13+
```python
14+
def within_and_has_double_quotes(s):
15+
# Check if string has at least 2 characters and starts/ends with a double quote
16+
if len(s) < 2 or s[0] != '"' or s[-1] != '"':
17+
return False
18+
# Check for another double quote in the interior (exclude first/last char)
19+
return '"' in s[1:-1]
20+
```
21+
22+
23+
### 🔍 Step-by-Step Explanation
24+
25+
1. **Check the boundary quotes:**
26+
- The string must be at least 2 characters.
27+
- The first character is `"` and the last character is `"`.
28+
2. **Check for an internal quote:**
29+
- Use `s[1:-1]` to get the inner part of the string (excluding first and last characters).
30+
- Test if `"` exists in this interior slice.
31+
32+
### 🧪 Practice Questions
33+
34+
#### Practice 1
35+
36+
```python
37+
print(within_and_has_double_quotes('"hello"')) # _______
38+
```
39+
40+
- Interior: `hello` (no quotes)
41+
- Output: `False`
42+
43+
44+
#### Practice 2
45+
46+
```python
47+
print(within_and_has_double_quotes('"he"llo"')) # _______
48+
```
49+
50+
- Interior: `he"llo`
51+
- Yes, has an interior double quote!
52+
- Output: `True`
53+
54+
55+
#### Practice 3
56+
57+
```python
58+
print(within_and_has_double_quotes('""')) # _______
59+
```
60+
61+
- Interior: empty string `""`
62+
- Output: `False`
63+
64+
65+
#### Practice 4
66+
67+
```python
68+
print(within_and_has_double_quotes('"a"b"c"')) # _______
69+
```
70+
71+
- Interior: `a"b"c`
72+
- Yes, contains double quotes inside!
73+
- Output: `True`
74+
75+
76+
#### Practice 5
77+
78+
```python
79+
print(within_and_has_double_quotes('"no inner quote')) # _______
80+
```
81+
82+
- No ending double quote.
83+
- Output: `False`
84+
85+
86+
### ✅ Key Points
87+
88+
- Checks **boundaries** (`"` at both ends)
89+
- Looks **inside** (middle of string) for at least one more double quote
90+
- Returns `True` *only* if both conditions are met
91+
92+
Happy Coding! 🚀
93+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
3+
## 📝 Function: Replace Middle Element with n Copies
4+
5+
Let's build a helpful Python function that replaces the middle element of a tuple with `n` copies of itself! 🧑‍💻✨
6+
7+
### 🚩 Function Definition
8+
9+
```python
10+
def replace_middle_with_n_copies(t, n):
11+
# Find the middle index
12+
mid = len(t) // 2
13+
# Create a tuple with 'n' copies of the middle element
14+
middle_replacement = (t[mid],) * n
15+
# Build the new tuple: before + replacement + after
16+
return t[:mid] + middle_replacement + t[mid+1:]
17+
```
18+
19+
20+
### 🔍 Step-by-Step Explanation
21+
22+
1. **Find the Middle Index**
23+
- Since the tuple has odd length, the *middle* index is `len(t) // 2`.
24+
2. **Create Replacement**
25+
- `(t[mid],) * n` makes `n` copies of the middle element as a tuple.
26+
3. **Assemble the Result**
27+
- Use slicing: `t[:mid]` (elements before the middle),
28+
`middle_replacement`,
29+
and `t[mid+1:]` (elements after the middle).
30+
31+
### 🤔 Practice Questions
32+
33+
#### Practice 1
34+
35+
```python
36+
t = (1, 2, 3, 4, 5)
37+
n = 3
38+
print(replace_middle_with_n_copies(t, n)) # What do you expect?
39+
```
40+
41+
- Middle element: `3`
42+
- Should be replaced by `(3, 3, 3)`
43+
- **Result:** `(1, 2, 3, 3, 3, 4, 5)`
44+
45+
46+
#### Practice 2
47+
48+
```python
49+
t = ('a', 'b', 'c')
50+
n = 2
51+
print(replace_middle_with_n_copies(t, n))
52+
```
53+
54+
- Middle element: `'b'`
55+
- **Result:** `('a', 'b', 'b', 'c')`
56+
57+
58+
#### Practice 3
59+
60+
```python
61+
t = (10,)
62+
n = 4
63+
print(replace_middle_with_n_copies(t, n))
64+
```
65+
66+
- Single element tuple: replace with 4 copies of itself.
67+
- **Result:** `(10, 10, 10, 10)`
68+
69+
70+
### ✨ Tips
71+
72+
- **Tuples are immutable:** You can’t change them; instead, create and return a new tuple.
73+
- **Odd length guaranteed:** No need to check for even-length inputs.
74+
- Works for any tuple type: numbers, strings, or mixed!
75+
76+
Happy Python-ing! 🐍🚀
77+

0 commit comments

Comments
 (0)