Tag: Web Development

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

    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.

  • Saturday morning vibe…

    Cleaning up some personal projects and performing some maintenance on some personal deployments.

  • Reblog: Site Editor Tools

    Reblog: Site Editor Tools

    The Site Editor gives you a powerful way to visually create every part of your site and tell your story.

  • Refining for microblog

    Refining for microblog

    I’ve recently revamped the website to embrace a more microblog-centric design compared to its previous layout. The navigation has been streamlined to three essential sections: ‘About,’ ‘Blog,’ and ‘Contact.’ The primary aim of this blog is to serve as the main channel for sharing my public thoughts and notes on topics I’m passionate about. While I maintain a presence on a few social media platforms, I don’t use them for content sharing. Instead, all my content is published here.

  • How-to Backup a WordPress Website Using WP-CLI

    How-to Backup a WordPress Website Using WP-CLI

    Backing up a WordPress website using WP-CLI (WordPress Command Line Interface) involves several steps. Here’s a general guide on how to do it:

    1. Install WP-CLI

    If you haven’t already installed WP-CLI, you’ll need to do so. You can find the installation instructions on the WP-CLI’s official website.

    2. Access Your Server

    You’ll need SSH access to your server. Once you’ve logged in, navigate to the root directory of your WordPress installation.

    3. Backup the Database

    To backup your WordPress database, use the following WP-CLI command:

    wp db export

    This command will create a .sql file in your WordPress directory. This file contains all of your WordPress database information.

    4. Backup WordPress Files

    You also need to backup your WordPress files, including themes, plugins, and uploads. To do this, you can use a command like rsync or tar. For example:

    tar -czvf yoursite_backup.tar.gz /path/to/your/wordpress/directory

    This command will create a compressed archive of your WordPress directory.

    5. Download the Backup

    After creating the backup files on your server, you’ll need to download them to a safe location. You can use an FTP client or a command like scp for this purpose.

    6. Automating the Process

    Optionally, you can write a script to automate the backup process and schedule it to run regularly using a cron job.

    Important Tips

    • Test Your Backup: Always test your backups to ensure they work as expected.
    • Secure Your Backup: Keep your backup files in a secure location to prevent unauthorized access.
    • Regular Backups: Schedule regular backups to minimize the risk of data loss.

    Remember, while WP-CLI is a powerful tool, you should be comfortable with command-line interfaces and have the necessary permissions on your hosting server to perform these actions.

  • Credit Card Testing

    Credit Card Testing

    PayPal sandbox testing guide

    The PayPal sandbox is a self-contained, virtual testing environment that simulates the live PayPal production environment. The sandbox provides a shielded space where you can initiate and watch while your apps process PayPal API requests without touching any live PayPal accounts.

  • Image Tag Cheat Sheet

    Image Tag Cheat Sheet

    Basic Usage

    <img src="path/to/image.jpg" alt="Image description" />

    Attributes

    AttributeDescription
    srcThe path to the image file.
    altThe text to display if the image fails to load.
    widthThe width of the image in pixels.
    heightThe height of the image in pixels.
    titleThe text to display when the user hovers over the image.

    Example

    <img src="path/to/image.jpg" alt="Image description" width="200" height="200" title="Image title" />

    Notes

    • The alt attribute is required for accessibility. It is used by screen readers to describe the image to visually impaired users.
    • The width and height attributes are optional. If you do not specify them, the image will be displayed at its original size.
    • The title attribute is optional. It is used to provide additional information about the image when the user hovers over it.
  • LAMP Stack Setup

    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.

  • Introducing new GitHub Copilot features in VS Code!

    Introducing new GitHub Copilot features in VS Code!

  • Getting a little fed up: I cannot easily share on WP

    Getting a little fed up: I cannot easily share on WP

    With the “death of Twitter,” and social media in general, I’d like to take back my content. It’s just not currently easy to share content to my blog.