Home » Articles by: Brad Morton

How to Refresh the Page in JavaScript using location.reload(), With Examples

JavaScript Refresh Page

Here’s a short guide to refreshing a webpage with JavaScript, with examples. There are over 500 ways to trigger a page reload using JavaScript. All but one are unofficial or are the side effect of another behavior. Here’s how to do it properly. Using location.reload() Simply call: location.reload() …anywhere in your code to trigger a page reload. It’s that easy. What about window.location.reload() ? You may see some use: window.location.reload() This is exactly the same as using location.reload() – the window object in JavaScript is the global context, so there’s usually no … Read more

Home » Articles by: Brad Morton

Compare JavaScript Dates (Day/Minute/Hour/Before/After), With Examples

JavaScript Compare Dates

Following on from our article on adding and subtracting time from dates in JavaScript – here’s how to compare two JavaScript date objects. This article will explore comparing dates/times with different granularity levels – from dates that are an exact month to dates that fall in the same year. Using Boolean Operators Native Javascript date objects can be compared using standard boolean/comparison operators – allowing you to compare dates by checking whether they are equal, not equal, greater than, less than, equal to or greater than, or equal to or … Read more

Home » Articles by: Brad Morton

How to Use Functions in Bash/Shell Scripts, With Examples

Bash Function Uses

This article will explain how to use functions in Bash scripts – helping you to reuse your code and simplify your scripts. Why write code multiple times when you can write it once and re-use it? That’s what functions let you do. This article outlines the use of functions in Bash/Shell scripts. What is a Function? A function is a piece of re-usable code. Functions can accept parameters, which allow them to perform the same repeatable actions on different inputs. Functions usually perform any action, output or print results, or return … Read more

Home » Articles by: Brad Morton

Using the ‘sed’ Command in Bash/Linux, With Examples

Bash sed command

The sed (Stream EDitor) command in Bash/Linux reads text from a stream or file and performs line-by-line operations on it based on a set of supplied criteria.  Here’s how to use it. sed is an automated way to process text. One simple example of where sed can be used is doing a simple find-and-replace for a word in a text document – the text with the words replaced can then be saved to a new file or overwrite the original. Why? Being able to modify text – either from a … Read more

Home » Articles by: Brad Morton

Using the ‘sleep’ Function in Bash Scripts, with Examples

Bash sleep Command

This article explains the sleep command in Bash/Shell scripts and how and why you might use it. The sleep command in Bash (and other Linux Shells) pauses execution for a specified amount of time – halting the script for a set number of seconds, minutes, hours, etc. Why Pause Execution? Why would you want to pause executing your script? Give the user a chance to interrupt an automated action Await user input Wait for a device to warm up/become available Stop text from flying across the screen if you’re trying to … Read more

Home » Articles by: Brad Morton

Converting to Integer with JavaScript parseInt() [Examples]

JavaScript parseInt

This article will show you how to use the parseInt() function in the JavaScript programming language. JavaScript is notoriously loosely typed – meaning that variables of one type (e.g., strings of text, numerical values, boolean values) are converted to others, allowing you to perform mathematical operations on strings and silly things like that. This causes all sorts of issues – strings containing numbers may not be parsed to the expected value, and all of a sudden, you have angry clients wondering why your shiny new … Read more

Home » Articles by: Brad Morton

How to List Users and Groups in Linux, With Examples

Linux List Users Groups

Linux supports multiple users and groups, allowing access to be granted to only the resources required.  Here’s how to list users, groups, and group membership. Separating users and groups ensures that different people can’t accidentally interfere with each other’s files and ensures system security by denying access to vital system files. This article details the various ways to query the users and groups on a computer running a Linux Operating System. Listing All Users The /etc/passwd file is a text-file database containing information on all of the users … Read more

Home » Articles by: Brad Morton

How to Change the Hostname in Linux (Debian, Ubuntu, Arch, RedHat)

Linux Change Hostname

This article will show you how to change the hostname for your Linux device (Debian, Arch, Ubuntu, or RedHat). The methods below should work for the vast majority of current and obsolete Linux Distributions. What is the Hostname? The hostname of a device on the network is the human-readable label of the system. It can be used to identify or connect to a system on the network instead of connecting to it via an IP address. Displaying the Current Hostname Regardless of your distribution, you can find out … Read more

Home » Articles by: Brad Morton

The MySQL/MariaDB ‘SHOW INDEX’ Statement, With Examples

MySQL SHOW INDEX

This article shows you how to use the MySQL SHOW INDEX statement to list the details of indexes and keys in a table. To use the SHOW INDEX statement, you will need to know which database and table you wish to view index information for. Looking to list the databases and tables on your system? What Are Indexes? Indexes are a tool that allows a database to quickly lookup data in a table for a certain column. Usually, when searching a table, the database software must read every row in … Read more

Home » Articles by: Brad Morton

The MySQL/MariaDB ‘DISTINCT’ Statement, With Examples

MySQL Distinct

The MySQL DISTINCT operator returns only unique values from a column from a database table; duplicates are not returned.  Here’s how to use it. The DISTINCT operator can be useful in many scenarios; for example, you may want to generate a list of countries you have shipped to, or you may want to provide a drop-down menu containing unique product options for the user to select. Example Usage of MySQL DISTINCT Examples will use the following table: table_orders: order_id shipping_country product_category 1 Australia soap 2 China … Read more