Tag: D4D4D4

  • In JavaScript, when is the target property used in a forEach() loop?

    In JavaScript, the target property is not directly associated with a forEach() loop itself. However, when you’re using forEach() to iterate over a collection of DOM elements (like those obtained from document.querySelectorAll()), you might encounter the target property if you’re working with event listeners inside the loop.

    Here’s an example:

    document.querySelectorAll('.my-button').forEach(button => {
        button.addEventListener('click', (event) => {
            console.log(event.target);  // This will log the button that was clicked
        });
    });

    In this case, event.target refers to the element that triggered the event (e.g., the button that was clicked). So, while target isn’t specific to the forEach() loop, you may use it inside the loop when handling events on elements.

    In JavaScript, when is the target property used in a forEach() loop?
  • LAMP Stack Setup

    Setup for Ubuntu 20.04 LTS or 22.04 LTS. Lifted from this resource on AWS.

    Linux

    WSL, Ubuntu Multipass, or equivalant.

    Apache

    Version: distribution

    sudo apt update -y
    sudo apt install apache2 -y

    PHP FPM

    Version: 8.2

    Run the following commands to install PHP:

    sudo apt-get install software-properties-common
    sudo add-apt-repository ppa:ondrej/php
    sudo apt-get update -y
    sudo apt install php8.2 php8.2-{fpm,mysql,curl,gd,mbstring,mysql,xml,mcrypt,zip,ldap} libapache2-mod-php8.2 -y

    Install PHP-FPM

    sudo a2enmod proxy_fcgi setenvif
    sudo a2enconf php8.2-fpm
    sudo a2dismod php8.2
    sudo systemctl enable php8.2-fpm
    sudo service apache2 restart;sudo service php8.2-fpm restart

    MariaDB

    Version: 11.1.2

    Run the following command to add the MariaDB yum repository (For all Linux distributions):

    curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-11.1.2"

    Install MariaDB Package

    sudo apt install mariadb-server -y

    MariaDB Secure Installation

    sudo mysql_secure_installation

    When prompted, set a password for the root account:

    • Enter the current root password. By default, the root account doesn’t have a password set.
    • Press Enter.
    • Press N to switch to unix_socket authentication.
    • Press Y to set a password, and then enter a secure password twice. Make sure to store this password in a safe place.
    • Press Y to remove the anonymous user accounts.
    • Press Y to disable the remote root login.
    • Press Y to remove the test database.
    • Press Y to reload the privilege tables and save your changes.

    Permissions

    The following command will add the ubuntu user to the www-data group:

    sudo usermod -a -G www-data ubuntu

    The following commands will set the correct permissions for the /var/www directory:

    sudo chown -R ubuntu:www-data /var/www
    sudo chmod 2775 /var/www
    find /var/www -type d -exec sudo chmod 2775 {} \;
    find /var/www -type f -exec sudo chmod 0664 {} \;

    Your site is ready!

    Visit your website by entering your instance’s public IP address in your browser. You should see the default Apache page.

    LAMP Stack Setup
  • News page added back to website

    The News page has been added back to the website. Some news sources were removed as they often produced RSS errors or the headlines were simply too bombastic or misleading by my standards.

    On the tech side of it, I did have to add some JavaScript to the native WordPress RSS widgets, so that I links opened in a new tab, etc., below is the code snippet:

    <script>
        // Open link in new tab
        let link = document.querySelectorAll('.wp-block-rss__item a')
        link.forEach((e) => {
            e.setAttribute("target", "_blank")
        })
    
        // Add inline style to the <ul>
        let news_list = document.querySelectorAll("ul.wp-block-rss")
        news_list.forEach((e) => {
            e.setAttribute("style", "list-style-type:none; margin: 1rem auto;");
        })
    
        // Make the title inline
        let wp_block_rss_item_title = document.querySelectorAll('div.wp-block-rss__item-title')
        wp_block_rss_item_title.forEach((e) => {
            e.setAttribute("style", "display:inline-block!important;");
        })
    
        // Style the publish date
        let wp_block_rss_item_publish_date = document.querySelectorAll('.wp-block-rss__item-publish-date')
        wp_block_rss_item_publish_date.forEach((e) => {
            e.setAttribute("style", "display:inline-block!important; font-weight:bold; margin:0 8px;")
        })
    </script>
    News page added back to website