Setup a new device with Windows 11 Home Edition without a Microsoft account

Prerequisite: Make sure you’re disconnected from the internet. This includes any hardwired connection.

When you’re asked to choose a home country, press Shift + F10. This will open the command prompt window.

In the command prompt window, you need to run the BypassNRO.cmd script file, located in C:\Windows\System32\OOBE

As a part of the process, your device will be restarted.

Automating Let’s Encrypt certificate Renewal using Certbot

Here, we’ll learn how to automate Let’s Encrypt’s SSL certificates using certbot. These instructions can be modified to automate any command.

Service unit file

A service unit file needs to be created at:
/etc/systemd/system/certbot-renewal.service

[Unit]
Description=Let's Encrypt certificate renewal using certbot

[Service]
Type=oneshot
ExecStart=certbot renew --quiet --agree-tos
ExecStartPost=service nginx restart

Timer unit file

The plan is to run the above renewal command every few weeks, as well as 15 minutes after the system boots up.

For this, a timer unit file needs to be created with the same name at:
/etc/systemd/system/certbot-renewal.timer

[Unit]
Description=Timer for Let's Encrypt's certificates renewal

[Timer]
OnBootSec=900
OnUnitActiveSec=2w
RandomizedDelaySec=1h
Persistent=true

[Install]
WantedBy=timers.target

Enable the timer

The timer can be enabled by the command:
systemctl enable --now certbot-renewal.timer

References: The steps above have been referenced from:

Creating custom permalinks for certain categories in WordPress

We had to create a custom permalink for a certain category, this is how it’s done.

For a certain client, we had to create a custom permalink structure for a certain category of posts. We could’ve created a custom post type and that would’ve accomplished that task as well. However, that was out of the scope of the project.

Here is what we ended up with:

add_filter( 'category_link', 'custom_category_permalink', 10, 2 );
function custom_category_permalink( $link, $cat_id ) {
    $slug = get_term_field( 'slug', $cat_id, 'category' );
    if ( ! is_wp_error( $slug ) && 'testimonials' === $slug ) {
        $link = home_url( user_trailingslashit( '/testimonials/', 'category' ) );
    }
    return $link;
}

add_action( 'init', 'custom_rewrite_rules' );
function custom_rewrite_rules() {
    add_rewrite_rule(
        'testimonials(?:/page/?([0-9]{1,})|)/?$',
        'index.php?category_name=testimonials&paged=$matches[1]',
        'top' // The rule position; either 'top' or 'bottom' (default).
    );

    add_rewrite_rule(
        'testimonials/([^/]+)(?:/([0-9]+))?/?$',
        'index.php?category_name=testimonials&name=$matches[1]&page=$matches[2]',
        'top' // The rule position; either 'top' or 'bottom' (default).
    );
}

This is just a starting point. Going through the WordPress Codex, you will find that the possibilities are endless.


References: The snippet above has been referenced from:

  1. https://wordpress.stackexchange.com/questions/296699/give-specific-category-its-own-permalink-structure/296703#296703

Cleaning up the boot partition on Ubuntu

As a part of maintenance, we will learn how to remove old kernels from an Ubuntu machine

Here’s how to clean your boot partition on Ubuntu or similar Debian based systems

Reboot the machine

It is important that the latest kernel is in use while cleaning up the old kernels. A simple reboot will ensure that the latest kernel is in use.

Check the current kernel version

The current kernel version can be checked using the following command:

uname -r

Show a list of installed kernels

Next, we need to fetch a list of all the installed kernels. This can be obtained using the following command:

dpkg --list 'linux-image*' | grep ^ii

Alternatively, an easier form would be:

sudo dpkg --list 'linux-image*' | awk '{ if ($1=="ii") print $2}' | grep -v `uname -r`

Remove the old kernels

We now need to remove the unused kernels from the step above. The following command needs to be executed for every unused version:

sudo apt purge linux-image-VERSION

Remove dependencies

With the old kernels removed, we now need to remove the dependencies by using:

sudo apt --purge autoremove

Update grub

Finally, we need to update grub to use the latest kernel.

sudo update-grub

And that should be it!


Disclaimer: The steps above have been tested with Ubuntu 18.xx and above. Replace apt with apt-get for older versions.


References: The steps above have been referenced from:

  1. StackOverflow (https://askubuntu.com/questions/345588/what-is-the-safest-way-to-clean-up-boot-partition)
  2. github (https://gist.github.com/ipbastola/2760cfc28be62a5ee10036851c654600)

Regular expression for matching an email address

A single RegEx to rule all email address validations

Effort has been made to keep the regex as language-agnostic as possible. This can be modified depending on the need.

The RegEx is as follows:

(([a-zA-Z0-9_-]+)([\.\+]?[a-zA-Z0-9_-]+)*)\@([a-zA-Z0-9]+[\.\-])+([a-zA-Z]{2,5})

Explanation

While the RegEx looks overly complicated and verbose, it can be broken down to simpler units as follows:

  • ([a-zA-Z0-9_-]+) : A word containing one or more characters that can be alphanumeric, as well as be and ‘underscore’ or a ‘hyphen’.
  • ([\.\+]?[a-zA-Z0-9_-]+)* : This is a repeat of the the first part, prefixed with a ‘dot’ or a ‘plus’ sign. This block can be repeated any number of times, including zero.
  • \@ : The ‘at’ symbol.
  • ([a-zA-Z0-9]+[\.\-])+ : The domain name, can contain ‘hyphens’ or ‘dots’, but not both consecutively.
  • ([a-zA-Z]{2,5}) : The TLD. Change this as per requirement.

References

The Wikipedia entry on email addresses gives us the acceptable formats.

Disable apps via adb (without root)

Here we learn to disable apps on aftermarket or stock ROMs without rooting

On your Android phone, most apps can be disabled by going to Settings > Apps. However, there are a few pesky apps that can’t be disabled via this method, and they need something a bit more sophisticated.

Often times, this is just bloatware that you want to get rid of.

To disabled the apps, you’ll have to connect the phone to your PC using the adb mode.

Once connected, issue the following command

pm disable <package.name.here>

This might not work on some OEM ROMs. If this is the case, try

pm disable-user <package.name.here>

IF this doesn’t work, try this

pm disable-user --user 0 <package.name.here>

This should do the trick, and the package should now be disabled.

Addendum

You migh also want to clear the user data for the app. This is especially true if you’re disabling bloatware.

While still connected over ADB, and preferably after disabling the app, issue the following command

pm clear <package.name.here>

Unless the vendor has specifically disabled clearing the app data via ADB (Oppo, for example), the command above should have cleared the data