<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Samson</title>
    <description>The latest articles on DEV Community by Samson (@samson_jebaraj).</description>
    <link>https://dev.to/samson_jebaraj</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2819726%2F0f9b7680-71fe-4ab8-8d78-0832c17cb7d2.jpg</url>
      <title>DEV Community: Samson</title>
      <link>https://dev.to/samson_jebaraj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/samson_jebaraj"/>
    <language>en</language>
    <item>
      <title>Interacting with AWS</title>
      <dc:creator>Samson</dc:creator>
      <pubDate>Mon, 03 Mar 2025 11:58:04 +0000</pubDate>
      <link>https://dev.to/samson_jebaraj/interacting-with-aws-15f2</link>
      <guid>https://dev.to/samson_jebaraj/interacting-with-aws-15f2</guid>
      <description>&lt;h3&gt;
  
  
  1. &lt;strong&gt;AWS Management Console (Protected by Password + MFA)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What it is&lt;/strong&gt;: The AWS Management Console is a web-based interface where you can manage AWS services. It requires a username, password, and Multi-Factor Authentication (MFA) for added security.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real-time Example&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Imagine you are a DevOps engineer responsible for managing an EC2 instance (a virtual server) running a web application.&lt;/li&gt;
&lt;li&gt;You log in to the AWS Management Console using your username and password. Additionally, you are prompted to enter a one-time code from your MFA device (e.g., Google Authenticator or a hardware token).&lt;/li&gt;
&lt;li&gt;Once logged in, you navigate to the EC2 dashboard, where you can start, stop, or configure your virtual server. You can also monitor metrics like CPU usage and network traffic.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  2. &lt;strong&gt;AWS Command Line Interface (CLI) (Protected by Access Keys)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What it is&lt;/strong&gt;: The AWS CLI is a command-line tool that allows you to interact with AWS services using text-based commands. It uses access keys (Access Key ID and Secret Access Key) for authentication.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Real-time Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Suppose you are a developer who needs to automate the deployment of a new version of your application to an S3 bucket (a storage service).&lt;/li&gt;
&lt;li&gt;Instead of using the AWS Management Console, you use the AWS CLI on your local machine. You configure the CLI with your access keys:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;aws configure
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;You enter your Access Key ID, Secret Access Key, default region, and output format.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Then, you upload your application files to the S3 bucket using the following command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;aws s3 &lt;span class="nb"&gt;cp &lt;/span&gt;my-app.zip s3://my-bucket/
&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;This method is faster and more efficient for repetitive tasks or automation.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  3. &lt;strong&gt;AWS Software Developer Kit (SDK) - For Code (Protected by Access Key)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What it is&lt;/strong&gt;: The AWS SDK is a set of libraries that allow developers to interact with AWS services programmatically in their preferred programming language (e.g., Python, Java, JavaScript). Like the CLI, it uses access keys for authentication.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Real-time Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Imagine you are a backend developer building a Python application that processes user-uploaded images. You want to store these images in an S3 bucket and trigger a Lambda function to resize them.&lt;/li&gt;
&lt;li&gt;You use the AWS SDK for Python (Boto3) to write code that uploads the image to S3:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize the S3 client
&lt;/span&gt;&lt;span class="n"&gt;s3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s3&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;aws_access_key_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;YOUR_ACCESS_KEY&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;aws_secret_access_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;YOUR_SECRET_KEY&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Upload a file to S3
&lt;/span&gt;&lt;span class="n"&gt;s3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upload_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;user-image.jpg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;my-bucket&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;user-image.jpg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;After the image is uploaded, you can use the SDK to invoke a Lambda function that processes the image:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;lambda_client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;lambda&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lambda_client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;FunctionName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;resize-image-function&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bucket&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;my-bucket&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user-image.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;This approach is ideal for integrating AWS services directly into your applications.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  Summary of Real-Time Use Cases:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AWS Management Console&lt;/strong&gt;: Used for manual, visual management of AWS resources (e.g., starting an EC2 instance).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AWS CLI&lt;/strong&gt;: Used for scripting and automation (e.g., uploading files to S3).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AWS SDK&lt;/strong&gt;: Used for programmatic integration of AWS services into applications (e.g., uploading files to S3 and triggering a Lambda function via code).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each method has its own use case, and the choice depends on whether you need manual control, automation, or programmatic integration.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Choosing the Right DevOps Monitoring Tool: AWS CloudWatch vs. Prometheus</title>
      <dc:creator>Samson</dc:creator>
      <pubDate>Fri, 07 Feb 2025 16:36:40 +0000</pubDate>
      <link>https://dev.to/samson_jebaraj/choosing-the-right-devops-monitoring-tool-aws-cloudwatch-vs-prometheus-1coj</link>
      <guid>https://dev.to/samson_jebaraj/choosing-the-right-devops-monitoring-tool-aws-cloudwatch-vs-prometheus-1coj</guid>
      <description>&lt;p&gt;When it comes to monitoring your DevOps infrastructure, selecting the right tool can make all the difference in maintaining system reliability and performance. Two popular options are &lt;strong&gt;AWS CloudWatch&lt;/strong&gt; and &lt;strong&gt;Prometheus&lt;/strong&gt;, each with its own strengths and use cases.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;AWS CloudWatch&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scope&lt;/strong&gt;: Monitors the entire infrastructure, including servers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Metrics&lt;/strong&gt;: Tracks up to 21 metrics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scrape Time&lt;/strong&gt;: Checks metrics every 60 seconds, with the ability to extend to longer intervals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case&lt;/strong&gt;: Ideal for general monitoring and checking system health over longer periods.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Prometheus&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scope&lt;/strong&gt;: Focuses on server and infrastructure monitoring.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Metrics&lt;/strong&gt;: Capable of monitoring over 1,000 metrics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scrape Time&lt;/strong&gt;: Checks metrics every 15 seconds to 1 minute, allowing for faster detection of issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Evaluation Time&lt;/strong&gt;: Evaluates metrics within 15 to 60 seconds, enabling quicker response to anomalies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Default Timeout&lt;/strong&gt;: If no response is received within 10 seconds, it triggers a timeout, ensuring timely error detection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time Series Database&lt;/strong&gt;: Stores initial metrics and only updates changes every 15 seconds, avoiding duplication and optimizing storage.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Key Takeaways&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Faster Detection&lt;/strong&gt;: Prometheus, with its 15-second scrape time, can detect errors more quickly than CloudWatch, which operates on a 60-second interval.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Comprehensive Monitoring&lt;/strong&gt;: Prometheus supports over 1,000 metrics, making it more detailed and versatile for complex infrastructures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficient Storage&lt;/strong&gt;: Prometheus uses a time series database to store and update only the changes in metrics, reducing duplication and saving storage space.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;While AWS CloudWatch is a robust tool for general monitoring, &lt;strong&gt;Prometheus&lt;/strong&gt; stands out for its faster scrape times, detailed metrics, and efficient storage mechanisms. For DevOps teams looking to detect and resolve issues swiftly, Prometheus offers a significant advantage.&lt;/p&gt;

&lt;p&gt;Choosing between these tools depends on your specific needs—whether you prioritize broader, less frequent monitoring or detailed, real-time insights. Both tools have their place in a DevOps toolkit, but Prometheus is particularly well-suited for environments where rapid detection and response are critical.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mastering Terraform: A Comprehensive Guide to Infrastructure as Code (IaC) from Basics to Advanced Concepts</title>
      <dc:creator>Samson</dc:creator>
      <pubDate>Fri, 07 Feb 2025 16:16:00 +0000</pubDate>
      <link>https://dev.to/samson_jebaraj/mastering-terraform-a-comprehensive-guide-to-infrastructure-as-code-iac-from-basics-to-advanced-59hn</link>
      <guid>https://dev.to/samson_jebaraj/mastering-terraform-a-comprehensive-guide-to-infrastructure-as-code-iac-from-basics-to-advanced-59hn</guid>
      <description>&lt;h3&gt;
  
  
  Terraform Summary: Key Concepts and Workflow
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Day 1: Introduction to Terraform&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Terraform Files (.tf)&lt;/strong&gt;: Used to define infrastructure as code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On-Demand vs. Reserved Resources&lt;/strong&gt;: On-demand for unplanned needs, reserved for planned future use.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;File Transfer&lt;/strong&gt;: Use &lt;code&gt;scp&lt;/code&gt; to copy files from a local machine to a Linux server using a PEM key for authentication.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terraform Init&lt;/strong&gt;: Initializes the working directory, creating &lt;code&gt;.terraform&lt;/code&gt; (environment setup) and a lock file (plugin version control).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terraform Blocks&lt;/strong&gt;:

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Terraform Block&lt;/strong&gt;: Specifies the provider (e.g., AWS, GCP).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provider Block&lt;/strong&gt;: Defines the region (e.g., &lt;code&gt;us-east-1&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Block&lt;/strong&gt;: Defines the resources to be created.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-Region VPC&lt;/strong&gt;: Multiple VPCs in different regions can be created using aliases.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Day 2: Immutability and Resource Management&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Terraform Apply vs. Plan&lt;/strong&gt;: You can run &lt;code&gt;terraform apply&lt;/code&gt; before &lt;code&gt;terraform plan&lt;/code&gt;, but it’s not recommended.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Modification&lt;/strong&gt;: Small changes (e.g., instance type) are modified in-place, while major changes (e.g., OS change) result in resource recreation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lifecycle Rules&lt;/strong&gt;:

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create Before Destroy&lt;/strong&gt;: Ensures new resources are created before old ones are destroyed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prevent Destroy&lt;/strong&gt;: Prevents accidental deletion of resources.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Count&lt;/strong&gt;: Used to create multiple instances of a resource (e.g., &lt;code&gt;count = 5&lt;/code&gt; creates 5 EC2 instances).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;For Each&lt;/strong&gt;: Used for creating resources like S3 buckets where &lt;code&gt;count&lt;/code&gt; is not applicable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Day 3: Variables and State Management&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;State File&lt;/strong&gt;: Stores the current state of the infrastructure. Changes made manually in the cloud console are not reflected in the state file unless &lt;code&gt;terraform refresh&lt;/code&gt; is run.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lifecycle Ignore Changes&lt;/strong&gt;: Prevents Terraform from overwriting manual changes (e.g., tags).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Depends On&lt;/strong&gt;: Ensures resources are created in a specific order.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Variables&lt;/strong&gt;: Declared in &lt;code&gt;var.tf&lt;/code&gt; to avoid hardcoding values. Can be overridden via CLI or environment variables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Variable Precedence&lt;/strong&gt;: Terraform looks for variables in the following order:

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;auto.tfvars&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;terraform.tfvars&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Environment variables&lt;/li&gt;
&lt;li&gt;&lt;code&gt;variable.tf&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;main.tf&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Day 4: Advanced Variables and Outputs&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lists and Maps&lt;/strong&gt;: Used to define multiple values for variables (e.g., instance types).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;File Variables&lt;/strong&gt;: Use &lt;code&gt;file()&lt;/code&gt; to include scripts or configuration files in resources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sensitive Data&lt;/strong&gt;: Mark variables as &lt;code&gt;sensitive = true&lt;/code&gt; to hide sensitive information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Outputs&lt;/strong&gt;: Use &lt;code&gt;output.tf&lt;/code&gt; to display resource attributes (e.g., public IP of an EC2 instance).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local Variables&lt;/strong&gt;: Use &lt;code&gt;locals&lt;/code&gt; to define reusable values (e.g., tags).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Day 5: State Locking, Provisioners, and Workspaces&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;State Locking&lt;/strong&gt;: Prevents concurrent operations on the same state file using DynamoDB and S3.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terraform Commands&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;terraform show&lt;/code&gt;: Displays the state file content.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;terraform state list&lt;/code&gt;: Lists resources in the state file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;terraform taint/untaint&lt;/code&gt;: Marks a resource for recreation or removes the mark.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;terraform apply -target&lt;/code&gt;: Applies changes to a specific resource.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Provisioners&lt;/strong&gt;:

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Remote&lt;/strong&gt;: Executes commands on a remote machine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local&lt;/strong&gt;: Executes commands locally.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;File&lt;/strong&gt;: Transfers files to or from a remote machine.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Workspaces&lt;/strong&gt;: Used to manage multiple environments (e.g., prod, dev, staging) within the same configuration.&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Key Takeaways&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Terraform is a powerful tool for managing infrastructure as code, offering flexibility through variables, lifecycle rules, and state management.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;count&lt;/code&gt; and &lt;code&gt;for_each&lt;/code&gt; to manage multiple resources efficiently.&lt;/li&gt;
&lt;li&gt;Leverage &lt;code&gt;output.tf&lt;/code&gt; to extract and display resource attributes.&lt;/li&gt;
&lt;li&gt;State locking and workspaces help manage complex environments and prevent conflicts.&lt;/li&gt;
&lt;li&gt;Provisioners allow for additional configuration and file transfers during resource creation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This summary provides a high-level overview of Terraform's core concepts and workflows, making it easier to understand and implement infrastructure as code in real-world scenarios.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Leetcode : 1280 (Counting Student Exam Attendances)</title>
      <dc:creator>Samson</dc:creator>
      <pubDate>Thu, 06 Feb 2025 12:53:09 +0000</pubDate>
      <link>https://dev.to/samson_jebaraj/leetcode-1280-counting-student-exam-attendances-4gci</link>
      <guid>https://dev.to/samson_jebaraj/leetcode-1280-counting-student-exam-attendances-4gci</guid>
      <description>&lt;p&gt;&lt;strong&gt;Problem Statement:&lt;/strong&gt;&lt;br&gt;
We need to find out how many times each student attended each exam. The data is spread across three tables: &lt;code&gt;Students&lt;/code&gt;, &lt;code&gt;Subjects&lt;/code&gt;, and &lt;code&gt;Examinations&lt;/code&gt;. The result should include all students and all subjects, even if a student did not attend any exams for a particular subject.&lt;/p&gt;




&lt;h3&gt;
  
  
  Key Steps in the Solution:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Combine All Students and Subjects:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use a &lt;code&gt;CROSS JOIN&lt;/code&gt; between the &lt;code&gt;Students&lt;/code&gt; and &lt;code&gt;Subjects&lt;/code&gt; tables to create all possible combinations of students and subjects. This ensures that every student is paired with every subject, even if they didn’t attend any exams.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Count Exam Attendances:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use a &lt;code&gt;LEFT JOIN&lt;/code&gt; with the &lt;code&gt;Examinations&lt;/code&gt; table to count how many times each student attended each exam. If a student did not attend any exams for a subject, the count will be 0.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Group and Order the Results:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Group the results by &lt;code&gt;student_id&lt;/code&gt;, &lt;code&gt;student_name&lt;/code&gt;, and &lt;code&gt;subject_name&lt;/code&gt; to calculate the count of attended exams.&lt;/li&gt;
&lt;li&gt;Order the results by &lt;code&gt;student_id&lt;/code&gt; and &lt;code&gt;subject_name&lt;/code&gt; for a clean and organized output.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  SQL Query:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; 
    &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;student_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;student_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subject_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;student_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;attended_exams&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; 
    &lt;span class="n"&gt;Students&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
&lt;span class="k"&gt;CROSS&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; 
    &lt;span class="n"&gt;Subjects&lt;/span&gt; &lt;span class="n"&gt;sub&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; 
    &lt;span class="n"&gt;Examinations&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; 
&lt;span class="k"&gt;ON&lt;/span&gt; 
    &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;student_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;student_id&lt;/span&gt; 
    &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subject_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subject_name&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; 
    &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;student_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;student_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subject_name&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; 
    &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;student_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subject_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Example Input Tables:
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;Students&lt;/code&gt; Table:
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;student_id&lt;/th&gt;
&lt;th&gt;student_name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Alex&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;Subjects&lt;/code&gt; Table:
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;subject_name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Math&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Physics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Programming&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;Examinations&lt;/code&gt; Table:
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;student_id&lt;/th&gt;
&lt;th&gt;subject_name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Math&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Physics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Programming&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Programming&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Physics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Math&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;Math&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;Programming&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;Physics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Math&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Math&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  Example Output:
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;student_id&lt;/th&gt;
&lt;th&gt;student_name&lt;/th&gt;
&lt;th&gt;subject_name&lt;/th&gt;
&lt;th&gt;attended_exams&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;Math&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;Physics&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;Programming&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;Math&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;Physics&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;Programming&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Alex&lt;/td&gt;
&lt;td&gt;Math&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Alex&lt;/td&gt;
&lt;td&gt;Physics&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Alex&lt;/td&gt;
&lt;td&gt;Programming&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Math&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Physics&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;Programming&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  Explanation of the Output:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Alice&lt;/strong&gt; attended the &lt;strong&gt;Math&lt;/strong&gt; exam &lt;strong&gt;3 times&lt;/strong&gt;, the &lt;strong&gt;Physics&lt;/strong&gt; exam &lt;strong&gt;2 times&lt;/strong&gt;, and the &lt;strong&gt;Programming&lt;/strong&gt; exam &lt;strong&gt;1 time&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bob&lt;/strong&gt; attended the &lt;strong&gt;Math&lt;/strong&gt; exam &lt;strong&gt;1 time&lt;/strong&gt;, the &lt;strong&gt;Programming&lt;/strong&gt; exam &lt;strong&gt;1 time&lt;/strong&gt;, and did not attend the &lt;strong&gt;Physics&lt;/strong&gt; exam.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Alex&lt;/strong&gt; did not attend any exams.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;John&lt;/strong&gt; attended the &lt;strong&gt;Math&lt;/strong&gt;, &lt;strong&gt;Physics&lt;/strong&gt;, and &lt;strong&gt;Programming&lt;/strong&gt; exams &lt;strong&gt;1 time each&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Why This Query Works:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;CROSS JOIN&lt;/code&gt; ensures all student-subject combinations are included.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;LEFT JOIN&lt;/code&gt; ensures that students who did not attend any exams are still included with a count of 0.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;COUNT&lt;/code&gt; function calculates the number of times each student attended each exam.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;GROUP BY&lt;/code&gt; and &lt;code&gt;ORDER BY&lt;/code&gt; clauses organize the results for clarity.&lt;/li&gt;
&lt;/ul&gt;




</description>
    </item>
    <item>
      <title>Find Duplicate in a list</title>
      <dc:creator>Samson</dc:creator>
      <pubDate>Wed, 05 Feb 2025 16:18:49 +0000</pubDate>
      <link>https://dev.to/samson_jebaraj/find-duplicate-in-a-list-2hm0</link>
      <guid>https://dev.to/samson_jebaraj/find-duplicate-in-a-list-2hm0</guid>
      <description>&lt;p&gt;The &lt;code&gt;findDuplicate&lt;/code&gt; function is designed to find the first duplicate number in a list. Here's a concise breakdown:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Code Explanation&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;object&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;findDuplicate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;  &lt;span class="c1"&gt;# Dictionary to store encountered numbers
&lt;/span&gt;        &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;  &lt;span class="c1"&gt;# Loop through the list
&lt;/span&gt;            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# If the number is already in the dictionary, it's a duplicate
&lt;/span&gt;                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="c1"&gt;# Return the duplicate number
&lt;/span&gt;            &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;  &lt;span class="c1"&gt;# Mark the number as seen
&lt;/span&gt;            &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;  &lt;span class="c1"&gt;# Move to the next number
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;How It Works&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;It initializes an empty dictionary &lt;code&gt;a&lt;/code&gt; to store numbers encountered so far.&lt;/li&gt;
&lt;li&gt;It loops through the list &lt;code&gt;nums&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;If the number is already in &lt;code&gt;a&lt;/code&gt;, it returns that number as the first duplicate.&lt;/li&gt;
&lt;li&gt;Otherwise, it adds the number to &lt;code&gt;a&lt;/code&gt; and continues.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The function returns the first duplicate found in the list.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Example&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Input:&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;solution&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;solution&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findDuplicate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;Output:&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;Explanation:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The number &lt;code&gt;2&lt;/code&gt; appears twice in the list, and the function detects it as the first duplicate.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Split Words By Separator</title>
      <dc:creator>Samson</dc:creator>
      <pubDate>Wed, 05 Feb 2025 16:04:05 +0000</pubDate>
      <link>https://dev.to/samson_jebaraj/split-words-by-separator-1chl</link>
      <guid>https://dev.to/samson_jebaraj/split-words-by-separator-1chl</guid>
      <description>&lt;h1&gt;
  
  
  Here’s a Python function to split words using a separator and remove empty results:
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution(object):
    def splitWordsBySeparator(self, words, separator):
      ans = []
      for i in range(len(words)):  # Loop through each word inthe list
          ans.append(words[i].split(separator))  # Split wordby the separator

      new = sum(ans, [])  # Flatten the list (converts list oflists into a single list)
      res = list(filter(None, new))  # Remove empty stringsfrom the list

      return res  # Return the cleaned list of words
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It takes two inputs:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;words: A list of strings.&lt;br&gt;
separator: A character used to split the words.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It loops through each word and splits it using the separator.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The split words are stored in a list (ans), which may contain sublists.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It flattens ans using sum(ans, []) to merge all sublists into a single list.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It removes empty strings using filter(None, new) to get rid of unnecessary empty elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, it returns the cleaned list of words.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;solution = Solution()
words = ["hello.world", "python.is.awesome", "split,this"]
separator = "."

result = solution.splitWordsBySeparator(words, separator)
print(result)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;['hello', 'world', 'python', 'is', 'awesome', 'split', 'this']

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
