Home » Articles by: Brad Morton

What is the $_SERVER Superglobal Variable in PHP?

PHP _SERVER

This article will explain what the $_SERVER superglobal variable is in the PHP programming language. What is a ‘Superglobal’ Variable? A superglobal variable is a variable that is available to all scripts in all scopes in PHP. It is available from within any file, class, or function. What is the $_SERVER Superglobal Variable? The $_SERVER superglobal contains information about the server and execution environment PHP is running in/on. It contains information on the request made to the web server, file paths, and other information. It will provide little to no info … Read more

Categories PHP

Home » Articles by: Brad Morton

How to Update/Upgrade Python in Linux [Ubuntu/RedHat]

Update/Upgrade Python in Linux

This article will show you how to update Python to the latest version on your Linux Operating system. Python is updated yearly with new features and big upgrades – these are called major updates. In addition to this, monthly updates are released which fix small issues and improve security – these are called minor updates. Major updates change how Python works a bit and may break compatibility with some code as features are added or removed, whereas minor updates are solely there to fix problems without altering any functionality. Updating From Python 2 … Read more

Home » Articles by: Brad Morton

XOR (Exclusive Or) in Python

Python XOR Exclusive Or

This article explains XOR (Exclusive Or) – what it is, why it’s used, and how to implement it in the Python programming language. What is XOR / Exclusive OR XOR – Exclusive Or – is a logical operation commonly used in computer programming. Logically, an XOR condition is true only if the supplied arguments differ. XOR compares two inputs and outputs, true or false, only if they are different. Those inputs are usually true/false boolean values or the result of a logical operation that returns a boolean value. For example, XOR on two values – 1 and 1 is false – they do not differ. XOR on two values … Read more

Home » Articles by: Brad Morton

Calculating the Absolute Value in JavaScript with Math.abs()

JavaScript Absolute Value abs()

This article will explain what absolute values are, how they are used, and how the JavaScript Math.abs() function can be used to calculate the absolute value of a number. What is the ‘Absolute Value’ of a Number? The absolute value of a number is that number’s value – without any regard to its sign. A numbers sign determines whether it is positive or negative – it’s the – symbol before a negative number. So, the absolute value of a number is never negative. Consider the absolute value of a number that numbers distance from 0. The absolute value of … Read more

Home » Articles by: Brad Morton

A Trick for Validating JSON in PHP

PHP Validate JSON

Here’s a quick trick for validating JSON in PHP – with a reusable function, you can copy and paste it into your own project. JSON has pretty much become the standard format for transferring data between applications on the internet. So if you’re building an API to be consumed by others or just building a backend for your app, you’ll be sending and receiving a lot of JSON data. But, you can never trust the request – the data coming into your application. Users enter bad data. Hackers deliberately enter bad … Read more

Categories PHP

Home » Articles by: Brad Morton

Capitalize the First Letter of Each Word in a String [JavaScript]

JavaScript Capitalize First Letter

This short article shows you how to capitalize the first letter in a string or all of the words in a string (title case) in the javascript programming language. Capitalizing the first letter in a string is useful if you’re capitalizing a single word or a whole sentence which you wish to display in a grammatically correct manner. Converting a string to title case – that’s where every word is capitalized in a string with multiple words – is useful for formatting text for use in an article … Read more

Home » Articles by: Brad Morton

Python: View Documentation With the help() Function

Python help() Function

This short article will show you how to use the Python help() function to view the documentation (Docstring) for a Python module, class, or function. Documenting Your Python Code with Docstrings You can document your Python code with a special string called a docstring. We’ve got a whole article on that here. The short version of it is this: put a triple quoted string immediately after declaring a function, class, or module in Python: “”” Just like this “”” …and you can later read from it using the help() … Read more

Home » Articles by: Brad Morton

How to Check if an Array is Empty in JavaScript [Examples]

Check if JavaScript Array is Empty

This quick tutorial will show you how to check whether an array is empty in the JavaScript programming language. What is an Array? An array is a type of variable that holds a collection of zero or more values. In JavaScript, arrays are ordered – each value in the array has a position (called the index) in the array, which is used to access it. Indexes start counting at 0, so the first value in an array is at index 0. Declaring an Array in JavaScript The quickest way to … Read more

Home » Articles by: Brad Morton

What are Python Docstrings and How Are They Used?

Python Docstring

This tutorial will explain what docstrings are in the Python programming language and how they can be used. What is a Docstring in Python? A docstring is a string literal that is used to document your code. A string literal is a sequence of characters 0 or more characters in length, which is to be treated as a single entity – i.e., it’s a string variable of any length. A docstring appears after the definition of a module, class, method, or function and should explain the purpose of the object it … Read more

Home » Articles by: Brad Morton

How to Reset/Clear/Empty an Array in JavaScript

Reset/Clear Array JavaScript

This quick article will show you the right way to reset/clear/empty an array in the JavaScript programming language. The Right Way to Reset/Clear/Empty an Array – Set the length to 0 This is the best way to reset/clear/empty an array in JavaScript. It is unambiguous and will affect both the variable containing the array and any variables referencing the array. var myArray = [1, 2, 3, 4]; myArray.length = 0; Above, an array is declared and then emptied by setting the array’s length property to 0. The Wrong Way – Re-declare the … Read more