GeekCoding101

  • Home
  • GenAI
    • Daily AI Insights
    • Machine Learning
    • Transformer
    • Azure AI
  • DevOps
    • Kubernetes
    • Terraform
  • Tech
    • CyberSec
    • System Design
    • Coding Notes
  • About
  • Contact
tutorial
Coding Notes

Golang Range Loop Reference - Why Your Loop Keeps Giving You the Same Pointer (and How to Fix It)

When I first started learning Go, I thought I was doing everything right—until I ran into a weird bug about golang range loop reference. I was iterating over a list of Book structs (of course, I can't share the real structs and code used here... all here are for turorial purpose), taking the pointer of each one, and storing them into a slice. But at the end of the loop, all the pointers pointed to... the same book?! 🤯 Let’s walk through this classic Go beginner mistake together — and fix it the right way. 📚 The Use Case: A Slice of Books in a Library Suppose we have a list of books, and we want to collect pointers to each one so we can modify them later. Here’s the code I thought would work: for _, book := range books { bookPointers = append(bookPointers, &book) // Oops... } But when I printed out the pointers, they all pointed to the last book in the list. This bug stumped me for a while until I understood one critical Go behavior. The File Structure To Run The Code learning-golang/ ├── 01-loop-reference-pitfall/ │ ├── main.go │ └── README.md ├── Makefile ├── bin/ └── go.mod This is the complete buggy code: package main import ( "fmt" ) type Book struct { Title string Author string } func main() { originalBooks := []Book{ {"Go in Action", "William Kennedy"}, {"The Go Programming Language", "Alan Donovan"}, {"Introducing Go", "Caleb Doxsey"}, } fmt.Println("❌ Buggy Version:") var buggyPointers []*Book for _, book := range originalBooks { buggyPointers =…

May 4, 2025 0comments 165hotness 0likes Geekcoding101 Read all
Terraform

Mastering Terraform with AWS Guide Part 1: Launch Real AWS Infrastructure with VPC, IAM and EC2

So… you’ve heard about Terraform. Maybe your team is using it, maybe your cloud dreams demand it — or maybe, like me, you’ve been deep in the Kubernetes jungle (My blog posts about K8S) and now want a declarative friend for AWS too! Either way, welcome aboard. In this post, I’ll walk you through setting up your Terraform with AWS environment from scratch, on a Mac. We’ll start simple and go all the way to managing VPC, Security Groups, IAM users and EC2 infrastructure using best practices -all built using Terraform with AWS. By the end, you’ll not only run Terraform with AWS  — you’ll understand all below questions, just to name a few, such as how to run terraform with aws, how to create aws ec2 instance using terraform, how to create security group in aws using terraform...fantastic! What is Terraform? Terraform is an open-source infrastructure as code (IaC) tool created by HashiCorp. It lets you define, provision, and manage cloud infrastructure using human-readable config files written in HCL (HashiCorp Configuration Language). Think of it as Git for your cloud — but with superpowers. I know it's kind of short introduction, let's look at a real life scenario to understand what it is and why we need it! Why Do We Actually Need Terraform? A Real-Life Scenario Let’s say you’re an ambitious DevOps engineer named Alice. One day your boss comes in hot: “Hey Alice! We need 3 EC2 instances on AWS, 2 on Azure, and an S3 bucket for backups. Oh — and don’t forget a VPC, IAM…

April 15, 2025 0comments 84hotness 0likes Geekcoding101 Read all
Kubernetes

Ultimate Kubernetes Tutorial Part 1: Setting Up a Thriving Multi-Node Cluster on Mac

Introduction Hey there! Welcome to this Kubernetes tutorial! Ever dreamed of running a real multi-node Kubernetes (K8s) cluster on your laptop instead of settling for Minikube’s diet version? A proper real multi-node Kubernetes environment requires virtual machines, and until last year, VMware Fusion was a paid product—an obstacle for many. I know there are alternatives, like KVM, Oracle VirtualBox, and even Minikube’s so-called multi-node mode ----but let’s be real: I’ve got a beast of a MacBook Pro, so why not flex its muscles and spin up a legit multi-node cluster? 🚀 But great news! On November 11, 2024, VMware announced that Fusion and Workstation are now free for all users! The moment I stumbled upon this announcement, I was thrilled. Time to roll up my sleeves, fire up some VMs, and make this cluster a reality. Kick off my Kubernetes tutorial! Let’s dive in! 🚀 Project Overview My Goal In this series of Kubernetes tutorial, I want to set up a full Kubernetes cluster on my MacBook Pro using VMware Fusion, creating multiple VMs to simulate real-world deployment and practice my DevOps and IaC (Infrastructure as Code) skills. Planned Setup Create a VM as Base VM (Rocky Linux 9) Configure networking Update system packages Disable firewalld Enable SSH passwordless login from local Mac to the base VM Set up zsh, tmux, vim and common aliases Install Miniforge for Python environment management Install and configure Ansible Set up a Local Server Node (localserver) Clone from the above base VM image Create an Ansible script to customize the base VM image withe new…

March 1, 2025 0comments 463hotness 1likes Geekcoding101 Read all
Newest Hotest Random
Newest Hotest Random
Kubernetes Control Plane Components Explained A 12 Factor Crash Course in Python: Build Clean, Scalable FastAPI Apps the Right Way Golang Range Loop Reference - Why Your Loop Keeps Giving You the Same Pointer (and How to Fix It) Terraform Associate Exam: A Powerful Guide about How to Prepare It Terraform Meta Arguments Unlocked: Practical Patterns for Clean Infrastructure Code Mastering Terraform with AWS Guide Part 1: Launch Real AWS Infrastructure with VPC, IAM and EC2
Terraform Associate Exam: A Powerful Guide about How to Prepare ItGolang Range Loop Reference - Why Your Loop Keeps Giving You the Same Pointer (and How to Fix It)A 12 Factor Crash Course in Python: Build Clean, Scalable FastAPI Apps the Right WayKubernetes Control Plane Components Explained
Transformers Demystified - Day 2 - Unlocking the Genius of Self-Attention and AI's Greatest Breakthrough Weight Initialization: Unleashing AI Performance Excellence Git Notes Groundbreaking News: OpenAI Unveils o3 and o3 Mini with Stunning ARC-AGI Performance Fix Font in VSCode Terminal Finished Machine Learning for Absolute Beginners - Level 1
Newest comment
Tag aggregation
Daily.AI.Insight Supervised Machine Learning Machine Learning security notes cybersecurity AI Transformer

COPYRIGHT © 2024 GeekCoding101. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang