Home » Programming

Modulus (Mod), Modulo and Python – Explanation and Code Examples

Python mod Modulus Modulo

This tutorial will explain (hopefully in the simplest terms possible) what modulus and modulo mean and how they can be calculated in the Python programming language. Modulus and Modulo are Different Things! There’s a bit of confusion about this, and it seems that in some places, the terms modulus and modulo are used in place of each other – this is wrong (and confused me too – hence this article)! What is Modulus? In mathematics, the modulus is the absolute value of a number. It’s the non-negative value of a number – or its … Read more

Home » Programming

Modulus (Mod), Modulo and PHP – Explanation and Code Examples

PHP mod Modulus Modulo

This article will explain (in the simplest terms possible) what modulus and modulo mean and how they are calculated in the PHP programming language. Modulus and Modulo are NOT the Same Things! There’s a bit of confusion about this, and it seems that in some places, the terms are used interchangeably – this is wrong (and confused me too – hence this article)! What is Modulus? In mathematics, the modulus is the absolute value of a number. It’s the non-negative value of a number – or its distance from 0 (zero). … Read more

Categories PHP

Home » Programming

How to Read a Local/Remote JSON File in JavaScript [Examples]

JavaScript Read JSON File

This article will show you how to read a JSON file into JavaScript as a JSON object – both local and remote files. What is JSON? JSON (JavaScript Object Notation) is a file format that stores objects, and arrays of objects, as human-readable text. It’s become the most popular method of storing and transmitting structured data on the internet. Thousands of APIs (used for mapping, communication, authentication, and many other purposes) use it as the format for submitting and receiving data. Desktop applications also use it to … Read more

Home » Programming

How to Write to a File Using JavaScript, With Examples

Write to File in JavaScript

This article will show you how to write to files from JavaScript – both from the web browser and Node.js environments. With examples on how to write, append, update, delete and rename files. JavaScript code is usually run from one of two environments – within a web browser when viewing a web page or in a Node.js environment which allows JavaScript to be executed outside of a web browser – commonly used for building back-end services and web apps. Write to a File From the Browser … Read more

Home » Programming

R vs Python – What Makes them Different? Which is Best?

R vs Python

This article provides a simple comparison of the R and Python programming languages – and what they’re best used for. If you’re looking to learn to program and are interested in data analysis, you’ll probably run into the choice – R or Python? This article breaks down each and why you might choose to use one – or both – of these languages. What is R? R is a programming language designed specifically for statistical computing. It is designed for, and widely used for, processing and analyzing large data sets. What is it Good … Read more

Home » Programming

Calculating Factorials in Python – The Easy Way

Python Factorial

This short article will show you the quickest and easiest way to calculate a factorial in Python using the factorial() function. This article is written for the Python 3 programming language. What is a Factorial, and How is it Calculated? A factorial is a mathematical formula in which a given positive integer is multiplied by all of the positive integers less than itself – the resulting number being the factorial of the original number. It is denoted with ! (exclamation mark) – so the factorial of 4 is written as 4! And is calculated out like so: … Read more

Home » Programming

Converting to Float Numbers with the parseFloat() JavaScript Function, With Examples

JavaScript ParseFloat()

This article will explain floating-point numbers and how to convert values to floating-point numbers using parseFloat() in JavaScript. Looking to convert to an integer value instead – use parseInt()! What is a Floating Point Number? In programming, a floating-point number (commonly just called a float) is a number with any number of characters before or after a decimal point. A floating-point number might look something like this: 14.392 A floating-point number or float is also a type of variable. A variable’s type determines what kind of values it can store and what can be done with the variable … Read more

Home » Programming

How to Compare Dates in PHP, With Examples

PHP Compare Dates

This tutorial will show you the best way to compare dates in the PHP programming language – and provide code examples. It’s essential to be able to accurately compare dates when building your app. For example, you may wish to compare dates for reporting purposes – retrieving a list of transactions from a shop for a given reporting period, or you may want to have your user enter a fake birthday into your webpage so that they can pretend that they are over 18. Anyway, … Read more

Categories PHP

Home » Programming

Using the PHP ‘exit’ (AKA ‘die’) Function to Terminate your Script [Examples]

PHP exit die

This short article will explain the PHP exit function and how it is used to quit/exit/terminate a PHP script. PHP exit Function Syntax The syntax for the PHP exit function is as follows: exit(STATUS) Note that: exit will terminate the execution of the script at the point it is called STATUS is an optional integer or string value containing a status code or exit message If an integer value with a status code, the script will return this code as the exit status if running on the command line Exit status should be 0 for … Read more

Categories PHP

Home » Programming

How to Convert String to Date in JavaScript, With Examples

JavaScript String to Date

Here are some easy-to-understand methods for converting strings to date objects in the JavaScript Programming language. Looking to compare dates in JavaScript? Find out how here. The Hard Way – Using Vanilla JavaScript JavaScript contains built-in functions for parsing a date from a string – but it’s severely limited. So here it is in action: var myString = ’01 Jan 1970 00:00:00 GMT’; var myDate = new Date(Date.parse(myString)); What’s happening here? A string is defined containing a date. A new Date object is then defined using the … Read more