Home » Articles by: Brad Morton

How to Export and Back Up PostgreSQL Databases

PostgreSQL Backup Import Export

This tutorial will show you how to export, import, and back up your PostgreSQL clusters and databases. You should regularly back up. It’s one of the most important things you can do as a sysadmin, developer, and even a hobbyist. Losing your data is detrimental to business, and your projects. Losing your family photos sucks too. This article demonstrates the various way to import and export PostgreSQL data so that it can be backed up. This process should be done regularly (or automated!), and performed … Read more

Home » Articles by: Brad Morton

How to Import a CSV File to PostgreSQL

PostgreSQL Import CSV File

This tutorial will show you how to import data from a CSV file into a PostgreSQL database table. What is a CSV File A CSV (Comma Separated Values) file is a text file that contains tabulated information. The rows in this data each take up a line in the text file, while the values in each column on each row are separated by a comma – hence, comma-separated. CSV files are versatile. Because the data within is stored as plain text, they can be opened … Read more

Home » Articles by: Brad Morton

Bash Split String (+ Shell Scripts)

Bash Split String

This article will show you how to split a string at a given delimiter in Bash/Shell scripts and show some examples. Splitting strings is a handy function to have available when crafting your scripts. CSV (Comma Separated Values) is a common format in which data is made available online, where data fields in a table are separated by (surprise) commas. You may also simply be looking to split a sentence into words at the spaces, or split paragraphs into sentences at the period, and so … Read more

Home » Articles by: Brad Morton

Printing Text in Python Without a Newline

Python print without newline

This short tutorial will show you how to print text in Python, without a new line appearing. The Newline Character in Python In Python, newlines are represented by a \ (backslash) followed by n: \n You Can Add New Lines to Printed Strings The \n won’t be shown to the user – a new line will be inserted instead (unless an escape character is added). So, when the below code is executed: print(“Linux\nScrew”) It will appear as: Linux Screw Print Statements Add a Newline By Default By default, a newline … Read more

Home » Articles by: Brad Morton

How to Run an SQL File in MySQL (or MariaDB) on Linux/Ubuntu

How to Run a SQL File in MySQL/MariaDB on Linux/Ubuntu

Here is an article outlining several methods for running SQL files in MySQL on Linux/Ubuntu. Whether you’re installing a package, following a tutorial, or restoring a backup – it’s useful to be able to execute an SQL script from a file and have it do all of the work for you, rather than having to type it all out. Most GUI database managers have a simple import option prominently displayed in the menu bar – so here’s how to do it from the command line … Read more

Home » Articles by: Brad Morton

How to Read CSV Files in Python, With Examples

Python read from csv file

This article will show you how to read CSV (Comma Separated Values) files in the Python programming language, with examples. What is CSV (Comma Separated Values) CSV (Comma Separated Values) is a format for storing and transmitting data, usually in a text file, in which the individual values are separated by a comma (,). Each row in a CSV file represents an individual record containing multiple comma separated values. A CSV file looks like this: name,age,favourite colour Fred,54,green Mary,31,pink Steve,12,orange Above, the CSV describes three people, with information … Read more

Home » Articles by: Brad Morton

Use wc to Count the Characters/Words/Lines [Linux/Bash]

Bash wc command count words

The wc program can be used in Bash scripts and from the Linux command line to count the number of bytes, characters, words, or lines in a file. Here’s how to use it, with examples. wc Program Syntax The syntax for the wc command is as follows: wc OPTIONS FILE Note that: OPTIONS should be provided from the below table of available options FILE is the path to the file which will have the contents counted More than one file can be specified If more than one file is specified, the total … Read more

Home » Articles by: Brad Morton

Python setAttr() – What it Does and How to Use It [Examples]

Python use setattr() to set object attributes

The setattr() function is used to set the value of an attribute of an object. Here is how it is used, with examples. Python Objects and Classes Python is an object oriented programming language. Object oriented means that rather than code being written as a list of instructions, accumulating data and passing the results to the following lines of code (known as procedural programming), data and functionality is contained within the objects it describes. Each object is a self-contained representation of something, that can be modified, and passed between functions … Read more

Home » Articles by: Brad Morton

JavaScript for Loops – How to Use Them [Examples]

How to use for loops in JavaScript

This article will show you how to use the simplest JavaScript loop – the for loop, and provide code examples. JavaScript for Loops JavaScript’s for loops are used to execute a block of code repeatedly until a condition is met. The initial variables, condition that must be met, and the expression which progresses the loop are all defined within the loop expression. for loop Syntax JavaScript for loops follow the following syntax: for (INITIALIZATION; CONDITION; FINAL_EXPRESSION) { //Code to be executed in the loop } Note that: INITIALIZATION sets the variable which is used to control … Read more

Home » Articles by: Brad Morton

How to Sort a Dictionary by Value in Python [Examples]

Python sort dictionary by value

This article will show you how to sort a dictionary by the values it contains in the Python programming language. Code examples are included. What is a Dictionary? A dictionary is one of Pythons built in variable types for storing data. Dictionaries are similar to associative arrays or hash tables in other languages. A dictionary contains a collection of values or objects. Unlike lists and arrays, rather than their values being stored at a specific index (the ordered position in the sequence of stored values), values in a dictionary … Read more