Home » 2021 » April

Calculating Absolute Values in Python, With Examples

Python Absolute Value

In this article, you’ll learn about absolute values – what they are, how they’re used, and how to use the Python abs() function to calculate them. 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 number’s sign is whether it is positive or negative. So, the absolute value of a number is never negative. To make it simple, consider the absolute value of a number that numbers distance from 0. It is also referred to in mathematics and … Read more

Home » 2021 » April

Concatenate Strings in Bash/Shell Scripts, With Examples

Bash Concatenate Strings

Here’s a short article on concatenating (merging) strings in Bash – the right way. Examples included. There are various ways two or more strings could be joined in a shell script. Various programs will accept strings and return them merged/concatenated – but using the side-effect of a programs operation to concatenate strings is a bit of a waste of time, so this article will focus on the simplest, most readable method. Inserting a String into Another A string can be inserted when creating another string … Read more

Home » 2021 » April

Command Line Arguments in Python Scripts, With Examples

Python Command Line Arguments

This article will show you simple methods to pass command line arguments to your Python scripts, with some examples. Passing arguments to your script makes it easy to build multi-use scripts that can work on different inputs. This is much easier than re-editing your code every time you want to change the inputs it will be working on. I’ve previously covered building a full command-line application in Python, which accepts command-line options and bundles the application into a distributable package with no external dependencies – … Read more

Home » 2021 » April

PHP include – How to Use It, With Examples

How to use PHP include

The PHP include expression allows you to import code from another file and import code from external PHP libraries. Here’s how to use it, with examples. PHP include will execute and import PHP code from another file or library.  It allows you to re-use code and work with libraries provided by others – for example, you may download a library to interact with a mapping service and wish to include it in your code. Syntax include ‘./path/to/file.php’; Simple! The include expression must be followed by the … Read more

Categories PHP

Home » 2021 » April

JavaScript Callback Functions How-To, With Examples

JavaScript Callbacks

This article will explain callback functions in JavaScript – what they are, why they’re used, and how to use them. What is a Callback in the JavaScript Programming Language? A callback function is a function that is passed as a parameter to another function to be executed from within the second function. What are Callbacks Useful For? Callback functions are usually used to execute a function when another has been completed. This allows for easy code- reuse. A single function that accepts a callback can be … Read more

Home » 2021 » April

Math/Arithmetic in Bash/Shell Scripts, With Examples

Bash Math & Arithmetic

Math is easy, Bash scripting is easy, so performing math/arithmetic in Bash/Shell scripts should be easy too. It is. Here’s how to do it. Working with Integers Bash’s built-in arithmetic can only handle integer (whole number) values. If you attempt to declare a variable with a non-integer value: declare -i e=2.5 You’ll see the following: bash: declare: 2.5: syntax error: invalid arithmetic operator (error token is “.5”) To work with non-integer numbers, you will need to use an external program to perform your calculations – but first, … Read more

Home » 2021 » April

Variables in Bash/Shell Scripts and How To Use Them [Tutorial]

Bash Variables and How to Use Them

This article will show you how to use variables in Bash and Shell scripts in Linux. Bash (or Linux Shell) scripts are files you write containing commands to automate common tasks and save yourself some time. Variables are things in scripts that hold a value for later use – a number, or a filename, or anything, really. Here’s how to define and use variables in Linux Shell scripts. These examples should work in the most popular Linux Shells, Bash, and Zsh. Declaring Bash Variables Bash VARIABLES ARE UNTYPED … Read more

Home » 2021 » April

jQuery vs JavaScript – Differences? Which is Better?

jQuery vs JavaScript

This article will explain what JavaScript and jQuery are, how they differ, and how/why they should be used. What is JavaScript JavaScript began life in the mid-1990s as a scripting language for adding interactivity to web pages. Over time it has been developed into a full-featured programming language, which can even be run outside the web browser (more detail on this in our Node.js article). You can also see our article outlining the differences between JavaScript and Typescript here. What is jQuery? jQuery is a library written in JavaScript. … Read more

Home » 2021 » April

DIY Raspberry Pi/Python Powered PACHINKO [Kitchen Build]

Raspberry Pi Python Pachinko

Pachinko? Pichinko? Pychinko? I’ve been playing around with is idea for a while because… I don’t know; it seemed like a cool concept. That’s my whole motivation. Here’s a Raspberry Pi and Python-powered pachinko machine. This project is really basic, so it’s good for beginners, and the result is a lot of fun to mess with and would make a good desk ornament to fidget with or something for the kids to build on a rainy day to learn about coding and circuits and all … Read more

Home » 2021 » April

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