> Agents can also search and read this documentation through its [MCP server](https://howto.atharvgyan.com/~gitbook/mcp).

# Home

Atharv Gyan - how to Code

## How to automate sending daily email reports in Python, and how I would set it up.

A basic script to automate sending daily email reports using Python, using the `smtplib` library for sending emails and `schedule` library for scheduling the task to run daily:

<mark style="color:blue;">Python</mark>&#x20;

<pre class="language-python"><code class="lang-python"><strong>import smtplib
</strong>from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import schedule
import time

def send_email():
    # Email content
    sender_email = "your_email@gmail.com"
    receiver_email = "recipient_email@example.com"
    subject = "Daily Report"
    body = "This is your daily report email."

    # Setup the MIME
    message = MIMEMultipart()
    message['From'] = sender_email
    message['To'] = receiver_email
    message['Subject'] = subject

    # Attach body to the email
    message.attach(MIMEText(body, 'plain'))

    # SMTP Server
    smtp_server = "smtp.gmail.com"
    smtp_port = 587
    smtp_username = "your_email@gmail.com"
    smtp_password = "your_email_password"

    # Login to the SMTP server
    server = smtplib.SMTP(smtp_server, smtp_port)
    server.starttls()
    server.login(smtp_username, smtp_password)

    # Send email
    server.sendmail(sender_email, receiver_email, message.as_string())
    print("Email sent successfully!")

    # Quit SMTP server
    server.quit()

# Schedule the email to be sent daily
schedule.every().day.at("08:00").do(send_email)

# Infinite loop to run the scheduler
while True:
    schedule.run_pending()
    time.sleep(60)  # Check every minute

</code></pre>

## How to set it up:

1. **Install Required Libraries**: First, you need to install the `schedule` library if you haven't already. You can do this using pip:

```python
pip install schedule
```

2. **Update Email Configuration**: Replace `"your_email@gmail.com"`, `"recipient_email@example.com"`, and `"your_email_password"` with your actual email credentials. Ensure that you are using an email provider that allows SMTP access.
3. **Customize Email Content**: Modify the `subject` and `body` variables in the `send_email` function to customize the content of your daily email report.
4. **Schedule Email Sending**: The script is scheduled to send the email daily at 8:00 AM. You can adjust the time by modifying the `"08:00"` argument in `schedule.every().day.at()`.
5. **Run the Script**: Save the script as, say, `daily_email_report.py`, and run it using Python:

```python
python daily_email_report.py
```

6. **Keep the Script Running**: Since the script includes an infinite loop (`while True`), it will keep running indefinitely, checking every minute if there's any scheduled task to execute.

Once set up, the script will automatically send the daily email report at the specified time without any manual intervention.


# Responsive Top Navigation Bar

how to create a responsive top navigation menu with CSS and JavaScript.

### Responsive Topnav Example

{% code lineNumbers="true" %}

```html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}

.topnav {
  overflow: hidden;
  background-color: #333;
}

.topnav a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}

.topnav a:hover {
  background-color: #ddd;
  color: black;
}

.topnav a.active {
  background-color: #04AA6D;
  color: white;
}

.topnav .icon {
  display: none;
}

@media screen and (max-width: 600px) {
  .topnav a:not(:first-child) {display: none;}
  .topnav a.icon {
    float: right;
    display: block;
  }
}

@media screen and (max-width: 600px) {
  .topnav.responsive {position: relative;}
  .topnav.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  .topnav.responsive a {
    float: none;
    display: block;
    text-align: left;
  }
}
</style>

<!---HTML--->

</head>
<body>

<div class="topnav" id="myTopnav">
  <a href="#home" class="active">Home</a>
  <a href="#solutions">Solutions</a>
  <a href="#contact">Contact</a>
  <a href="#about">About</a>
  <a href="javascript:void(0);" class="icon" onclick="myFunction()">
    <i class="fa fa-bars"></i>
  </a>
</div>

<div style="padding-left:16px">
  <h2>Responsive Topnav Example</h2>
  <p>Resize the browser window to see how it works.</p>
</div>

<!---Javascript--->

<script>
function myFunction() {
  var x = document.getElementById("myTopnav");
  if (x.className === "topnav") {
    x.className += " responsive";
  } else {
    x.className = "topnav";
  }
}
</script>

</body>
</html>

```

{% endcode %}


# How do I make navigation links responsive?

To make navigation links responsive, you can use CSS media queries along with JavaScript. In the provided example, the navigation links become responsive by hiding all links except the first one and displaying a menu icon (hamburger menu) when the screen width is 600px or less. Clicking the menu icon toggles the visibility of the links. Here's a brief overview of how it's done:

CSS Media Queries: The example uses CSS media queries to apply different styles based on the screen width. When the screen width is 600px or less, it hides all navigation links except the first one and shows a menu icon.

```css
@media screen and (max-width: 600px)
 { .topnav a:not(:first-child)
  {display: none;} 
.topnav a.icon
 { float: right; display: block; } }
```

&#x20;JavaScript Function: A JavaScript function myFunction() toggles the navigation links' visibility when the menu icon is clicked. It changes the class of the navigation bar to "topnav responsive" to show the links in a vertical layout instead of horizontal.

Copy function myFunction() { var x = document.getElementById("myTopnav"); if (x.className === "topnav") { x.className += " responsive"; } else { x.className = "topnav"; } } How do I use media queries for different screen sizes? How can I add a dropdown menu to the responsive navigation? How do I change the color of the navigation bar in responsive mode? Sources Responsive Top Navigation Bar


# How to make a top navigation menu with CSS and JavaScript

CSS and JavaScript can be used for a top navigation menu. The provided example demonstrates how CSS is used to style the navigation menu and make it responsive, while JavaScript is used to toggle the

<mark style="color:red;">**CSS for styling**</mark>

```css
<!-- CSS for styling -->

<style>
.topnav {
  overflow: hidden;
  background-color: #333;
}
.topnav a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}
/* Additional CSS for responsiveness */
@media screen and (max-width: 600px) {
  .topnav a:not(:first-child) {display: none;}
  .topnav a.icon {
    float: right;
    display: block;
  }
}
</style>
```

<mark style="color:red;">**JavaScript for functionality**</mark>

```javascript
<!-- JavaScript for functionality -->
<script>
function myFunction() {
  var x = document.getElementById("myTopnav");
  if (x.className === "topnav") {
    x.className += " responsive";
  } else {
    x.className = "topnav";
  }
}
</script>

```


# How to automate sending daily email reports in Python, and how I would set it up.

A basic script to automate sending daily email reports using Python, using the smtplib library for sending emails and schedule library for scheduling the task to run daily:

<mark style="color:blue;">Python</mark>&#x20;

<pre class="language-python"><code class="lang-python"><strong>import smtplib
</strong>from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import schedule
import time

def send_email():
    # Email content
    sender_email = "your_email@gmail.com"
    receiver_email = "recipient_email@example.com"
    subject = "Daily Report"
    body = "This is your daily report email."

    # Setup the MIME
    message = MIMEMultipart()
    message['From'] = sender_email
    message['To'] = receiver_email
    message['Subject'] = subject

    # Attach body to the email
    message.attach(MIMEText(body, 'plain'))

    # SMTP Server
    smtp_server = "smtp.gmail.com"
    smtp_port = 587
    smtp_username = "your_email@gmail.com"
    smtp_password = "your_email_password"

    # Login to the SMTP server
    server = smtplib.SMTP(smtp_server, smtp_port)
    server.starttls()
    server.login(smtp_username, smtp_password)

    # Send email
    server.sendmail(sender_email, receiver_email, message.as_string())
    print("Email sent successfully!")

    # Quit SMTP server
    server.quit()

# Schedule the email to be sent daily
schedule.every().day.at("08:00").do(send_email)

# Infinite loop to run the scheduler
while True:
    schedule.run_pending()
    time.sleep(60)  # Check every minute

</code></pre>

## How to set it up:

1. **Install Required Libraries**: First, you need to install the `schedule` library if you haven't already. You can do this using pip:

```python
pip install schedule
```

2. **Update Email Configuration**: Replace `"your_email@gmail.com"`, `"recipient_email@example.com"`, and `"your_email_password"` with your actual email credentials. Ensure that you are using an email provider that allows SMTP access.
3. **Customize Email Content**: Modify the `subject` and `body` variables in the `send_email` function to customize the content of your daily email report.
4. **Schedule Email Sending**: The script is scheduled to send the email daily at 8:00 AM. You can adjust the time by modifying the `"08:00"` argument in `schedule.every().day.at()`.
5. **Run the Script**: Save the script as, say, `daily_email_report.py`, and run it using Python:

```python
python daily_email_report.py
```

6. **Keep the Script Running**: Since the script includes an infinite loop (`while True`), it will keep running indefinitely, checking every minute if there's any scheduled task to execute.

Once set up, the script will automatically send the daily email report at the specified time without any manual intervention.


# How To Make Working Contact Form With JavaScript

The steps to create a simple HTML JavaScript contact form:

1. **HTML Structure**:

* Create an HTML file (e.g., `contact.html`) with a basic structure:

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Contact Form</title>
</head>
<body>
    <!--form here -->
<form id="contact-form" method="POST" action="sendmail.php">
    <div class="form-row form-error" style="display:none;"></div>
    <div class="form-row">
        <label for="contact-form-name">Name:</label>
        <input id="contact-form-name" class="form-input" type="text" name="name" required>
    </div>
    <div class="form-row">
        <label for="contact-form-email">Email:</label>
        <input id="contact-form-email" class="form-input" type="email" name="email" required>
    </div>
    <div class="form-row">
        <label for="contact-form-phone">Phone:</label>
        <input id="contact-form-phone" class="form-input" type="tel" name="phone">
    </div>
    <div class="form-row">
        <label for="contact-form-message">Message:</label>
        <textarea id="contact-form-message" class="form-input" name="message" required></textarea>
    </div>
    <button type="submit">Submit</button>
</form>
 
</body>
</html>

```

2. **CSS Styling**:

* Add CSS code to the `<head>` tag to style the form:

```css
.form-row {
    margin-bottom: 10px;
}
.form-input {
    display: block;
}
.form-error {
    color: red;
}

```

3. **Server-Side Processing (PHP)**:

* Create a PHP file (e.g., `sendmail.php`) to handle form data processing.
* In `sendmail.php`, check if the request method is POST and validate the required form variables (name, email, and message).
* If all variables are present, use the data to send an email:

```php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['message'])) {
        $name = $_POST["name"];
        $email = $_POST["email"];
        $phone = $_POST["phone"];
        $message = $_POST["message"];

        $to = "your@email.com"; // Replace with your email address
        $subject = "New Contact Form Submission";
        $body = "Name: {$name}\nEmail: {$email}\nPhone: {$phone}\nMessage: {$message}";

        // Use PHP mail() function to send the email
        mail($to, $subject, $body);
    }
}
?>

```

Remember to replace `"your@email.com"` with your actual email address.

**Conclusion**: Follow these steps to create a functional contact form using HTML, JavaScript, and PHP. 📧


# How to Create a header line that appears when a user scrolls using HTML, CSS, and JavaScript

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
   body, html {
  margin: 0;
  padding: 0;
  height: 200%;
  font-family: Arial, sans-serif;
}

.header-line {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background-color: blue;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

.content {
  padding: 20px;
}

    </style>
</head>
<body>

  <div class="header-line" id="headerLine"></div>
  <div class="content">
    <!-- Add lots of content here to enable scrolling -->
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque vitae vehicula nunc, in consectetur libero. Nullam id tincidunt risus, eget venenatis lectus. Suspendisse potenti. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Vivamus auctor ligula nec turpis pharetra, in dignissim mauris tempus. Nam vitae ante volutpat, elementum lorem ut, posuere sem. Maecenas eget sem ultricies, consequat mi sed, commodo nisl.</p>
    <!-- Repeat the paragraph above or add more content to allow scrolling -->
  </div>
    
  <script>
 
  window.addEventListener('scroll', () => {
  const headerLine = document.getElementById('headerLine');
  if (window.scrollY > 50) {
    headerLine.style.transform = 'translateY(0)';
  } else {
    headerLine.style.transform = 'translateY(-100%)';
  }
});

 </script>
 
</body>
</html>


  
```

## Explain :

1. **HTML**:
   * We create a `div` element with a class of `header-line` that will act as our header line.
   * We also create a `div` with a class of `content` to contain enough text to make the page scrollable.
2. **CSS**:
   * We set up basic styling for the body and HTML to ensure the page has enough height and a sans-serif font.
   * The `.header-line` class styles the header line to be fixed at the top of the page, with an initial transform property to hide it above the viewport.
   * A smooth transition is set for the transform property to allow the header line to slide down smoothly when the user scrolls.
3. **JavaScript**:
   * We add an event listener for the `scroll` event.
   * In the event handler, we check the `scrollY` property (the number of pixels the document has already been scrolled vertically).
   * If the `scrollY` value is greater than 50 pixels, we set the `transform` property of the header line to `translateY(0)` to slide it into view.
   * If the `scrollY` value is 50 pixels or less, we hide the header line by setting the `transform` property back to `translateY(-100%)`.


