Snippets Collections
http://chatbotscriptmanage.dev.com/login

10.240.144.197 staging.chatbot-public.cyberbot.vn
10.240.144.197 staging.chatbot-private.cyberbot.vn

// Banker's Algorithm
#include <stdio.h>
int main()
{
    // P0, P1, P2, P3, P4 are the Process names here

    int n, m, i, j, k;
    n = 5; // Number of processes
    m = 3; // Number of resources
    int alloc[5][3] = { { 0, 1, 0 }, // P0    // Allocation Matrix
                        { 2, 0, 0 }, // P1
                        { 3, 0, 2 }, // P2
                        { 2, 1, 1 }, // P3
                        { 0, 0, 2 } }; // P4

    int max[5][3] = { { 7, 5, 3 }, // P0    // MAX Matrix
                      { 3, 2, 2 }, // P1
                      { 9, 0, 2 }, // P2
                      { 2, 2, 2 }, // P3
                      { 4, 3, 3 } }; // P4

    int avail[3] = { 3, 3, 2 }; // Available Resources

    int f[n], ans[n], ind = 0;
    for (k = 0; k < n; k++) {
        f[k] = 0;
    }
    int need[n][m];
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++)
            need[i][j] = max[i][j] - alloc[i][j];
    }
    int y = 0;
    for (k = 0; k < 5; k++) {
        for (i = 0; i < n; i++) {
            if (f[i] == 0) {

                int flag = 0;
                for (j = 0; j < m; j++) {
                    if (need[i][j] > avail[j]){
                        flag = 1;
                         break;
                    }
                }

                if (flag == 0) {
                    ans[ind++] = i;
                    for (y = 0; y < m; y++)
                        avail[y] += alloc[i][y];
                    f[i] = 1;
                }
            }
        }
    }
  
      int flag = 1;
      
      for(int i=0;i<n;i++)
    {
      if(f[i]==0)
      {
        flag=0;
         printf("The following system is not safe");
        break;
      }
    }
    
      if(flag==1)
    {
      printf("Following is the SAFE Sequence\n");
      for (i = 0; i < n - 1; i++)
        printf(" P%d ->", ans[i]);
      printf(" P%d", ans[n - 1]);
    }
    

    return (0);

    // This code is contributed by Deep Baldha (CandyZack)
}
#include <stdio.h>

int main() {
    int arrival_time[10], burst_time[10], remaining_time[10];
    int i, smallest, count = 0, time, limit;
    double wait_time = 0, turnaround_time = 0, end_time;
    float average_waiting_time, average_turnaround_time;

    printf("Enter the Total Number of Processes: ");
    scanf("%d", &limit);
    
    printf("Enter Details of %d Processes\n", limit);
    for (i = 0; i < limit; i++) {
        printf("Enter Arrival Time for Process %d: ", i + 1);
        scanf("%d", &arrival_time[i]);
        printf("Enter Burst Time for Process %d: ", i + 1);
        scanf("%d", &burst_time[i]);
        remaining_time[i] = burst_time[i];
    }
    
    remaining_time[9] = 9999;  // Sentinel value for comparison

    for (time = 0; count != limit; time++) {
        smallest = 9;
        for (i = 0; i < limit; i++) {
            if (arrival_time[i] <= time && remaining_time[i] < remaining_time[smallest] && remaining_time[i] > 0) {
                smallest = i;
            }
        }

        remaining_time[smallest]--;

        if (remaining_time[smallest] == 0) {
            count++;
            end_time = time + 1;
            wait_time += end_time - arrival_time[smallest] - burst_time[smallest];
            turnaround_time += end_time - arrival_time[smallest];
        }
    }

    average_waiting_time = wait_time / limit;
    average_turnaround_time = turnaround_time / limit;

    printf("\nAverage Waiting Time: %.2lf", average_waiting_time);
    printf("\nAverage Turnaround Time: %.2lf\n", average_turnaround_time);

    return 0;
}
#include <stdio.h>

int main() {
    int bt[20], p[20], wt[20], tat[20], i, j, n, total = 0, pos, temp;
    float avg_wt, avg_tat;

    printf("Enter number of processes: ");
    scanf("%d", &n);

    printf("\nEnter Burst Time:\n");
    for (i = 0; i < n; i++) {
        printf("p%d: ", i + 1);
        scanf("%d", &bt[i]);
        p[i] = i + 1; // Process number
    }

    // Sorting of burst times and process numbers in ascending order
    for (i = 0; i < n; i++) {
        pos = i;
        for (j = i + 1; j < n; j++) {
            if (bt[j] < bt[pos])
                pos = j;
        }

        // Swapping burst time
        temp = bt[i];
        bt[i] = bt[pos];
        bt[pos] = temp;

        // Swapping process number
        temp = p[i];
        p[i] = p[pos];
        p[pos] = temp;
    }

    wt[0] = 0; // Waiting time for the first process is 0

    // Calculating waiting time
    for (i = 1; i < n; i++) {
        wt[i] = 0;
        for (j = 0; j < i; j++)
            wt[i] += bt[j];

        total += wt[i];
    }

    avg_wt = (float) total / n; // Average waiting time
    total = 0;

    printf("\nProcess\t    Burst Time    Waiting Time    Turnaround Time\n");
    for (i = 0; i < n; i++) {
        tat[i] = bt[i] + wt[i]; // Calculating turnaround time
        total += tat[i];
        printf("p%d\t\t  %d\t\t    %d\t\t    %d\n", p[i], bt[i], wt[i], tat[i]);
    }

    avg_tat = (float) total / n; // Average turnaround time
    printf("\nAverage Waiting Time = %.2f", avg_wt);
    printf("\nAverage Turnaround Time = %.2f\n", avg_tat);

    return 0;
}
// Bounded type parameter example
class NumberContainer<T extends Number> {
    private T number;

    public NumberContainer(T number) {
        this.number = number;
    }

    public T getNumber() {
        return number;
    }

    public void setNumber(T number) {
        this.number = number;
    }

    public void display() {
        System.out.println("Number: " + number);
    }
}

// Wildcard argument example
class Utils {
    // Method to display elements of a NumberContainer with wildcard argument
    public static void displayNumberContainer(NumberContainer<?> container) {
        System.out.println("Number in container: " + container.getNumber());
    }
}

public class Main {
    public static void main(String[] args) {
        // Bounded type parameter example
        NumberContainer<Integer> intContainer = new NumberContainer<>(10);
        intContainer.display();

        NumberContainer<Double> doubleContainer = new NumberContainer<>(3.14);
        doubleContainer.display();

        // Wildcard argument example
        Utils.displayNumberContainer(intContainer);
        Utils.displayNumberContainer(doubleContainer);
    }
}
 AVLNode<T extends Comparable<T>> {
    T data;
    AVLNode<T> left, right;
    int height;

    public AVLNode(T data) {
        this.data = data;
        this.left = null;
        this.right = null;
        this.height = 1;
    }
}

public class AVLTree<T extends Comparable<T>> {
    private AVLNode<T> root;

    public AVLTree() {
        this.root = null;
    }

    private int height(AVLNode<T> node) {
        if (node == null) return 0;
        return node.height;
    }

    private int getBalance(AVLNode<T> node) {
        if (node == null) return 0;
        return height(node.left) - height(node.right);
    }

    public AVLNode<T> insert(AVLNode<T> node, T data) {
        if (node == null) return new AVLNode<>(data);

        if (data.compareTo(node.data) < 0) {
            node.left = insert(node.left, data);
        } else if (data.compareTo(node.data) > 0) {
            node.right = insert(node.right, data);
        } else {
            return node; // Duplicate keys not allowed
        }

        // Update height of this ancestor node
        node.height = 1 + Math.max(height(node.left), height(node.right));

        // Get the balance factor and perform rotation if needed
        int balance = getBalance(node);

        // Left Left Case
        if (balance > 1 && data.compareTo(node.left.data) < 0) {
            return rightRotate(node);
        }

        // Right Right Case
        if (balance < -1 && data.compareTo(node.right.data) > 0) {
            return leftRotate(node);
        }

        // Left Right Case
        if (balance > 1 && data.compareTo(node.left.data) > 0) {
            node.left = leftRotate(node.left);
            return rightRotate(node);
        }

        // Right Left Case
        if (balance < -1 && data.compareTo(node.right.data) < 0) {
            node.right = rightRotate(node.right);
            return leftRotate(node);
        }

        return node;
    }

    private AVLNode<T> rightRotate(AVLNode<T> y) {
        AVLNode<T> x = y.left;
        AVLNode<T> T2 = x.right;

        // Perform rotation
        x.right = y;
        y.left = T2;

        // Update heights
        y.height = Math.max(height(y.left), height(y.right)) + 1;
        x.height = Math.max(height(x.left), height(x.right)) + 1;

        return x;
    }

    private AVLNode<T> leftRotate(AVLNode<T> x) {
        AVLNode<T> y = x.right;
        AVLNode<T> T2 = y.left;

        // Perform rotation
        y.left = x;
        x.right = T2;

        // Update heights
        x.height = Math.max(height(x.left), height(x.right)) + 1;
        y.height = Math.max(height(y.left), height(y.right)) + 1;

        return y;
    }

    public void insert(T data) {
        root = insert(root, data);
    }

    public void inorderTraversal() {
        inorderTraversal(root);
        System.out.println();
    }

    private void inorderTraversal(AVLNode<T> node) {
        if (node != null) {
            inorderTraversal(node.left);
            System.out.print(node.data + " ");
            inorderTraversal(node.right);
        }
    }

    public static void main(String[] args) {
        AVLTree<Integer> avlTree = new AVLTree<>();
        avlTree.insert(10);
        avlTree.insert(20);
        avlTree.insert(30);
        avlTree.insert(40);
        avlTree.insert(50);
        avlTree.insert(25);

        System.out.println("Inorder traversal:");
        avlTree.inorderTraversal();
    }
}
--------------------------------------
 vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {
        stack<int> s;
        const int N =1e5;
        vector<int> ans;
        vector<int> v(N);
        int n=nums2.size();
        s.push(nums2[n-1]);
        v[nums2[n-1]]=-1;
        
        for(int i=nums2.size()-2;i>=0;--i)
        {
             if(nums2[i]<(s.top()))
            {
                
                v[nums2[i]]=s.top();
                s.push(nums2[i]);
            }
            else
            {
                while(!s.empty() && s.top()<nums2[i]  )//order matters in &&
                s.pop();
                if(s.empty())
                v[nums2[i]]=-1;
                else
                v[nums2[i]]=s.top();
                s.push(nums2[i]);
            }
        }
        for(int j=0;j<nums1.size();++j)
        {
            ans.push_back(v[nums1[j]]);
        }


        return ans;
    }
   
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <video src="video.mp4" height="255" controls loop muted poster="download.jpg"></video>

    <audio src="sachin.mp3" controls autoplay loop muted></audio>

    <svg height="100" width="100">
        <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
    </svg>
    <img src="img.svg" alt="My Svg Image">

    <!-- <iframe src="https://www.codewithharry.com/tutorial/html-iframes/" width="322" height="444"></iframe> -->
    
    <iframe width="560" height="315" src="https://www.youtube.com/embed/tVzUXW6siu0?si=NuQZuYqrMHn7Pg-i&amp;start=739" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

    <!-- Quick Quiz  -->
    <!-- Create a website which shows videos of different category and audios of different categories.
    You can use YouTube videos in an iframe using YouTube's embedding feature -->
</body>
</html>
Block Elements (Most Commonly Used First)

<div>: A generic container for flow content.
<p>: Paragraph.
<h1>, <h2>, <h3>, <h4>, <h5>, <h6>: Headings.
<ul>: Unordered list.
<ol>: Ordered list.
<li>: List item.
<form>: A section containing form controls.
<table>: Table.
<section>: A standalone section of a document.
<header>: A container for introductory content or a set of navigational links.
<footer>: Footer of a section or page.
<nav>: A section of a page that contains navigation links.
<article>: A self-contained composition in a document.
<aside>: A section of a page that contains information indirectly related to the main content.
<main>: The main content of a document.
<fieldset>: A set of form controls grouped under a common name.
<blockquote>: A block of text that is a quotation from another source.
<pre>: Preformatted text.
<canvas>: A container used to draw graphics via JavaScript.
<dl>: Description list.
<dt>: Term in a description list.
<dd>: Description in a description list.
<figure>: Any content that is referenced from the main content.
<figcaption>: A caption for a <figure> element.
<address>: Contact information for the author or owner of the document.
<hr>: A thematic break or a horizontal rule.
<tfoot>: Footer of a table.



Inline Elements (Most Commonly Used First)
<a>: Anchor or hyperlink.
<img>: Image.
<span>: Generic inline container.
<input>: Input field.
<label>: Label for a form element.
<strong>: Strong emphasis.
<em>: Emphasized text.
<br>: Line break.
<code>: Code snippet.
<b>: Bold text.
<i>: Italic text.
<u>: Underlined text.
<small>: Smaller text.
<sub>: Subscript.
<sup>: Superscript.
<mark>: Marked or highlighted text.
<q>: Short inline quotation.
<cite>: Citation.
<kbd>: Keyboard input.
<samp>: Sample output.
<var>: Variable in a mathematical expression or programming context.
<time>: Time.
<abbr>: Abbreviation.
<data>: Machine-readable translation of content.
<acronym>: Acronym (Not supported in HTML5).
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Inline and Block Elements - HTML</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <p>Hey I am a para</p>
    <a href="https://google.com">Google</a>
    <div> I am a block element</div>
    <span>I am span and I am inline</span>
    <a href="">yes he is inline</a>

    <!-- Quick Quiz:
    Without using br tag, write a vertically aligned form asking for name, city and pincode of a user.
    Everyone must comment -->

</body>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Forms - Lets learn it</title>
</head>

<body>
    <h1>Form to apply for Sigma Web Development course - TA </h1>
    <form action="post">
        <div>
            <label for="username">Enter your Username</label>
            <input type="text" id="username" name="username" placeholder="Enter your username" autofocus>
        </div>
        <div>
            <input type="radio" id="male" name="gender" value="male">
            <label for="male">Male</label>
            <input type="radio" id="female" name="gender" value="female">
            <label for="female">Female</label>
        </div>

        <div>
            <input type="checkbox" id="subscribe" name="subscribe" value="yes">
            <label for="subscribe">Subscribe to newsletter</label>
        </div>
        <div>
            <label for="comment">Enter your comment</label>
            <br>
            <textarea id="comment" name="comment" rows="4" cols="50"></textarea>
        </div>

        <div>
            <select name="fruits">
                <option value="apple">Apple</option>
                <option value="banana">Banana</option>
                <option value="cherry">Cherry</option>
          </select>
        </div>
    </form>
</body>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Images</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <img height="230" src="image.png" alt="Train image">
    <br>
    <table>
        <caption>Employee Details</caption>
        <thead>
            <tr>
                <th>Name</th>
                <th>Designation</th>
                <th>Fav Language</th>
            </tr>
        </thead>
        <tbody>


            <tr>
                <td>Harry</td>
                <td>Programmer</td>
                <td>JavaScript</td>
            </tr>

            <tr>
                <td colspan="2">Sam</td>//colspan means how many column a data will span
                <td rowspan="2">Java</td>
            </tr>
            <tr>
                <td colspan="2">Sam</td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td colspan="2">Sam</td>
                <td rowspan="2">foot</td>
            </tr>
        </tfoot>
    </table>


    <ul type="square">
        <li>Harry</li>
        <li>Rohan</li>
        <li>Shubham</li>
    </ul>
    <ol type="A">
        <li>Harry</li>
        <li>Rohan</li>
        <li>Shubham</li>
    </ol>

</body>

</html>
git clone https://github.com/AdnanHodzic/displaylink-debian.git
cd displaylink-debian
sudo ./displaylink-debian.sh
* git clone https://github.com/0xbitx/DEDSEC-XICOMAP.git
* cd DEDSEC-XICOMAP
* sudo pip3 install pystyle pycryptodome tabulate tqdm
* sudo python3 dedsec_xicomap.py
* git clone https://github.com/0xbitx/DEDSEC-XICOMAP.git
* cd DEDSEC-XICOMAP
* sudo pip3 install pystyle pycryptodome tabulate tqdm
* sudo python3 dedsec_xicomap.py
db.tweets.updateMany(
    {},
    {
        $unset: {
            "file_name": "",
            "json_data.id_str": "",
            "json_data.display_text_range": "",
            "json_data.source": "",
            "json_data.truncated": "",
            "json_data.favorite_count": "",
            "json_data.in_reply_to_status_id_str": "",
            "json_data.in_reply_to_user_id_str": "",
            "json_data.user.id_str": "",
            "json_data.user.name": "",
            "json_data.user.screen_name": "",
            "json_data.user.url": "",
            "json_data.user.translator_type": "",
            "json_data.user.protected": "",
            "json_data.user.listed_count": "",
            "json_data.user.favourites_count": "",
            "json_data.user.statuses_count": "",
            "json_data.user.utc_offset": "",
            "json_data.user.time_zone": "",
            "json_data.user.geo_enabled": "",
            "json_data.user.geo": "",
            "json_data.user.coordinates": "",
            "json_data.user.is_translator": "",
            "json_data.user.contributors_enabled": "",
            "json_data.user.profile_background_color": "",
            "json_data.user.profile_background_image_url": "",
            "json_data.user.profile_background_image_url_https": "",
            "json_data.user.profile_background_tile": "",
            "json_data.user.profile_link_color": "",
            "json_data.user.profile_sidebar_border_color": "",
            "json_data.user.profile_sidebar_fill_color": "",
            "json_data.user.profile_text_color": "",
            "json_data.user.profile_use_background_image": "",
            "json_data.user.profile_image_url": "",
            "json_data.user.profile_image_url_https": "",
            "json_data.user.profile_banner_url": "",
            "json_data.user.default_profile": "",
            "json_data.user.default_profile_image": "",
            "json_data.user.following": "",
            "json_data.user.follow_request_sent": "",
            "json_data.user.notifications": "",
            "json_data.contributors": "",
            "json_data.is_quote_status": "",
            "json_data.entities.urls": "",
            "json_data.entities.symbols": "",
            "json_data.extended_entities": "",
            "json_data.favorited": "",
            "json_data.possibly_sensitive": "",
            "json_data.filter_level": ""
        }
    }
);
<img src="" alt="">
/**Display Form using short-code**/

[subscription_form]



/**Custom Subscribe Form Style Start**/



#subscribe-form {
    display: flex;
    gap: 10px;
}

#subscribe-form input[type="email"] {
		width: 100%;
		height: 40px;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 16px;
    flex: 1;
}
#subscribe-form input:focus,input:hover{
	border-color: #3498db;
}

#subscribe-form button {
		line-height: 1rem;
    padding: 10px 20px;
    border: none;
    background-color: black;
    color: white;
    font-size: 1rem;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.3s;
}

#subscribe-form button:hover {
    background-color: #333;
}

#form-message {
    margin-top: 10px;
    font-size: 16px;
}

#form-message.success {
    color: green;
}

#form-message.error {
    color: red;
}


@media only screen and (max-width: 600px){
	#subscribe-form {
		flex-wrap: wrap;
}
	#subscribe-form input[type="email"] {
	width: 100%;
}

#subscribe-form button {
	width: 100%;
}
}

/**Custom Subscribe Form Style End**/





/** Form PHP start**/

//**this snippet will going to register user as wordpress subscriber on form submit.
  
 /*you can use any snippet plugin or directly add this snippet into your theme function.php file*/
  
<?php

function subscription_form_handler() {
    $output = '';

    // Check if the form is submitted
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['subscribe'])) {
        if (isset($_POST['email']) && is_email($_POST['email'])) {
            $email = sanitize_email($_POST['email']);

            if (email_exists($email)) {
                $message = 'already_registered';
            } else {
                $username = sanitize_user(explode('@', $email)[0] . '_' . wp_generate_password(4, false));
                $password = wp_generate_password();

                $user_id = wp_create_user($username, $password, $email);
                if (is_wp_error($user_id)) {
                    $message = 'subscription_failed';
                } else {
                    $user = new WP_User($user_id);
                    $user->set_role('subscriber');
                    $message = 'subscription_successful';
                }
            }
        } else {
            $message = 'invalid_email';
        }

        // Redirect to the same page with the message parameter
        wp_redirect(add_query_arg('message', $message, get_permalink()));
        exit;
    }

    // Always display the form
    $output .= '
    <form id="subscribe-form" method="post">
        <input type="email" name="email" placeholder="E-Mail" required>
        <button type="submit" name="subscribe">Subscribe</button>
    </form>';

    // Display the message if it exists in the URL parameters
    if (isset($_GET['message'])) {
        switch ($_GET['message']) {
            case 'already_registered':
                $output .= '<div id="form-message" class="error">Already Registered</div>';
                break;
            case 'subscription_failed':
                $output .= '<div id="form-message" class="error">Subscription failed.</div>';
                break;
            case 'subscription_successful':
                $output .= '<div id="form-message" class="success">Subscription successful!</div>';
                break;
            case 'invalid_email':
                $output .= '<div id="form-message" class="error">Invalid email address.</div>';
                break;
        }
    }

    return $output;
}

add_shortcode('subscription_form', 'subscription_form_handler');

function enqueue_custom_script() {
    ?>
    <script type="text/javascript">
        document.addEventListener('DOMContentLoaded', function() {
            const url = new URL(window.location);
            if (url.searchParams.has('message')) {
                url.searchParams.delete('message');
                window.history.replaceState({}, document.title, url.toString());
            }
        });
    </script>
    <?php
}

add_action('wp_footer', 'enqueue_custom_script');

?>


/**Form Php End **/
var n = prompt("¿Cuántos estudiantes desea ingresar?")

for (var nos = 0; nos < n; nos++) {
    var nom = prompt("Ingrese el nombre del estudiante " + (nos + 1) + ":")
    var notas = parseInt(prompt("¿Cuántas notas desea ingresar para " + nom + "?"))
    var suma = 0

    for (var cu = 1; cu <= notas; cu++) {
        var nts = parseInt(prompt("Ingrese la nota " + cu + " del estudiante " + nom + ":"))
        suma += nts
    }

    var promedio = suma / notas

    document.write("<hr><strong>El promedio del estudiante " + nom + " es " + promedio + "</strong><br><br>")
    document.write("<strong> y las notas del estudiante "+nom)

    for (var i = 1; i <= notas; i++) {
        document.write(i === notas ? nts : nts + ", ")
    }

    document.write("<br><br>")
}
class GenericStackLinkedList<T> {
    private Node<T> top;

    public GenericStackLinkedList() {
        this.top = null;
    }

    public void push(T item) {
        Node<T> newNode = new Node<>(item);
        newNode.next = top;
        top = newNode;
    }

    public T pop() {
        if (top == null) {
            System.out.println("Stack Underflow");
            return null;
        }
        T data = top.data;
        top = top.next;
        return data;
    }

    public boolean isEmpty() {
        return top == null;
    }
}
class GenericStackArray<T> {
    private T[] stackArray;
    private int top;
    private int maxSize;

    @SuppressWarnings("unchecked")
    public GenericStackArray(int size) {
        this.maxSize = size;
        this.stackArray = (T[]) new Object[maxSize];
        this.top = -1;
    }

    public void push(T item) {
        if (top < maxSize - 1) {
            stackArray[++top] = item;
        } else {
            System.out.println("Stack Overflow");
        }
    }

    public T pop() {
        if (top >= 0) {
            return stackArray[top--];
        } else {
            System.out.println("Stack Underflow");
            return null;
        }
    }

    public boolean isEmpty() {
        return top == -1;
    }
}
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Apr 16 08:39:43 2024

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL> create table passenger(
  2    2  passenger_ID int primary key,
  3    3  Ticket_no INTEGER,
  4    4  Name varchar(10),
  5    5  DOB date,
  6    6  sex char(1),address varchar(50));
SP2-0640: Not connected
SQL> connect sys as sysdba
Enter password:
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified


SQL> connect sys as sysdba
Enter password:
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified


SQL> connect sys as sysdba
Enter password:
Connected.
SQL> create user Tharun identified by tharun;

User created.

SQL> grant dba to Tharun;

Grant succeeded.

SQL> show user;
USER is "SYS"
SQL> connect Tharun;
Enter password:
ERROR:
ORA-01017: invalid username/password; logon denied


Warning: You are no longer connected to ORACLE.
SQL> connect Tharun;
Enter password:
Connected.
SQL> spool 'C:\Users\CVR\Desktop\1252'
SQL>  create table passenger(
  2    2    2  passenger_ID int primary key,
  3    3    3  Ticket_no INTEGER,
  4    4    4  Name varchar(10),
  5    5    5  DOB date,
  6    6    6  sex char(1),address varchar(50)
  7  ;
  2    2  passenger_ID int primary key,
  *
ERROR at line 2:
ORA-00904: : invalid identifier


SQL> create table passenger(
  2  ;

*
ERROR at line 2:
ORA-00904: : invalid identifier


SQL> create table passenger(
  2    2  passenger_ID int primary key,
  3    3  Ticket_no INTEGER,
  4    4  Name varchar(10),
  5    5  DOB date,
  6    6  sex char(1),address varchar(50));
  2  passenger_ID int primary key,
  *
ERROR at line 2:
ORA-00904: : invalid identifier


SQL> create table passenger(
  2  passenger_ID int primary key,
  3  Name varchar(20),
  4  Ticket_No INTEGER,
  5  sex char(1),
  6  address varchar(50),
  7  source varchar(30),
  8  destination varchar(30) NOT NULL,
  9  DOB DATE,
 10  type varchar(3));

Table created.

SQL> insert into passenger(passenger_ID,Name,Ticket_No,type,sex,address,source,destination,DOB)
  2  values('e001','tulasi','101','ac','m','Telangana hyderabad bn reddy','JBS','Yamjal',DATE '1980-02-21);
ERROR:
ORA-01756: quoted string not properly terminated


SQL> insert into passenger(passenger_ID,Name,Ticket_No,type,sex,address,source,destination,DOB)
  2  values('e001','tulasi','101','ac','m','Telangana hyderabad bn reddy','JBS','Yamjal',DATE '1980-02-21');
values('e001','tulasi','101','ac','m','Telangana hyderabad bn reddy','JBS','Yamjal',DATE '1980-02-21')
       *
ERROR at line 2:
ORA-01722: invalid number


SQL> insert into passenger(passenger_ID,Name,Ticket_No,type,sex,address,source,destination,DOB)
  2  values(001,'tulasi',101,'ac','m','Telanganahyderabadbnreddy','JBS','Yamjal',DATE '1980-02-21');

1 row created.

SQL> insert into passenger(passenger_ID,Name,Ticket_No,type,sex,address,source,destination,DOB)
  2  values(002,'snigdha',102,'nac','f','Telanganahyderabadbnreddy','MGBS','BN reddy',DATE '1984-11-26');

1 row created.

SQL> insert into passenger(passenger_ID,Name,Ticket_No,type,sex,address,source,destination,DOB)
  2  values(003,'sherley',103,'ac','f','Telanganahyderabadbnreddy','MGBS','Kalwakurthy',DATE '1985-01-01');

1 row created.

SQL> insert into passenger(passenger_ID,Name,Ticket_No,type,sex,address,source,destination,DOB)
  2  values(004,'jangaiah',104,'nac','m','Telanganahyderabadbnreddy','kalwakurthy','Srisailam',DATE '1986-09-13');

1 row created.

SQL> describe;
Usage: DESCRIBE [schema.]object[@db_link]
SQL> describe passenger;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 PASSENGER_ID                              NOT NULL NUMBER(38)
 NAME                                               VARCHAR2(20)
 TICKET_NO                                          NUMBER(38)
 SEX                                                CHAR(1)
 ADDRESS                                            VARCHAR2(50)
 SOURCE                                             VARCHAR2(30)
 DESTINATION                               NOT NULL VARCHAR2(30)
 DOB                                                DATE
 TYPE                                               VARCHAR2(3)

SQL> select passenger_ID FROM passenger
  2  WHERE unique(;)
  3  ;
WHERE unique(;)
      *
ERROR at line 2:
ORA-00936: missing expression


SQL> select * FROM passenger
  2  WHERE UNIQUE(passenger_ID);
WHERE UNIQUE(passenger_ID)
      *
ERROR at line 2:
ORA-00936: missing expression


SQL> select * FROM passenger
  2  select * FROM passenger;
select * FROM passenger
*
ERROR at line 2:
ORA-00933: SQL command not properly ended


SQL> select Name FROM passenger
  2  WHERE sex == 'm';
WHERE sex == 'm'
           *
ERROR at line 2:
ORA-00936: missing expression


SQL> select Name FROM passenger
  2  WHERE sex = 'm';

NAME
--------------------
tulasi
jangaiah

SQL> select Ticket_No,Name FROM passenger;

 TICKET_NO NAME
---------- --------------------
       101 tulasi
       102 snigdha
       103 sherley
       104 jangaiah

SQL> ALTER table passenger
  2  ADD column timetaken(h);
ADD column timetaken(h)
    *
ERROR at line 2:
ORA-00904: : invalid identifier


SQL> ALTER table passenger
  2  ADD column timetaken(h) INTEGER;
ADD column timetaken(h) INTEGER
    *
ERROR at line 2:
ORA-00904: : invalid identifier


SQL> ALTER table passenger
  2  ADD column timetaken INTEGER;
ADD column timetaken INTEGER
    *
ERROR at line 2:
ORA-00904: : invalid identifier


SQL> ALTER TABLE passenger
  2  ADD timetravel INTEGER;

Table altered.

SQL> insert into passenger(timetravel)
  2  values(12);
insert into passenger(timetravel)
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("THARUN"."PASSENGER"."PASSENGER_ID")


SQL> insert into passenger(passenger_ID,Name,Ticket_No,type,sex,address,source,destination,DOB,timetravel)
  2  values(001,'tulasi',101,'ac','m','Telanganahyderabadbnreddy','JBS','Yamjal',DATE '1980-02-21',12);
insert into passenger(passenger_ID,Name,Ticket_No,type,sex,address,source,destination,DOB,timetravel)
*
ERROR at line 1:
ORA-00001: unique constraint (THARUN.SYS_C004028) violated


SQL> select source ,destination FROM passenger;

SOURCE                         DESTINATION
------------------------------ ------------------------------
JBS                            Yamjal
MGBS                           BN reddy
MGBS                           Kalwakurthy
kalwakurthy                    Srisailam

SQL> select Name FROM passenger
  2  WHERE DOB > 1985-01-01;
WHERE DOB > 1985-01-01
          *
ERROR at line 2:
ORA-00932: inconsistent datatypes: expected DATE got NUMBER


SQL> select Name FROM passenger
  2  ORDER BY ASC;
ORDER BY ASC
         *
ERROR at line 2:
ORA-00936: missing expression


SQL> select Name FROM passenger
  2  ORDER BY Name ASC;

NAME
--------------------
jangaiah
sherley
snigdha
tulasi

SQL> select * FROM passenger
  2  WHERE type IN('ac','nac');

PASSENGER_ID NAME                  TICKET_NO S
------------ -------------------- ---------- -
ADDRESS
--------------------------------------------------
SOURCE                         DESTINATION
     DOB        TYP
------------------------------ ------------------------------ --------- ---
TIMETRAVEL
----------
           1 tulasi                      101 m
Telanganahyderabadbnreddy
JBS                            Yamjal
     21-FEB-80 ac



PASSENGER_ID NAME                  TICKET_NO S
------------ -------------------- ---------- -
ADDRESS
--------------------------------------------------
SOURCE                         DESTINATION
     DOB        TYP
------------------------------ ------------------------------ --------- ---
TIMETRAVEL
----------
           2 snigdha                     102 f
Telanganahyderabadbnreddy
MGBS                           BN reddy
     26-NOV-84 nac



PASSENGER_ID NAME                  TICKET_NO S
------------ -------------------- ---------- -
ADDRESS
--------------------------------------------------
SOURCE                         DESTINATION
     DOB        TYP
------------------------------ ------------------------------ --------- ---
TIMETRAVEL
----------
           3 sherley                     103 f
Telanganahyderabadbnreddy
MGBS                           Kalwakurthy
     01-JAN-85 ac



PASSENGER_ID NAME                  TICKET_NO S
------------ -------------------- ---------- -
ADDRESS
--------------------------------------------------
SOURCE                         DESTINATION
     DOB        TYP
------------------------------ ------------------------------ --------- ---
TIMETRAVEL
----------
           4 jangaiah                    104 m
Telanganahyderabadbnreddy
kalwakurthy                    Srisailam
     13-SEP-86 nac
     ;
  1  select * FROM passenger
  2* WHERE type IN('ac','nac')
SQL> ^S^A^A;
SP2-0042: unknown command "" - rest of line ignored.
SQL> ;HERE type IN('ac','nac')
  1  select * FROM passenger
  2* WHERE type IN('ac','nac')
#include<stdio.h>
int n;
int main()
{
int seq[30],fr[5],pos[5],find,flag,max,i,j,m,k,t,s;
int count=1,pf=0,p=0;
float pfr;
printf("Enter maximum limit of the sequence: ");
scanf("%d",&max);
printf("\nEnter the sequence: ");
 for(i=0;i<max;i++)
scanf("%d",&seq[i]);
 printf("\nEnter no. of frames: ");
 scanf("%d",&n);
fr[0]=seq[0];
pf++;
printf("%d\t",fr[0]);
i=1;
while(count<n)
{
flag=1; p++;
for(j=0;j<i;j++)
{
if(seq[i]==seq[j]) flag=0;
}
if(flag!=0)
{
 fr[count]=seq[i];
 printf("%d\t",fr[count]);
 count++;
pf++;

}
i++;
}
 
printf("\n");
for(i=p;i<max;i++)
{
flag=1;
for(j=0;j<n;j++)
{
if(seq[i]==fr[j])
flag=0;
}
if(flag!=0)

{
for(j=0;j<n;j++)
{
m=fr[j];
for(k=i;k<max;k++)
{
if(seq[k]==m)
{
    pos[j]=k;
     break;

 }
else
pos[j]=1;

}
}
for(k=0;k<n;k++)
{
if(pos[k]==1)
flag=0;
}
if(flag!=0)
s=findmax(pos);
 if(flag==0)
{
for(k=0;k<n;k++)
{
if(pos[k]==1)
{
s=k;
 break;
}
}
}
fr[s]=seq[i];
for(k=0;k<n;k++)
printf("%d\t",fr[k]);
pf++;
printf("\n");
}
}
pfr=(float)pf/(float)max;
printf("\nThe no. of page faults are %d",pf);
printf("\nPage fault rate %f",pfr);
getch();
}
int findmax(int a[])
{
int max,i,k=0;
max=a[0];
for(i=0;i<n;i++)
{
if(max<a[i])
{
  max=a[i];
   k=i;
}
}
return k;
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j , k, min, rs[25], m[10], count[10], flag[25], n, f, pf=0, next=1;
//clrscr();
printf("Enter the length of reference string -- ");
 scanf("%d",&n);
printf("Enter the reference string -- ");
 for(i=0;i<n;i++)
{
scanf("%d",&rs[i]);
flag[i]=0;
}
printf("Enter the number of frames -- ");
 scanf("%d",&f);
for(i=0;i<f;i++)

{
count[i]=0;
m[i]=-1;
}
printf("\nThe Page Replacement process is -- \n");
 for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
{
if(m[j]==rs[i])
{
flag[i]=1;
count[j]=next;
 next++;
}

}
if(flag[i]==0)
{

if(i<f)
{  m[i]=rs[i];
   count[i]=next;
   next++;
 }
else
{ min=0;
for(j=1;j<f;j++)
if(count[min] > count[j])
  min=j;

m[min]=rs[i];
 count[min]=next;
  next++;


}
pf++;
}

for(j=0;j<f;j++)
printf("%d\t", m[j]);
 if(flag[i]==0)
printf("PF No. -- %d" , pf);
 printf("\n");
}
printf("\nThe number of page faults using LRU are %d",pf);
 getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int i, j, k, f, pf=0, count=0, rs[25], m[10], n;
printf("\n Enter the length of reference string -- ");
scanf("%d",&n);
printf("\n Enter the reference string -- ");
 for(i=0;i<n;i++)
scanf("%d",&rs[i]);
 printf("\n Enter no. of frames -- ");
 scanf("%d",&f);
for(i=0;i<f;i++)
m[i]=-1;

printf("\n The Page Replacement Process is -- \n");
 for(i=0;i<n;i++)
{
for(k=0;k<f;k++)
{
  if(m[k]==rs[i])
  break;

}
if(k==f)
{
m[count++]=rs[i];
pf++;

}

for(j=0;j<f;j++)
printf("\t%d",m[j]);
if(k==f)
printf("\tPF No. %d",pf);
printf("\n");
if(count==f)
count=0;
}
printf("\n The number of Page Faults using FIFO are %d",pf);
getch();
}
#include<stdio.h>
#include<stdlib.h>
int mutex=1,full=0,empty=3,x=0;
int main()
{
   int n;
   void producer();
   void consumer();
   int wait(int);
   int signal(int);
   printf("\n 1.Producer \n 2.Consumer \n 3.Exit");
   while(1)
   {
      printf("\nEnter your choice:");
      scanf("%d",&n);
      switch(n)
      {
         case 1:
                 if((mutex==1)&&(empty!=0))
                    producer();
                 else
                    printf("Buffer is full");
     break;
         case 2:
             if((mutex==1)&&(full!=0))
    consumer();
    else
        printf("Buffer is empty");
       break;
         case 3:
    exit(0);
    break;
      }
   }
}
int wait(int s)
{
   return (--s);
}
int signal(int s)
{
   return(++s);
}
void producer()
{
   mutex=wait(mutex);
   full=signal(full);
   empty=wait(empty);
   x++;
   printf("Producer produces the item %d\n",x);
   mutex=signal(mutex);
}
void consumer()
{
   mutex=wait(mutex);
   full=wait(full);
   empty=signal(empty);
   printf("Consumer consumes item %d\n",x);
   x--;
   mutex=signal(mutex);
}
#include <stdio.h>
int main() {
    int n, m, i, j, k;

    // Get the number of processes and resources from the user
    printf("Enter the number of processes: ");
    scanf("%d", &n);
    printf("Enter the number of resources: ");
    scanf("%d", &m);

    int alloc[n][m], max[n][m], avail[m];

    // Get the Allocation Matrix from the user
    printf("Enter the Allocation Matrix:\n");
    for (i = 0; i < n; i++) {
        printf("Process %d:\n", i);
        for (j = 0; j < m; j++) {
            scanf("%d", &alloc[i][j]);
        }
    }

    // Get the Maximum Matrix from the user
    printf("Enter the Maximum Matrix:\n");
    for (i = 0; i < n; i++) {
        printf("Process %d:\n", i);
        for (j = 0; j < m; j++) {
            scanf("%d", &max[i][j]);
        }
    }

    // Get the Available Resources from the user
    printf("Enter the Available Resources:\n");
    for (i = 0; i < m; i++) {
        scanf("%d", &avail[i]);
    }

    int f[n], ans[n], ind = 0;
    for (k = 0; k < n; k++) {
        f[k] = 0;
    }

    int need[n][m];
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            need[i][j] = max[i][j] - alloc[i][j];
        }
    }

    int y = 0;
    for (k = 0; k < n; k++) {
        for (i = 0; i < n; i++) {
            if (f[i] == 0) {
                int flag = 0;
                for (j = 0; j < m; j++) {
                    if (need[i][j] > avail[j]) {
                        flag = 1;
                        break;
                    }
                }

                if (flag == 0) {
                    ans[ind++] = i;
                    for (y = 0; y < m; y++) {
                        avail[y] += alloc[i][y];
                    }
                    f[i] = 1;
                }
            }
        }
    }

    int flag = 1;
    for (i = 0; i < n; i++) {
        if (f[i] == 0) {
            flag = 0;
            printf("The system is not in a safe state.\n");
            break;
        }
    }

    if (flag == 1) {
        printf("The system is in a safe state.\nSafe sequence is: ");
        for (i = 0; i < n - 1; i++) {
            printf("P%d -> ", ans[i]);
        }
        printf("P%d\n", ans[n - 1]);
    }

    return 0;
}
#include <stdio.h>

int main() {
    int n, i, j, temp, sum_wait = 0, sum_turnaround = 0;
    float avg_wait, avg_turnaround;
    int priority[20], bt[20], wt[20], tat[20];

    printf("Enter the number of processes: ");
    scanf("%d", &n);

    // Input burst times and priorities for each process
    printf("Enter burst times and priorities for each process:\n");
    for (i = 0; i < n; i++) {
        printf("Process %d: ", i + 1);
        scanf("%d%d", &bt[i], &priority[i]);
    }

    // Sort processes based on priority (ascending order)
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (priority[i] > priority[j]) {
                temp = priority[i];
                priority[i] = priority[j];
                priority[j] = temp;
                temp = bt[i];
                bt[i] = bt[j];
                bt[j] = temp;
            }
        }
    }

    // Calculate waiting time for each process
    wt[0] = 0; // Waiting time for first process is zero
    for (i = 1; i < n; i++) {
        wt[i] = wt[i - 1] + bt[i - 1];
        sum_wait += wt[i];
    }

    // Calculate turnaround time for each process
    for (i = 0; i < n; i++) {
        tat[i] = wt[i] + bt[i];
        sum_turnaround += tat[i];
    }

    // Calculate average waiting time and average turnaround time
    avg_wait = (float)sum_wait / n;
    avg_turnaround = (float)sum_turnaround / n;

    // Print process details
    printf("\nProcess\tBT\tPriority\tWT\tTAT\n");
    for (i = 0; i < n; i++) {
        printf("P%d\t%d\t%d\t\t%d\t%d\n", i + 1, bt[i], priority[i], wt[i], tat[i]);
    }

    // Print average waiting time and average turnaround time
    printf("\nAverage Waiting Time: %.2f\n", avg_wait);
    printf("Average Turnaround Time: %.2f\n", avg_turnaround);

    return 0;
}
#include <stdio.h>

int main() {
    int n, tq, i, total_time = 0, time = 0, flag = 0;
    int bt[10], rem_bt[10], wt[10], tat[10]; // Burst times, remaining burst times, waiting times, turnaround times
    float avg_wt = 0, avg_tat = 0;

    printf("Enter the number of processes: ");
    scanf("%d", &n);

    printf("Enter the burst time for each process:\n");
    for (i = 0; i < n; i++) {
        printf("P[%d]: ", i + 1);
        scanf("%d", &bt[i]);
        rem_bt[i] = bt[i]; // Initialize remaining burst time as burst time
    }

    printf("Enter the time quantum: ");
    scanf("%d", &tq);

    while (1) {
        flag = 0;
        for (i = 0; i < n; i++) {
            if (rem_bt[i] > 0) {
                flag = 1; // There is a pending process

                if (rem_bt[i] > tq) {
                    time += tq;
                    rem_bt[i] -= tq;
                } else {
                    time += rem_bt[i];
                    wt[i] = time - bt[i]; // Waiting time is current time minus burst time
                    rem_bt[i] = 0;
                }
            }
        }
        
        if (flag == 0) // All processes are done
            break;
    }

    printf("\nProcess\tBT\tWT\tTAT\n");
    for (i = 0; i < n; i++) {
        tat[i] = bt[i] + wt[i]; // Turnaround time is burst time plus waiting time
        avg_wt += wt[i];
        avg_tat += tat[i];
        printf("P[%d]\t%d\t%d\t%d\n", i + 1, bt[i], wt[i], tat[i]);
    }

    avg_wt /= n;
    avg_tat /= n;

    printf("\nAverage Waiting Time: %.2f", avg_wt);
    printf("\nAverage Turnaround Time: %.2f", avg_tat);

    return 0;
}
#include <stdio.h>

int main() {
    int n, i, j, min_bt, time = 0, completed = 0, sum_wait = 0, sum_turnaround = 0;
    int at[10], bt[10], rt[10], p[10]; // Arrays for arrival times, burst times, remaining times, and process numbers
    int wait[10], turnaround[10]; // Arrays for waiting times and turnaround times
    float avg_wait, avg_turnaround;

    printf("Enter the number of processes: ");
    scanf("%d", &n);

    // Input arrival times and burst times for each process
    for (i = 0; i < n; i++) {
        printf("Enter the arrival time and burst time for process %d: ", i + 1);
        scanf("%d%d", &at[i], &bt[i]);
        rt[i] = bt[i]; // Initialize remaining time as burst time
        p[i] = i + 1; // Process numbers
    }

    // Initialize arrays for waiting and turnaround times
    for (i = 0; i < n; i++) {
        wait[i] = 0;
        turnaround[i] = 0;
    }

    printf("\nProcess\tAT\tBT\tWT\tTAT\n");

    while (completed != n) {
        // Find process with minimum remaining time at each time unit
        min_bt = 9999; // A large number to find the minimum burst time
        int shortest = -1; // Index of the process with the shortest remaining time

        for (i = 0; i < n; i++) {
            if (at[i] <= time && rt[i] > 0 && rt[i] < min_bt) {
                min_bt = rt[i];
                shortest = i;
            }
        }

        if (shortest == -1) {
            // No process is currently available to execute
            time++;
            continue;
        }

        rt[shortest]--; // Decrement the remaining time of the shortest process

        if (rt[shortest] == 0) {
            // Process is completed
            completed++;
            int end_time = time + 1; // Time at which the process completes
            turnaround[shortest] = end_time - at[shortest]; // Turnaround time
            wait[shortest] = turnaround[shortest] - bt[shortest]; // Waiting time
            sum_wait += wait[shortest];
            sum_turnaround += turnaround[shortest];

            printf("P[%d]\t%d\t%d\t%d\t%d\n", p[shortest], at[shortest], bt[shortest], wait[shortest], turnaround[shortest]);
        }

        time++; // Increment time
    }

    avg_wait = (float)sum_wait / (float)n;
    avg_turnaround = (float)sum_turnaround / (float)n;

    printf("Average waiting time is %.2f\n", avg_wait);
    printf("Average turnaround time is %.2f\n", avg_turnaround);

    return 0;
}
#include <stdio.h>

int main() {
    int n, i, j, temp, time = 0, count, completed = 0, sum_wait = 0, sum_turnaround = 0, start;
    float avg_wait, avg_turnaround;
    int at[10], bt[10], p[10]; // Arrays for arrival times, burst times, and process numbers

    printf("Enter the number of processes: ");
    scanf("%d", &n);

    // Input arrival times and burst times for each process
    for (i = 0; i < n; i++) {
        printf("Enter the arrival time and burst time for process %d: ", i + 1);
        scanf("%d%d", &at[i], &bt[i]);
        p[i] = i + 1;
    }

    // Sort processes by arrival times, and then by burst times
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (at[i] > at[j] || (at[i] == at[j] && bt[i] > bt[j])) {
                temp = at[i];
                at[i] = at[j];
                at[j] = temp;
                temp = bt[i];
                bt[i] = bt[j];
                bt[j] = temp;
                temp = p[i];
                p[i] = p[j];
                p[j] = temp;
            }
        }
    }

    printf("\nProcess\tAT\tBT\tWT\tTAT\n");

    // Main loop to calculate waiting times and turnaround times
    while (completed < n) {
        count = 0;
        for (i = completed; i < n; i++) {
            if (at[i] <= time) {
                count++;
            } else {
                break;
            }
        }

        // Sort the ready processes by burst time
        if (count > 1) {
            for (i = completed; i < completed + count - 1; i++) {
                for (j = i + 1; j < completed + count; j++) {
                    if (bt[i] > bt[j]) {
                        temp = at[i];
                        at[i] = at[j];
                        at[j] = temp;
                        temp = bt[i];
                        bt[i] = bt[j];
                        bt[j] = temp;
                        temp = p[i];
                        p[i] = p[j];
                        p[j] = temp;
                    }
                }
            }
        }

        start = time;
        time += bt[completed];
        printf("P[%d]\t%d\t%d\t%d\t%d\n", p[completed], at[completed], bt[completed], time - at[completed] - bt[completed], time - at[completed]);
        sum_wait += time - at[completed] - bt[completed];
        sum_turnaround += time - at[completed];
        completed++;
    }

    avg_wait = (float)sum_wait / (float)n;
    avg_turnaround = (float)sum_turnaround / (float)n;

    printf("Average waiting time is %.2f\n", avg_wait);
    printf("Average turnaround time is %.2f\n", avg_turnaround);

    return 0;
}
//FCFS                                                                                     #include<stdio.h>
int main(void)
{
      int n,at[10],bt[10],ct[10],tat[10],wt[10],sum,i,j,k;
      float totaltat=0,totalwt=0;
      printf("Enter No of processors:");
      scanf(" %d",&n);
      for(i=0;i<n;i++)
      {
            printf("Enter the arrival time of processor %d:",i+1);
            scanf(" %d",&at[i]);
      }
      for(i=0;i<n;i++)
      {
            printf("Enter the burst time of processor %d:",i+1);
            scanf(" %d",&bt[i]);
      }
      //Calculation of completion times for each processor
      sum=at[0];
      for(j=0;j<n;j++)
      {
            sum=sum+bt[j];
            ct[j]=sum;
      }
      //Calculation of turn around time
      for(k=0;k<n;k++)
      {
            tat[k]=ct[k]-at[k];
            totaltat=totaltat+tat[k];
      }
      //Calculation of waiting time
      for(i=0;i<n;i++)
      {
            wt[i]=tat[i]-bt[i];
            totalwt=totalwt+wt[i];
      }
      printf("Process\tAT\tBT\tCT\tTAT\tWt\n");
      for(i=0;i<n;i++)
      {
            printf("\nP%d\t%d\t%d\t%d\t%d\t%d\t\n",i+1,at[i],bt[i],ct[i],tat[i],wt[i]);
      }
      printf("average of turn around time:%0.1f\n",totaltat/n);
      printf("average of waiting time:%0.1f\n",totalwt/n);
      return 0;
}
FCFS-CPU SCHEDULING
//FCFS                                                                                                         #include<stdio.h>
int main(void)
{
      int n,at[10],bt[10],ct[10],tat[10],wt[10],sum,i,j,k;
      float totaltat=0,totalwt=0;
      printf("Enter No of processors:");
      scanf(" %d",&n);
      for(i=0;i<n;i++)
      {
            printf("Enter the arrival time of processor %d:",i+1);
            scanf(" %d",&at[i]);
      }
      for(i=0;i<n;i++)
      {
            printf("Enter the burst time of processor %d:",i+1);
            scanf(" %d",&bt[i]);
      }
      //Calculation of completion times for each processor
      sum=at[0];
      for(j=0;j<n;j++)
      {
            sum=sum+bt[j];
            ct[j]=sum;
      }
      //Calculation of turn around time
      for(k=0;k<n;k++)
      {
            tat[k]=ct[k]-at[k];
            totaltat=totaltat+tat[k];
      }
      //Calculation of waiting time
      for(i=0;i<n;i++)
      {
            wt[i]=tat[i]-bt[i];
            totalwt=totalwt+wt[i];
      }
      printf("Process\tAT\tBT\tCT\tTAT\tWt\n");
      for(i=0;i<n;i++)
      {
            printf("\nP%d\t%d\t%d\t%d\t%d\t%d\t\n",i+1,at[i],bt[i],ct[i],tat[i],wt[i]);
      }
      printf("average of turn around time:%0.1f\n",totaltat/n);
      printf("average of waiting time:%0.1f\n",totalwt/n);
      return 0;
}
SJF-NON PREEMPTIVE
#include <stdio.h>

int main() {
    int n, i, j, temp, time = 0, count, completed = 0, sum_wait = 0, sum_turnaround = 0, start;
    float avg_wait, avg_turnaround;
    int at[10], bt[10], p[10]; // Arrays for arrival times, burst times, and process numbers

    printf("Enter the number of processes: ");
    scanf("%d", &n);

    // Input arrival times and burst times for each process
    for (i = 0; i < n; i++) {
        printf("Enter the arrival time and burst time for process %d: ", i + 1);
        scanf("%d%d", &at[i], &bt[i]);
        p[i] = i + 1;
    }

    // Sort processes by arrival times, and then by burst times
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (at[i] > at[j] || (at[i] == at[j] && bt[i] > bt[j])) {
                temp = at[i];
                at[i] = at[j];
                at[j] = temp;
                temp = bt[i];
                bt[i] = bt[j];
                bt[j] = temp;
                temp = p[i];
                p[i] = p[j];
                p[j] = temp;
            }
        }
    }

    printf("\nProcess\tAT\tBT\tWT\tTAT\n");

    // Main loop to calculate waiting times and turnaround times
    while (completed < n) {
        count = 0;
        for (i = completed; i < n; i++) {
            if (at[i] <= time) {
                count++;
            } else {
                break;
            }
        }

        // Sort the ready processes by burst time
        if (count > 1) {
            for (i = completed; i < completed + count - 1; i++) {
                for (j = i + 1; j < completed + count; j++) {
                    if (bt[i] > bt[j]) {
                        temp = at[i];
                        at[i] = at[j];
                        at[j] = temp;
                        temp = bt[i];
                        bt[i] = bt[j];
                        bt[j] = temp;
                        temp = p[i];
                        p[i] = p[j];
                        p[j] = temp;
                    }
                }
            }
        }

        start = time;
        time += bt[completed];
        printf("P[%d]\t%d\t%d\t%d\t%d\n", p[completed], at[completed], bt[completed], time - at[completed] - bt[completed], time - at[completed]);
        sum_wait += time - at[completed] - bt[completed];
        sum_turnaround += time - at[completed];
        completed++;
    }

    avg_wait = (float)sum_wait / (float)n;
    avg_turnaround = (float)sum_turnaround / (float)n;

    printf("Average waiting time is %.2f\n", avg_wait);
    printf("Average turnaround time is %.2f\n", avg_turnaround);

    return 0;
}
SRTF(SJF-PREEMPTIVE)
#include <stdio.h>

int main() {
    int n, i, j, min_bt, time = 0, completed = 0, sum_wait = 0, sum_turnaround = 0;
    int at[10], bt[10], rt[10], p[10]; // Arrays for arrival times, burst times, remaining times, and process numbers
    int wait[10], turnaround[10]; // Arrays for waiting times and turnaround times
    float avg_wait, avg_turnaround;

    printf("Enter the number of processes: ");
    scanf("%d", &n);

    // Input arrival times and burst times for each process
    for (i = 0; i < n; i++) {
        printf("Enter the arrival time and burst time for process %d: ", i + 1);
        scanf("%d%d", &at[i], &bt[i]);
        rt[i] = bt[i]; // Initialize remaining time as burst time
        p[i] = i + 1; // Process numbers
    }

    // Initialize arrays for waiting and turnaround times
    for (i = 0; i < n; i++) {
        wait[i] = 0;
        turnaround[i] = 0;
    }

    printf("\nProcess\tAT\tBT\tWT\tTAT\n");

    while (completed != n) {
        // Find process with minimum remaining time at each time unit
        min_bt = 9999; // A large number to find the minimum burst time
        int shortest = -1; // Index of the process with the shortest remaining time

        for (i = 0; i < n; i++) {
            if (at[i] <= time && rt[i] > 0 && rt[i] < min_bt) {
                min_bt = rt[i];
                shortest = i;
            }
        }

        if (shortest == -1) {
            // No process is currently available to execute
            time++;
            continue;
        }

        rt[shortest]--; // Decrement the remaining time of the shortest process

        if (rt[shortest] == 0) {
            // Process is completed
            completed++;
            int end_time = time + 1; // Time at which the process completes
            turnaround[shortest] = end_time - at[shortest]; // Turnaround time
            wait[shortest] = turnaround[shortest] - bt[shortest]; // Waiting time
            sum_wait += wait[shortest];
            sum_turnaround += turnaround[shortest];

            printf("P[%d]\t%d\t%d\t%d\t%d\n", p[shortest], at[shortest], bt[shortest], wait[shortest], turnaround[shortest]);
        }

        time++; // Increment time
    }

    avg_wait = (float)sum_wait / (float)n;
    avg_turnaround = (float)sum_turnaround / (float)n;

    printf("Average waiting time is %.2f\n", avg_wait);
    printf("Average turnaround time is %.2f\n", avg_turnaround);

    return 0;
}


ROUND ROBIN PROGRAM
#include <stdio.h>

int main() {
    int n, tq, i, total_time = 0, time = 0, flag = 0;
    int bt[10], rem_bt[10], wt[10], tat[10]; // Burst times, remaining burst times, waiting times, turnaround times
    float avg_wt = 0, avg_tat = 0;

    printf("Enter the number of processes: ");
    scanf("%d", &n);

    printf("Enter the burst time for each process:\n");
    for (i = 0; i < n; i++) {
        printf("P[%d]: ", i + 1);
        scanf("%d", &bt[i]);
        rem_bt[i] = bt[i]; // Initialize remaining burst time as burst time
    }

    printf("Enter the time quantum: ");
    scanf("%d", &tq);

    while (1) {
        flag = 0;
        for (i = 0; i < n; i++) {
            if (rem_bt[i] > 0) {
                flag = 1; // There is a pending process

                if (rem_bt[i] > tq) {
                    time += tq;
                    rem_bt[i] -= tq;
                } else {
                    time += rem_bt[i];
                    wt[i] = time - bt[i]; // Waiting time is current time minus burst time
                    rem_bt[i] = 0;
                }
            }
        }
        
        if (flag == 0) // All processes are done
            break;
    }

    printf("\nProcess\tBT\tWT\tTAT\n");
    for (i = 0; i < n; i++) {
        tat[i] = bt[i] + wt[i]; // Turnaround time is burst time plus waiting time
        avg_wt += wt[i];
        avg_tat += tat[i];
        printf("P[%d]\t%d\t%d\t%d\n", i + 1, bt[i], wt[i], tat[i]);
    }

    avg_wt /= n;
    avg_tat /= n;

    printf("\nAverage Waiting Time: %.2f", avg_wt);
    printf("\nAverage Turnaround Time: %.2f", avg_tat);

    return 0;
}
PRIORITY PROGRAM
#include <stdio.h>

int main() {
    int n, i, j, temp, sum_wait = 0, sum_turnaround = 0;
    float avg_wait, avg_turnaround;
    int priority[20], bt[20], wt[20], tat[20];

    printf("Enter the number of processes: ");
    scanf("%d", &n);

    // Input burst times and priorities for each process
    printf("Enter burst times and priorities for each process:\n");
    for (i = 0; i < n; i++) {
        printf("Process %d: ", i + 1);
        scanf("%d%d", &bt[i], &priority[i]);
    }

    // Sort processes based on priority (ascending order)
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (priority[i] > priority[j]) {
                temp = priority[i];
                priority[i] = priority[j];
                priority[j] = temp;
                temp = bt[i];
                bt[i] = bt[j];
                bt[j] = temp;
            }
        }
    }

    // Calculate waiting time for each process
    wt[0] = 0; // Waiting time for first process is zero
    for (i = 1; i < n; i++) {
        wt[i] = wt[i - 1] + bt[i - 1];
        sum_wait += wt[i];
    }

    // Calculate turnaround time for each process
    for (i = 0; i < n; i++) {
        tat[i] = wt[i] + bt[i];
        sum_turnaround += tat[i];
    }

    // Calculate average waiting time and average turnaround time
    avg_wait = (float)sum_wait / n;
    avg_turnaround = (float)sum_turnaround / n;

    // Print process details
    printf("\nProcess\tBT\tPriority\tWT\tTAT\n");
    for (i = 0; i < n; i++) {
        printf("P%d\t%d\t%d\t\t%d\t%d\n", i + 1, bt[i], priority[i], wt[i], tat[i]);
    }

    // Print average waiting time and average turnaround time
    printf("\nAverage Waiting Time: %.2f\n", avg_wait);
    printf("Average Turnaround Time: %.2f\n", avg_turnaround);

    return 0;
}
BANKERS ALGORITHM
#include <stdio.h>
int main() {
    int n, m, i, j, k;

    // Get the number of processes and resources from the user
    printf("Enter the number of processes: ");
    scanf("%d", &n);
    printf("Enter the number of resources: ");
    scanf("%d", &m);

    int alloc[n][m], max[n][m], avail[m];

    // Get the Allocation Matrix from the user
    printf("Enter the Allocation Matrix:\n");
    for (i = 0; i < n; i++) {
        printf("Process %d:\n", i);
        for (j = 0; j < m; j++) {
            scanf("%d", &alloc[i][j]);
        }
    }

    // Get the Maximum Matrix from the user
    printf("Enter the Maximum Matrix:\n");
    for (i = 0; i < n; i++) {
        printf("Process %d:\n", i);
        for (j = 0; j < m; j++) {
            scanf("%d", &max[i][j]);
        }
    }

    // Get the Available Resources from the user
    printf("Enter the Available Resources:\n");
    for (i = 0; i < m; i++) {
        scanf("%d", &avail[i]);
    }

    int f[n], ans[n], ind = 0;
    for (k = 0; k < n; k++) {
        f[k] = 0;
    }

    int need[n][m];
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            need[i][j] = max[i][j] - alloc[i][j];
        }
    }

    int y = 0;
    for (k = 0; k < n; k++) {
        for (i = 0; i < n; i++) {
            if (f[i] == 0) {
                int flag = 0;
                for (j = 0; j < m; j++) {
                    if (need[i][j] > avail[j]) {
                        flag = 1;
                        break;
                    }
                }

                if (flag == 0) {
                    ans[ind++] = i;
                    for (y = 0; y < m; y++) {
                        avail[y] += alloc[i][y];
                    }
                    f[i] = 1;
                }
            }
        }
    }

    int flag = 1;
    for (i = 0; i < n; i++) {
        if (f[i] == 0) {
            flag = 0;
            printf("The system is not in a safe state.\n");
            break;
        }
    }

    if (flag == 1) {
        printf("The system is in a safe state.\nSafe sequence is: ");
        for (i = 0; i < n - 1; i++) {
            printf("P%d -> ", ans[i]);
        }
        printf("P%d\n", ans[n - 1]);
    }

    return 0;
}
PRODUCER-CONSUMER PROBLEM
#include<stdio.h>
#include<stdlib.h>
int mutex=1,full=0,empty=3,x=0;
int main()
{
   int n;
   void producer();
   void consumer();
   int wait(int);
   int signal(int);
   printf("\n 1.Producer \n 2.Consumer \n 3.Exit");
   while(1)
   {
      printf("\nEnter your choice:");
      scanf("%d",&n);
      switch(n)
      {
         case 1:
                 if((mutex==1)&&(empty!=0))
                    producer();
                 else
                    printf("Buffer is full");
     break;
         case 2:
             if((mutex==1)&&(full!=0))
    consumer();
    else
        printf("Buffer is empty");
       break;
         case 3:
    exit(0);
    break;
      }
   }
}
int wait(int s)
{
   return (--s);
}
int signal(int s)
{
   return(++s);
}
void producer()
{
   mutex=wait(mutex);
   full=signal(full);
   empty=wait(empty);
   x++;
   printf("Producer produces the item %d\n",x);
   mutex=signal(mutex);
}
void consumer()
{
   mutex=wait(mutex);
   full=wait(full);
   empty=signal(empty);
   printf("Consumer consumes item %d\n",x);
   x--;
   mutex=signal(mutex);
}
FCFS-PAGE REPLACEMENT ALGORITHM
//FIFO PAGE REPLACEMENT ALGORITHM
#include<stdio.h>
#include<conio.h>
int main()
{
int i, j, k, f, pf=0, count=0, rs[25], m[10], n;
printf("\n Enter the length of reference string -- ");
scanf("%d",&n);
printf("\n Enter the reference string -- ");
 for(i=0;i<n;i++)
scanf("%d",&rs[i]);
 printf("\n Enter no. of frames -- ");
 scanf("%d",&f);
for(i=0;i<f;i++)
m[i]=-1;

printf("\n The Page Replacement Process is -- \n");
 for(i=0;i<n;i++)
{
for(k=0;k<f;k++)
{
  if(m[k]==rs[i])
  break;

}
if(k==f)
{
m[count++]=rs[i];
pf++;

}

for(j=0;j<f;j++)
printf("\t%d",m[j]);
if(k==f)
printf("\tPF No. %d",pf);
printf("\n");
if(count==f)
count=0;
}
printf("\n The number of Page Faults using FIFO are %d",pf);
getch();
}
2.LRU PAGE REPLACEMENT ALGORITHM
//LRU
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j , k, min, rs[25], m[10], count[10], flag[25], n, f, pf=0, next=1;
//clrscr();
printf("Enter the length of reference string -- ");
 scanf("%d",&n);
printf("Enter the reference string -- ");
 for(i=0;i<n;i++)
{
scanf("%d",&rs[i]);
flag[i]=0;
}
printf("Enter the number of frames -- ");
 scanf("%d",&f);
for(i=0;i<f;i++)

{
count[i]=0;
m[i]=-1;
}
printf("\nThe Page Replacement process is -- \n");
 for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
{
if(m[j]==rs[i])
{
flag[i]=1;
count[j]=next;
 next++;
}

}
if(flag[i]==0)
{

if(i<f)
{  m[i]=rs[i];
   count[i]=next;
   next++;
 }
else
{ min=0;
for(j=1;j<f;j++)
if(count[min] > count[j])
  min=j;

m[min]=rs[i];
 count[min]=next;
  next++;


}
pf++;
}

for(j=0;j<f;j++)
printf("%d\t", m[j]);
 if(flag[i]==0)
printf("PF No. -- %d" , pf);
 printf("\n");
}
printf("\nThe number of page faults using LRU are %d",pf);
 getch();
}



3.OPTIMAL PAGE REPLACEMENT ALGORITHM
//Optimal page replacement
#include<stdio.h>
int n;
int main()
{
int seq[30],fr[5],pos[5],find,flag,max,i,j,m,k,t,s;
int count=1,pf=0,p=0;
float pfr;
printf("Enter maximum limit of the sequence: ");
scanf("%d",&max);
printf("\nEnter the sequence: ");
 for(i=0;i<max;i++)
scanf("%d",&seq[i]);
 printf("\nEnter no. of frames: ");
 scanf("%d",&n);
fr[0]=seq[0];
pf++;
printf("%d\t",fr[0]);
i=1;
while(count<n)
{
flag=1; p++;
for(j=0;j<i;j++)
{
if(seq[i]==seq[j]) flag=0;
}
if(flag!=0)
{
 fr[count]=seq[i];
 printf("%d\t",fr[count]);
 count++;
pf++;

}
i++;
}
 
printf("\n");
for(i=p;i<max;i++)
{
flag=1;
for(j=0;j<n;j++)
{
if(seq[i]==fr[j])
flag=0;
}
if(flag!=0)

{
for(j=0;j<n;j++)
{
m=fr[j];
for(k=i;k<max;k++)
{
if(seq[k]==m)
{
    pos[j]=k;
     break;

 }
else
pos[j]=1;

}
}
for(k=0;k<n;k++)
{
if(pos[k]==1)
flag=0;
}
if(flag!=0)
s=findmax(pos);
 if(flag==0)
{
for(k=0;k<n;k++)
{
if(pos[k]==1)
{
s=k;
 break;
}
}
}
fr[s]=seq[i];
for(k=0;k<n;k++)
printf("%d\t",fr[k]);
pf++;
printf("\n");
}
}
pfr=(float)pf/(float)max;
printf("\nThe no. of page faults are %d",pf);
printf("\nPage fault rate %f",pfr);
getch();
}
int findmax(int a[])
{
int max,i,k=0;
max=a[0];
for(i=0;i<n;i++)
{
if(max<a[i])
{
  max=a[i];
   k=i;
}
}
return k;
}
#include <stdio.h>

int main() {
    int n, m, i, j, k;

    // Get the number of processes and resources from the user
    printf("Enter the number of processes: ");
    scanf("%d", &n);
    printf("Enter the number of resources: ");
    scanf("%d", &m);

    int alloc[n][m], max[n][m], avail[m];

    // Get the Allocation Matrix from the user
    printf("Enter the Allocation Matrix:\n");
    for (i = 0; i < n; i++) {
        printf("Process %d:\n", i);
        for (j = 0; j < m; j++) {
            scanf("%d", &alloc[i][j]);
        }
    }

    // Get the Maximum Matrix from the user
    printf("Enter the Maximum Matrix:\n");
    for (i = 0; i < n; i++) {
        printf("Process %d:\n", i);
        for (j = 0; j < m; j++) {
            scanf("%d", &max[i][j]);
        }
    }

    // Get the Available Resources from the user
    printf("Enter the Available Resources:\n");
    for (i = 0; i < m; i++) {
        scanf("%d", &avail[i]);
    }

    int f[n], ans[n], ind = 0;
    for (k = 0; k < n; k++) {
        f[k] = 0;
    }

    int need[n][m];
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            need[i][j] = max[i][j] - alloc[i][j];
        }
    }

    int y = 0;
    for (k = 0; k < n; k++) {
        for (i = 0; i < n; i++) {
            if (f[i] == 0) {
                int flag = 0;
                for (j = 0; j < m; j++) {
                    if (need[i][j] > avail[j]) {
                        flag = 1;
                        break;
                    }
                }

                if (flag == 0) {
                    ans[ind++] = i;
                    for (y = 0; y < m; y++) {
                        avail[y] += alloc[i][y];
                    }
                    f[i] = 1;
                }
            }
        }
    }

    int flag = 1;
    for (i = 0; i < n; i++) {
        if (f[i] == 0) {
            flag = 0;
            printf("The system is not in a safe state.\n");
            break;
        }
    }

    if (flag == 1) {
        printf("The system is in a safe state.\nSafe sequence is: ");
        for (i = 0; i < n - 1; i++) {
            printf("P%d -> ", ans[i]);
        }
        printf("P%d\n", ans[n - 1]);
    }

    return 0;
}
$('a[data-scroll]').click(function (e) {
	e.preventDefault();

	//Set Offset Distance from top to account for fixed nav

	var offset = 10;

	var target = '#' + $(this).data('scroll');

	var $target = $(target);

	//Animate the scroll to, include easing lib if you want more fancypants easings

	$('html, body')
		.stop()
		.animate(
			{
				scrollTop: $target.offset().top - offset,
			},
			800,	
			'swing',
		);
});

//jQuery

//jQuery('a[data-scroll]').click(function (e) {
// 	e.preventDefault();

// 	// Set Offset Distance from top to account for fixed nav
// 	var offset = 10;

// 	var target = '#' + jQuery(this).data('scroll');
// 	var $target = jQuery(target);

// 	// Animate the scroll to, include easing lib if you want more fancypants easings
// 	jQuery('html, body')
// 		.stop()
// 		.animate(
// 			{
// 				scrollTop: $target.offset().top - offset,
// 			},
// 			800,
// 			'swing',
// 		);
// });
	this.$burger = this.$element.find('.header__burger');
			this.$navBodyItems = this.$element.find(
				'.header__popup-menu .col-lg-3.col-md-6.col-12',
			);

			const tl = gsap.timeline();
			tl.fromTo(
				this.$navBodyItems,
				{ opacity: 0, y: -500 },
				{ opacity: 1, y: 0, duration: 1 },
			);

			this.$burger.on('click', (event) => {
				event.preventDefault();
				if (tl.reversed()) {
					tl.play();
				} else {
					tl.reverse();
				}
			});
// use while loops when the number of items we are looping over are unknown


let items = [
  { id: 1, name: "Item 1", price: 10.99 },
  { id: 2, name: "Item 2", price: 15.49 },
  { id: 3, name: "Item 3", price: 7.99 },
  { id: 4, name: "Item 4", price: 12.0 },
  { id: 5, name: "Item 5", price: 9.5 },
];

let i = 0; // counter variable

let numberOfItems = items.length ?? 0; // if the number of items is not a number give me 0;
console.log(numberOfItems);

while (i < items.length) {
  let { id, name, price } = items[i]; // Destructuring assignment
  console.log(`ID: ${id}, Name: ${name}, Price: $${price}`);
  i++;
}
CREATE TABLE `user_activity` (
  `id` int NOT NULL AUTO_INCREMENT,
  `username` varchar(150) DEFAULT NULL,
  `login_time` datetime DEFAULT NULL,
  `logout_time` datetime DEFAULT NULL,
  `path_info` varchar(255) DEFAULT NULL,
  `api_hit` tinyint(1) DEFAULT '0',
  `response_time` bigint DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT '',
  `timestamp` datetime DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=117382 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;


CREATE TABLE `user_session` (
  `id` int NOT NULL AUTO_INCREMENT,
  `username` varchar(150) DEFAULT '',
  `login_time` datetime NOT NULL,
  `logout_time` datetime DEFAULT NULL,
  `session_duration_seconds` int DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=98 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
 1class ContactForm extends Component
 2{
 3    public $name;
 4    public $email;
 5 
 6    protected $rules = [
 7        'name' => 'required|min:6',
 8        'email' => 'required|email',
 9    ];
10 
11    public function updated($propertyName)
12    {
13        $this->validateOnly($propertyName);
14    }
15 
16    public function saveContact()
17    {
18        $validatedData = $this->validate();
19 
20        Contact::create($validatedData);
21    }
22}
gcloud compute ssh --zone YOUR_ZONE YOUR_INSTANCE_NAME -- -L 8888:localhost:8888
    
1<div>
2    <input wire:model="message" type="text">
3 
4    <h1>{{ $message }}</h1>
5</div>

//data binding 
 1public $search = '';
 2public $isActive = true;
 3 
 4public function resetFilters()
 5{
 6    $this->reset('search');
 7    // Will only reset the search property.
 8 
 9    $this->reset(['search', 'isActive']);
10    // Will reset both the search AND the isActive property.
11 
12    $this->resetExcept('search');
13    // Will only reset the isActive property (any property but the search property).
14}
1class HelloWorld extends Component
2{
3    public $message;
4       //initializing properties witht the property
5    public function mount()
6    {
7        $this->message = 'Hello World!';
8    }
9}
 1public $search = '';
 2public $isActive = true;
 3 
 4public function resetFilters()
 5{
 6    $this->reset('search');
 7    // Will only reset the search property.
 8 
 9    $this->reset(['search', 'isActive']);
10    // Will reset both the search AND the isActive property.
11 
12    $this->resetExcept('search');
13    // Will only reset the isActive property (any property but the search property).
14}
<script>
  async function harryPotterStudents() {
      const res = await fetch('https://hp-api.herokuapp.com/api/characters/students');
      const json = await res.json()

      if (res.ok) {
          return json
      } else {
          throw new Error(json)
      }
  }

  let promise = harryPotterStudents()
</script>

<h2>Estudiantes de la saga Harry Potter (promesas)</h2>
{#await promise}
  <p>Esperando resultados...</p>
{:then students}
  <p>Total estudiantes: {students.length}</p>
  {#each students as {name: alt, house, image: src}}
    {#if src}
      <h3>{alt} ({house})</h3>
      <img height="100" {src} {alt} />
    {/if}
  {/each}
{:catch error}
  <p style="color: red">{error.message}</p>
{/await}
declare 
   invalid_sal Exception;
   s employee.sal%type:=&sal;
begin 
   if (s<3000) then
     raise invalid_sal;
   else
     insert into employee(sal) values(s);
     dbms_output.put_line('Record inserted');
   end if;
Exception
      when invalid_sal then
           dbms_output.put_line('sal greater ');
end;
/
/*
 * @Author: allen_
 * @Date: 2024-05-22 10:45:18
 * @Email: zhangxudong_a@aspirecn.com
 * @LastEditors: allen_
 * @LastEditTime: 2024-05-23 15:43:17
 * @Description: 水印
 * @example:
 *   watermark.set(this.$refs.body, { text: '水印文字', gap: [50, 100], fontSize: 14, color: 'rgba(0, 0, 0, 0.35)'})
 */
import html2canvas from 'html2canvas'
const watermark = {}

/**
 * @description: 设置水印
 * @param {*} sourceBody 需要设置的元素
 * @param {*} text 水印文字
 * @param {array} gap 水印间距 [上下间距, 左右间距]
 * @param {*} fontSize 水印文字大小
 * @param {*} color 水印字体颜色
 * @param {*} zIndex 水印层级
 * @param {*} rotate 水印角度
 */
const setWatermark = (sourceBody, { text = 'watermark', gap = [100, 120], fontSize = 14, color = 'rgba(0, 0, 0, 0.25)', zIndex = 9999, rotate = -22, custom = null }) => {
  // @Explain: 生成随机元素 id
  const id = Math.random() * 10000 + '-' + Math.random() * 10000 + '/' + Math.random() * 10000

  if (document.getElementById(id) !== null) {
    document.body.removeChild(document.getElementById(id))
  }
  let canvasData = null
  if (!custom) {
    const can = document.createElement('canvas')
    can.height = gap[0] // 水印上下间距
    can.width = gap[1] // 水印左右间距

    const cans = can.getContext('2d')
    cans.rotate((rotate * Math.PI) / 180)
    cans.font = fontSize + 'px Microsoft YaHei'
    cans.fillStyle = color
    cans.textAlign = 'left'
    cans.textBaseline = 'Middle'
    cans.fillText(text, can.width / 20, can.height / 3)
    canvasData = can.toDataURL('image/png', 1.0)
  } else {
    canvasData = custom
  }

  const water_div = document.createElement('div')
  water_div.id = id
  water_div.className = 'watermark-body'
  const styleStr = `
    background: url(${canvasData}) left top repeat;
    pointer-events: none;
    width: 100%;
    height: 100%;
    position: absolute;
    z-index: ${zIndex};
    top: 0px;
    left: 0px;
  `
  water_div.setAttribute('style', styleStr)
  const partnerStyle = `
    ${sourceBody.getAttribute('style') || ''}
    position: relative;
    userSelect: none;
  `
  sourceBody.setAttribute('style', partnerStyle)
  sourceBody.appendChild(water_div)

  // 防止水印被删除
  const observer = new MutationObserver(() => {
    const wmInstance = document.getElementById(id)
    if ((wmInstance && wmInstance.getAttribute('style') !== styleStr) || !wmInstance) {
      // 如果标签在,只修改了属性,重新赋值属性
      if (wmInstance) {
        // 避免一直触发 -- 水印属性修改了
        wmInstance.setAttribute('style', styleStr)
      } else {
        // observer.disconnect()
        sourceBody.appendChild(water_div)
      }
    } else if (sourceBody.getAttribute('style') !== partnerStyle) {
      // @Explain: 判断父元素样式是否存在更改
      sourceBody.setAttribute('style', partnerStyle)
    }
  })
  observer.observe(sourceBody, {
    attributes: true,
    subtree: true,
    childList: true
  })

  return id
}

// @Explain: 为元素设置水印
watermark.set = (sourceBody, opi) => {
  const domArr = Array.from(document.getElementsByClassName('watermark-body'))
  for (let i = domArr.length; i--;) {
    const element = domArr[i]
    element.remove()
  }
  if ((!opi.text && !opi.custom) || !sourceBody) return null
  if (!(sourceBody instanceof HTMLElement)) {
    // @Condition: 判断传入的元素是否为dom元素 || VueComponent
    sourceBody = sourceBody.$el
  }
  const id = setWatermark(sourceBody, opi)
  return id
}
// @Explain: html2canvas 创建元素 base64
watermark.baseImg = (el, scale = window.devicePixelRatio < 3 ? window.devicePixelRatio : 2) => {
  return new Promise((resolve) => {
    html2canvas(el, {
      useCORS: true, // 【重要】开启跨域配置
      scale,
      allowTaint: true, // 允许跨域图片
      backgroundColor: null // 是否设置背景色透明
    }).then((canvas) => {
      const imgData = canvas.toDataURL('img/jpg', 1.0)
      resolve(imgData)
    })
  })
}
// @Explain: 创建水印方法
watermark.create = (text = 'watermark', callback = null, cache = true) => {
  if (callback && typeof callback === 'function') {
    // @Condition: 自定义水印元素创建方法
    return callback(text, watermark)
  }
  // @Explain: 判断缓存创建的水印元素是否存在
  if (watermark.cacheEl && cache) {
    watermark.cacheEl.querySelector('.watermark-user-info').innerText = text
    return watermark.cacheEl
  }
  const div = document.createElement('div')
  div.style = `
    width: 200px;
    height: 160px;
    display: flex;
    align-items: center;`
  const watermarkDiv = document.createElement('div')
  watermarkDiv.style = `
    width: 210px;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    transform-origin: center;
    transform: rotate(-35deg);`
  const img = document.createElement('img')
  img.style = 'width: 201px;'
  // if you need image, edit here
  // img.src = require('@/assets/img/watermark.png')
  const userInfo = document.createElement('div')
  userInfo.className = 'watermark-user-info'
  userInfo.style = `
    font-size: 12px;
    color: rgba(38, 42, 48, 0.1);
    letter-spacing: 0;
    font-family: PingFangSC-Regular;`
  userInfo.innerText = text
  watermarkDiv.appendChild(img)
  watermarkDiv.appendChild(userInfo)
  div.appendChild(watermarkDiv)
  watermark.cacheEl = div // 缓存水印元素
  return div
}

export default watermark
star

Tue May 28 2024 07:08:22 GMT+0000 (Coordinated Universal Time)

@manhmd #java

star

Tue May 28 2024 03:22:18 GMT+0000 (Coordinated Universal Time) https://www.geeksforgeeks.org/bankers-algorithm-in-operating-system-2/

@rahulk

star

Tue May 28 2024 02:49:53 GMT+0000 (Coordinated Universal Time)

@prabhas

star

Tue May 28 2024 02:49:20 GMT+0000 (Coordinated Universal Time)

@prabhas

star

Tue May 28 2024 02:43:50 GMT+0000 (Coordinated Universal Time)

@python

star

Tue May 28 2024 02:27:26 GMT+0000 (Coordinated Universal Time)

@Asadullah69

star

Mon May 27 2024 23:33:58 GMT+0000 (Coordinated Universal Time)

@ayushg103 #c++

star

Mon May 27 2024 22:16:05 GMT+0000 (Coordinated Universal Time)

@AYWEB #html

star

Mon May 27 2024 21:47:16 GMT+0000 (Coordinated Universal Time)

@AYWEB #html

star

Mon May 27 2024 21:46:23 GMT+0000 (Coordinated Universal Time)

@AYWEB #html

star

Mon May 27 2024 21:26:48 GMT+0000 (Coordinated Universal Time)

@AYWEB #html

star

Mon May 27 2024 21:01:39 GMT+0000 (Coordinated Universal Time)

@AYWEB #html

star

Mon May 27 2024 20:40:14 GMT+0000 (Coordinated Universal Time) https://0xbitx.github.io/0xbit-blog/linux-based-dual-monitor-setup

@samaدghaderi

star

Mon May 27 2024 20:38:44 GMT+0000 (Coordinated Universal Time) https://0xbitx.github.io/0xbit-blog/dedsec-xicomap

@samaدghaderi

star

Mon May 27 2024 20:38:40 GMT+0000 (Coordinated Universal Time) https://0xbitx.github.io/0xbit-blog/dedsec-xicomap

@samaدghaderi

star

Mon May 27 2024 20:35:21 GMT+0000 (Coordinated Universal Time)

@madgakantara

star

Mon May 27 2024 20:32:20 GMT+0000 (Coordinated Universal Time)

@AYWEB #html

star

Mon May 27 2024 20:24:44 GMT+0000 (Coordinated Universal Time)

@Y@sir #subscribeform #subscriptionform

star

Mon May 27 2024 18:34:41 GMT+0000 (Coordinated Universal Time)

@mateo2005

star

Mon May 27 2024 17:32:38 GMT+0000 (Coordinated Universal Time)

@Asadullah69

star

Mon May 27 2024 17:28:17 GMT+0000 (Coordinated Universal Time)

@Asadullah69

star

Mon May 27 2024 16:28:47 GMT+0000 (Coordinated Universal Time)

@user02

star

Mon May 27 2024 16:12:30 GMT+0000 (Coordinated Universal Time)

@user02

star

Mon May 27 2024 16:11:59 GMT+0000 (Coordinated Universal Time)

@user02

star

Mon May 27 2024 16:11:34 GMT+0000 (Coordinated Universal Time)

@user02

star

Mon May 27 2024 16:11:12 GMT+0000 (Coordinated Universal Time)

@user02

star

Mon May 27 2024 16:10:50 GMT+0000 (Coordinated Universal Time)

@user02

star

Mon May 27 2024 16:10:24 GMT+0000 (Coordinated Universal Time)

@user02

star

Mon May 27 2024 16:09:59 GMT+0000 (Coordinated Universal Time)

@user02

star

Mon May 27 2024 16:09:20 GMT+0000 (Coordinated Universal Time)

@user02

star

Mon May 27 2024 16:08:53 GMT+0000 (Coordinated Universal Time)

@user02

star

Mon May 27 2024 16:08:24 GMT+0000 (Coordinated Universal Time)

@user02

star

Mon May 27 2024 15:39:40 GMT+0000 (Coordinated Universal Time)

@prabhas

star

Mon May 27 2024 13:27:16 GMT+0000 (Coordinated Universal Time) https://www.pyramidions.com/android-application-development-company-in-chennai.html

@Steve_1 #androidapp development company in chennai

star

Mon May 27 2024 13:23:58 GMT+0000 (Coordinated Universal Time)

@proxylabs

star

Mon May 27 2024 11:11:57 GMT+0000 (Coordinated Universal Time)

@divyasoni23 #jquery

star

Mon May 27 2024 09:28:28 GMT+0000 (Coordinated Universal Time)

@divyasoni23 #jquery #gsap

star

Mon May 27 2024 08:53:57 GMT+0000 (Coordinated Universal Time) https://www.kryptobees.com/axie-infinity-clone-script

@jackwyatt134 ##axieinfinityclonescript#metaversegame #virtualreality

star

Mon May 27 2024 08:34:18 GMT+0000 (Coordinated Universal Time)

@Shira

star

Mon May 27 2024 08:13:39 GMT+0000 (Coordinated Universal Time)

@davidmchale #while #loop

star

Mon May 27 2024 05:59:30 GMT+0000 (Coordinated Universal Time)

@ajjjuu

star

Mon May 27 2024 05:49:55 GMT+0000 (Coordinated Universal Time) https://laravel-livewire.com/docs/2.x/input-validation

@tsesang

star

Mon May 27 2024 05:03:18 GMT+0000 (Coordinated Universal Time) https://research.google.com/colaboratory/local-runtimes.html

@kris96tian

star

Mon May 27 2024 04:05:18 GMT+0000 (Coordinated Universal Time) https://laravel-livewire.com/docs/2.x/properties

@tsesang

star

Mon May 27 2024 04:04:51 GMT+0000 (Coordinated Universal Time) https://laravel-livewire.com/docs/2.x/properties

@tsesang

star

Mon May 27 2024 04:00:08 GMT+0000 (Coordinated Universal Time) https://laravel-livewire.com/docs/2.x/properties

@tsesang

star

Mon May 27 2024 03:58:04 GMT+0000 (Coordinated Universal Time) https://laravel-livewire.com/docs/2.x/properties

@tsesang

star

Mon May 27 2024 03:07:54 GMT+0000 (Coordinated Universal Time)

@davelauren #javascript #svelte

star

Mon May 27 2024 02:58:35 GMT+0000 (Coordinated Universal Time)

@signup

star

Mon May 27 2024 01:25:59 GMT+0000 (Coordinated Universal Time)

@allen_ #javascript

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension