# My Learning Journey

> Welcome to my My Learning Journey repository! This is where I document my journey of continuous learning, discoveries, and insights. Every day, I make it a point to learn something new, whether it's about technology, personal growth, or anything that sparks my curiosity. This repository serves as a record of that journey.

Welcome to my learning repository! This is where I document my day-to-day learnings, findings, and discoveries. Whether it's a new programming concept, a technology I've explored, or a personal insight, you'll find it all here.

## Why I Created This Repository

I believe that continuous learning is key to personal and professional growth. By maintaining this repository, I aim to:

* **Track** my progress over time.
* **Reflect** on what I've learned.
* **Share** my knowledge with others.

Feel free to browse through the day-to-day notes and explore the various topics I've covered. I hope you find something that sparks your interest!

## Timeline

### [December, 2024](/content/2024/december)

* Explore my updates for November 2024, where I've documented day-to-day insights, new skills, and discoveries that have caught my interest.

### [November, 2024](/content/2024/november)

* Explore my updates for November 2024, where I've documented day-to-day insights, new skills, and discoveries that have caught my interest.

### [August, 2024](/content/2024/august)

* Explore my updates for August 2024, where I've documented day-to-day insights, new skills, and discoveries that have caught my interest.


# Timeline

* [2024](/content/2024)


# 2024

[**August**](/content/2024/august)

[**November**](/content/2024/november)

[**December**](/content/2024/december)


# August

* [Day 08](/content/2024/august/day-08)
* [Day 09](/content/2024/august/day-09)
* [Day 10](/content/2024/august/day-10)
* [Day 11](/content/2024/august/day-11)
* [Day 12](/content/2024/august/day-12)
* [Day 19](/content/2024/august/day-19)


# August 08, 2024

## Things That I Discovered

### 1. **Take Out Full Backup of Raspberry Pi SD Card**

* I learned how to create a complete backup of my Raspberry Pi SD card. This will help me preserve all my data and settings before giving away the Raspberry Pi.
* **Reference**: [Backup Raspberry Pi SD Card](https://pimylifeup.com/backup-raspberry-pi/#backing-up-your-raspberry-pi-sd-card-on-linux)

### 2. **Backup Methods**

* **DD Command**: I discovered that using the `dd` command is a powerful way to clone the SD card.
  * Example command: `sudo dd if=/dev/sdX of=/path/to/backup.img bs=4M`
  * **Note**: Replace `/dev/sdX` with the actual device path of your SD card.
* **GUI Tools**: I found GUI tools like `Etcher` that simplify the backup process, making it easier for users who prefer not to use the command line.

### 3. **Exploring Content of Backup Image**

* Since, the image file contents all the partitions of the SD Card, we need calculate the offset for each partition and adjust accordingly. The offsets can be checked by `sudo fdisk -l` command.
* Example command: `sudo mount -o loop,offset=70254592 /path/to/backup-rpi-image.img /mnt/rpi-img`
  * **Note**: This command would mount the image file to `/mnt/rpi-img` directory, so create it beforehand!
* **Reference**: [Access the contents of a .img file](https://learn.pi-supply.com/make/access-the-contents-of-a-img-file/)

### 4. **Compressing Image File**

* Apparently, `dd` command would read and write even empty space to the image file, so we can just compress the image file using `gzip` command.
* Example command: `gzip --keep /path/to/backup-image.img`

### 5. **Importance of Regular Backups**

* I realized the significance of backing up not just the Raspberry Pi but also any critical data regularly. It’s a good practice to have multiple backup strategies.

## Reflections

* Today was productive! Understanding the backup process gives me peace of mind as I prepare to hand over my Raspberry Pi 4.
* I also appreciated how accessible these resources are; the online tutorials made it easy to follow along.


# August 09, 2024

## Things That I Discovered

### 1. **Systemd Services**

* **User-scored Services**: I encountered an issue with a dependency on a non-existent unit `multi-user.target` in a user-scoped service. Resolved it by ensuring that the service doesn't rely on system-level targets.
* **Reference**: [systemd.service - Service Unit Configuration](https://www.freedesktop.org/software/systemd/man/systemd.service.html)

### 2. **Ansible 101 by Jeff Geerling - YouTube Streaming Series**

* I discovered Jeff Geerling's "Ansible 101" YouTube series, which provides a comprehensive introduction to Ansible, making it accessible for beginners and helpful for refreshing foundational concepts.
* **Reference**: Watch the series on YouTube [here](https://www.jeffgeerling.com/blog/2020/ansible-101-jeff-geerling-youtube-streaming-series).

### 3. **Awesome Ansible - GitHub**

* I found a curated list of Ansible resources on GitHub, known as "Awesome Ansible." This list includes books, tutorials, plugins, and tools that can enhance my understanding and usage of Ansible.
* **Notable Sections**:
  * Tools: A variety of tools that extend Ansible’s capabilities.
  * Plugins: Useful plugins that can be integrated into Ansible playbooks for more complex tasks.
  * Community Resources: Links to active communities and forums where I can connect with other Ansible users.
* **Reference**: Explore the repository [here](https://github.com/ansible-community/awesome-ansible).

## Next Steps

* I plan to start watching the "Ansible 101" series from the beginning and take notes on key concepts and practices.
* I’ll begin exploring the "Awesome Ansible" list, starting with tools and plugins that could be immediately useful in my projects.
* Consider documenting what I learn from these resources in my TIL section.


# August 10, 2024

## Things That I Discovered

### 1. **Learn Cloudflare Workers by Kristian Freeman - YouTube Full Video Course**

* I discovered Cloudflare's full course on their Workers offering, from setting up Cloudflare new account to writing code for Workers, deploying it, it got everything covered!
* Watch the full video on YouTube [here](https://www.youtube.com/watch?v=H7Qe96fqg1M).
* **Reference(s)**:
  * [Cloudflare Workers](https://developers.cloudflare.com/workers/)
  * [Hono - Web Framework](https://hono.dev/)
  * [Wrangler](https://developers.cloudflare.com/workers/wrangler/)

### 2. **Stateful Apps with Cloudflare Workers by Kristian Freeman - YouTube Full Video Course**

* Another video on Cloudflare Workers by Kristian Freeman, teaching how to use Cloudflare's Key Value (KV), Serverless SQL Database (D1), Prisma in Cloudflare Workers.
* Watch the full video on YouTube [here](https://www.youtube.com/watch?v=QTsaAhFvX9o)
* **Reference(s)**:
  * [Cloudflare D1 - Serverless SQL Database](https://developers.cloudflare.com/d1/)
  * [Cloudflare KV - Key Value Data Storage](https://developers.cloudflare.com/kv/)
  * [Hono - Web Framework](https://hono.dev/)
  * [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
  * [Prisma - Next-generation ORM for Node.js & TypeScript](https://github.com/prisma/prisma)


# August 11, 2024

## Things That I Discovered

### 1. **Run Ansible Playbook Locally on the Host Machine**

* I learned that we can run Ansible Playbooks directly on the host machine without needing a remote connection. This is particularly useful for scenarios where local configuration management is required or when working with a single machine.
* **Command Example**:

  ```bash
  ansible-playbook --connection=local --inventory 127.0.0.1, playbook_name.yml
  ```
* Further Reading: I’ve documented this in more detail on my TIL website. Check it out [here](https://gitbook.devjugal.com/til/ansible/run-ansible-playbook-locally).

### 2. **How Canva Saved Millions in AWS S3 Costs - YouTube**

* [YouTube Video Link](https://www.youtube.com/watch?v=qcqlbf27CWg)


# August 12, 2024

## Things That I Discovered

### 1. Running a job in container on GitHub Actions

* Recently, I had to run a job on GitHub Actions in a container, ended up writing a TIL for that [here](https://gitbook.devjugal.com/til/github/actions/running-jobs-in-a-container).

### 2. Set Unlimited Bash History

* Unlimited Bash history? Well, why not? Sometimes, I find myself scratching my head trying to find a command that I had run a long time ago!
* We need to set `HISTSIZE` & `HISTFILESIZE` variables of Bash to `-1`.
* To make it permanent for an user, we can set `HISTSIZE` & `HISTFILESIZE` variables in `~/.bashrc` file.
* **Reference**: [bash - Linux Manpages Online](https://man.cx/bash)


# August 19, 2024

## Things That I Discovered

### 1. Logging in Caddy Server

* It's been a long since I've run [Caddy Server](https://caddyserver.com/), but hardly used any logging, thought of exploring logs which is easy to setup.
* **Logging in Caddyfile**:

  ```
  example.domain.com {
      reverse_proxy localhost:8080
      log {
          output file /var/log/caddy/example.domain.com-access.log
      }
  }
  ```
* **Reference**: [Log Caddyfile Directive - Caddy Server Documentation](https://caddyserver.com/docs/caddyfile/directives/log)
* To avoid repeating the same log block again, and we can use snippets instead.
* **Logging using Snippets in Caddyfile**:

  ```
  (logging) {
      log {
          output file /var/log/{args[0]}-access.log
      }
  }
  example.domain.com {
      reverse_proxy localhost:8080
      import logging example.domain.com
  }
  ```
* **Reference**: [Snippets Caddyfile Directive - Caddy Server Documentation](https://caddyserver.com/docs/caddyfile/concepts#snippets)

### 2. Getting Started with Grafana Loki & Promtail

* Today I explored [Grafana Loki](https://grafana.com/docs/loki/latest/) and [Promtail](https://grafana.com/docs/loki/latest/send-data/promtail/) as part of my effort to streamline log access from my remote servers.
* **Grafana Loki**: A horizontally scalable, highly available, multi-tenant log aggregation system inspired by Prometheus.
* **Promtail**: An agent that ships the contents of local logs to a private Loki instance, scraping logs and labeling them for efficient querying.
* This setup will significantly improve my ability to monitor and analyze logs from various servers in a centralized and organized manner.


# November

* [Day 26](/content/2024/november/day-26)


# November 26, 2024

After a long hiatus, back again! Hopefully, this time I will be consistent :)

## Things That I Discovered

### 1. **List Systemd Services Of A User**

* To list the services of a user, we can use `systemctl --user --machine=<username>@ list-units --type=service` command to list the services of a user.
* **Reference**: [Ask Ubuntu](https://askubuntu.com/a/1424341)


# December

* [Day 13](/content/2024/december/day-13)
* [Day 21](/content/2024/december/day-21)


# December 13, 2024

## Things That I Discovered

### 1. Prevent cronjobs from overlapping

* I recently started running Systemd timer for a recurring task; rclone sync, and wanted bare minimum time to re-run it, but here comes a caveat, if the execution doesn't finish in time, a new task might be started, resulting in overlap, and if the task is handling data, say database for an example. That can lead to data loss/corruption. We can use `flock` command to overcome this.
* **Example:**

  ```
  flock /var/lock/rclone-sync.lock -w 30 rclone sync <SOURCE> <DESTINATION>
  ```
* Here, `flock` command would check for a lock file at `/var/lock/rclone-sync.lock` and wait for 30 seconds before it exits with an error if a lock file is found.
* Read more at my TIL [Website](https://til.devjugal.com/linux/systemd/prevent-systemd-timers-from-overlapping).
* **Reference(s):**
  * [CleverUptime](https://cleveruptime.com/docs/commands/flock)
  * [Mattias Geniar Blog](https://ma.ttias.be/prevent-cronjobs-from-overlapping-in-linux/)
  * [Bashscript.net](https://bashscript.net/using-flock-in-bash-scripts-manage-file-locks-and-prevent-task-overlaps/)


# December 21, 2024

## Things That I Discovered

### 1. Caddy Load-Balancing

* Turned to Caddy's Load Balancing capabilities to make sure a service stays up even if the server A goes down, and for that we can just declare a Reverse Proxy such that the server B is used when the server A goes down.
* **Example**:

  ```
  :80 {
      reverse_proxy {
          to 100.64.0.1:12345 100.64.0.2:12345
          health_uri /health
          health_interval 5s
          health_timeout 2s
          health_status 200
          health_passes 5
          fail_duration 30s
          lb_policy first
      }
  }
  ```
* **Reference(s):**
  * [Caddy Server Documentation](https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#load-balancing)
  * [Linux Training Academy](https://www.linuxtrainingacademy.com/caddy-load-balancing-tutorial/)
  * [Greg Hilston Blog](https://www.greghilston.com/post/how-to-load-balance-with-preference/)

### 2. Show Wi-Fi Networks in Ubuntu Server

* In order to show available WiFi Networks in Ubuntu Server, we can use `iwlist`command.
* **Example:**

  ```
  sudo iwlist <INTERFACE_NAME> scan | grep ESSID
  ```
* **Reference(s):**
  * [LinuxBabe](https://www.linuxbabe.com/ubuntu/connect-to-wi-fi-from-terminal-on-ubuntu-18-04-19-04-with-wpa-supplicant)
  * [Linux Uprising](https://www.linuxuprising.com/2019/11/how-to-show-available-wifi-networks.html)


