Programming & Scripting

Advanced Python Concepts

This tutorial covers advanced python concepts such as Python classes, constructors, encapsulation, inheritance, polymorphism and creating Python packages and modules. Therefore, if you do not have any prior Python knowledge we refer you to our Python Fundamentals Tutorial. Python Classes Python Constructors Python Encapsulation Python Inheritance Python Polymorphism Python Packages and Modules
Read More...

Check Python Version

Objective The following artcile will provide you with the information on how to check Python version on your operating system. Difficulty EASY Conventions
Read More...

Introduction to the Doctrine ORM and data mapper pattern in php

Objective Learn the basic concepts of Doctrine ORM, implementing the Data Mapper pattern with php. Requirements Composer (php package manager) A working lamp setup Understanding the basic object oriented programming and php Understanding the basic database concepts Difficulty MEDIUM Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ - requires given linux commands to be executed as a regular...
Read More...

How to check Bash version

Objective This article will provide you with the information on how to check bash version on your operating system. Operating System and Software Versions Operating System: - Distribution Agnostic Requirements No special prerequisites are required is required. Difficulty EASY Conventions
Read More...

Bash Scripting Tutorial for Beginners

Bash Shell Scripting Definition Bash Bash is a command language interpreter. It is widely available on various operating systems and is a default command interpreter on most GNU/Linux systems. The name is an acronym for the ‘ B ourne- A gain SH ell’. Shell Shell is a macro processor which allows for an interactive or non-interactive command execution. Scripting Scripting allows for an automatic commands execution that would otherwise be executed interactively one-by-one. Bash Shell Script...
Read More...

How to use argparse to parse python scripts parameters

Objective Learn to use the argparse module to easily parse python scripts parameters Requirements Basic knowledge of python and object oriented concepts Difficulty EASY Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ - requires given linux commands to be executed as a regular non-privileged user Introduction In a previous article we have seen how to parse command line arguments using getopts in the...
Read More...

How to Play Audio With VLC In Python

Objective Play audio with VLC in Python. Distributions This will work on any Linux distribution Requirements A working Linux install with Python and VLC. Difficulty Easy Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ - requires given linux commands to be executed as a regular non-privileged user Introduction There are plenty of ways to play audio files with Python. It really depends on your...
Read More...

How to Use JSON API Data In Python

Objective Consume a JSON API in Python. Distributions This will work on any Linux distribution. Requirements A working Linux install with Python. Difficulty Easy Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ - requires given linux commands to be executed as a regular non-privileged user Introduction One of the main reasons that you'd like to work with JSON in Python is consuming APIs. There are...
Read More...

How to Parse Data From JSON Into Python

Objective Parse JSON data in Python. Distributions This will work on any Linux distribution. Requirements A working Linux install with Python. Difficulty Easy Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ - requires given linux commands to be executed as a regular non-privileged user Introduction JSON is a favorite among developers for serializing data. It's used in most public APIs on the web, and...
Read More...

How to Encode Data From Python To JSON

Objective Encode Python data into JSON. Distributions This will work on any distribution with Python installed. Requirements A working Linux install with Python Difficulty Easy Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ - requires given linux commands to be executed as a regular non-privileged user Introduction JSON is the universal format for passing data between programs and/or languages,...
Read More...

How to modify scripts behavior on signals using bash traps

Objective The objective of this tutorial is to describe how to use the bash shell trap builtin to make our scripts able to perform certain actions when they receive a signal or in other specific situations. Requirements No special requirements Difficulty EASY Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ - requires given linux commands to be executed as a regular non-privileged user Introduction When...
Read More...

How to obtain Sunrise & Sunset time for any location from Linux command line

Objective The objective is to use command line and bash shell script to obtain Sunrise & Sunset time information for any given location. Operating System and Software Versions Operating System: - Linux distribution agnostic. Requirements Installed lynx tool and access to shell command line. Your location code obtained from https://weather.codes/search/ . Difficulty EASY Conventions
Read More...

How to use getopts to parse a script options

Objective Learn how to use the bash getopts builtin to parse a script options Operating System and Software Versions Operating System: - All Linux distributions Requirements No special requirements, just access to a bash shell Difficulty MEDIUM Conventions
Read More...

Children multiplication tables practice test with Bash script on Linux

Introduction The following post is a little bit different from my other posts as it does not solve any of your Linux configuration problems. Apologies there! This post is an attempt to kill multiple birds with one stone, hence expose children to a command line, avoid web flash and ads driven multiplication practice tests online and most importantly gain some multiplication skills along the way. My daughter reached the age where she is required to perform multiplication calculation at school....
Read More...

Learn the basics of the ZSH shell

Objective Install ZSH with Oh My ZSH and learn the basic features. Distributions ZSH is available in the repositories of nearly every distribution. Requirements A working Linux install with root privileges. Difficulty Easy Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ - requires given linux commands to be executed as a regular non-privileged user Introduction Bash isn't bad. It gets the job done just...
Read More...

Introduction to Bash shell redirections

Objective Learn to use redirections, pipes and tee in the Bash shell Operating System and Software Versions Operating System: - Linux distribution agnostic Requirements Access to a Bash shell Difficulty EASY Conventions
Read More...

Python Exception Handling

Introduction Python will let you know when you get your syntax wrong. It'll immediately fail and not allow your program to run. What about when your code has a different type of problem? Those are called exceptions, and they tend to be harder to catch. It's up to you to recognize situations where hey might come up and catch them to prevent your program from crashing altogether. Imagine a scenario where you need user input. Do you want your program to crash every time a user mistypes something...
Read More...

Python OS Module

Introduction Python is a powerful scripting language. So, why not use it to script Linux? The os module is Python's answer to handling many Linux file operations. The os module allows Python to perform many of the file and folder operations that you'd typically carry out in the Linux command line. It enable you to begin swapping out Bash for Python, which makes for a much cleaner and friendlier scripting experience. Loading OS The os module is a Python module like any other. In any script...
Read More...

Python Lambdas

Introduction You've worked with both functions and methods, but there's a different type of function, the anonymous function. Anonymous functions are just functions without names, and in Python, they are handled with the lambda operator. Anonymous functions allow you to use the behavior of a function without having to create a function. This is especially good when you only need to use a function once or twice. It might sound like an unusual occurrence, but it happens fairly frequently when a...
Read More...

Reading And Writing Files With Python

Introduction Jut about any program of a decent size needs to be able to read and write from files. At very least, it needs to be able to generate logs. Python is also tightly integrated into Linux system administration and scripting. Again, reading and writing are important for managing a system. Opening A File Python creates and object from the file that it opens. It can then manipulate that object. When it's done, it uses the object to save the any changes back to the file. Create a new text...
Read More...