Looking at alternative computer software solutions for a variety of reasons. This includes price, computer security, virus prevention and reliability. Here are my notes and great that if it helps you, otherwise please understand what you are doing and not follow blindly. All works expressed are my own and does not necessarily express the products or organisations mentioned here.
Friday, May 28, 2021
How to clone a git branch
Thursday, March 11, 2021
Backup Postgresql Database
Here are the basic steps to backup and restore Postgresql database. At this point of writing, I am using Postgresql 10 and 11 on Centos Linux 8.
In this article, backup database is inventory_system and restore of the backup is to another database that I will call cupboard.
Singles Database
Step 1: Login as postgres user
su - postgres
or
sudo su postgres -
Step 2: Dump the database content to a file using the tool pg_dump
pg_dump inventory_system > inventory_system-20210312.bak
or when database is located at IP 10.1.1.123 with port 5432
pg_dump -h 10.1.1.123 -p 5432 inventory_system > inventory_system-20210312.bak
Step 3: Create the new database
createdb cupboard
Step 4: Restore the database file with psql
psql cupboard < inventory_system-20210312.bak
On MS Windows 10 prompt that is provided through Laragon, the postgres user login is required
pg_dump -U postgres cm2020_1 > test.bak
Schedule backup
Cron job is suitable to automate the backup process mentioned above. To schedule a cron job, use the command
crontab -e
Then save the following instruction to run at midnight of every Saturday
0 0 * * 6 pg_dump -U postgres inventory_system > ~/postgres/backups/inventory_system-20210312.bak
Save and exit from the text editor.
Refer to Cron activities in the file /var/log/cron
For automated backup, there is a good note with the scripts at Postgresql wiki.
Sunday, February 28, 2021
Raspberry Pi display problems
Having successfully installed a new Raspberry Pi with Raspbian OS, it is common that the next reboot the screen display just leaves a blank screen. You just know its the display setting run when at the boot screen the system messages can be seen.
Firstly, the most important file you must know is the /boot/config.txt
This contains many configuration, that require the file to be save and RPi to be restarted.
If your display is working, but the resolution is wrong, then access the start menu And look for Configuration, or directly access the resolution setting, type
raspi-config
When the display is a touch screen, it would be a good idea to install a virtual keyboard. Do this by
sudo apt install florence
Back to troubleshooting a display that's not showing. Always check your display is powered, and that system messages appear at boot before proceeding here.
Step 1.
Ensure RPi is connected to your local network, then SSH to your RPi. On MS Windows there is a software named Putty.
Step 2.
Determine your device supported resolutions. Use either of following commands;
tvservice -m CEA
tvservice -m DMT
Depending on whether you are connected to a TV (CEA) or computer monitor (DMT). Generally, a TV with VGA cable will use CEA.
Step 3.
Edit the file /boot/config.txt
Use the settings identified in Step 2. If you are using CEA then the value of hdmi_group=1,
if its DMT then hdmi_group=2.
Eg 1. when connected to a monitor with resolution 1280×720 and frequency 60Hz, these are the settings;
hdmi_safe=1
hdmi_group=2
hdmi_mode=85
Eg 2. when connected to a TV through HDMI with resolution 640x480 and frequency 60Hz. Since the TV have a standard HDMI connector, hdmi_safe will be commented out. These are the settings;
#hdmi_safe=1
hdmi_group=2
hdmi_mode=4
Reference: Raspberry site
Thursday, February 18, 2021
How to alter Postgresql table owner
All this while I have been changing table owners individually in a specific schema. One fine day, there was a requirement to transfer all tables to another owner without changing the database ownership.
The existing tables where having owner as "postgres", but to allow other application to access, a separate user is created and allowed access. Here is how its done to assign the user;
\c mydatabase;
ALTER TABLE public.users OWNER TO contractors;
In the case where ALL tables are to have a new owner, then following can be done
select 'ALTER TABLE ' || table_name || ' OWNER TO contractors;' from information_schema.tables where table_schema = 'public' \gexec ;
Wednesday, February 10, 2021
Select Query with JSON column in Postgresql
Recently I encountered a problem to use JSONB type column with Reportserver and log it in their forum. Since I have made the example, why not post it here?
Here is an example to use JSONB type column in Postgresql 10 and newer.
Step 1: Create the sample database
CREATE TABLE public.products (id int4 NOT NULL PRIMARY KEY,
"name" varchar NOT NULL,
"product" jsonb NULL
);
Step 2: Add sample data
id|name |product |
--|-----------|----------------------------------------------------------------------|
1|Orange bod |[{"id": 18, "name": "Orange Gala", "value": "1Bll-1-99-aaa"}] |
2|Chicken Pie|[{"id": 4, "name": "Downtown Chicken Pie", "value": "1Bll-1-201-aaa"}]|
3|Apple Pie |[{"id": 5, "name": "Apple Pie", "value": "1All-1-1000-xzp"}] |
Step 3: Run an SQL query
SELECT name, jsonb_agg(t->'name') AS brand, jsonb_agg(t->'value') AS codeFROM products, jsonb_array_elements(products.product) t GROUP BY name;
The results
name |brand |code |
-----------|------------------------|-------------------|
Apple Pie |["Apple Pie"] |["1All-1-1000-xzp"]|
Orange bod |["Orange Gala"] |["1Bll-1-99-aaa"] |
Chicken Pie|["Downtown Chicken Pie"]|["1Bll-1-201-aaa"] |
Another method is to include a WHERE clause as shown below;
SELECT name, jsonb_agg(t->'name') AS brand, jsonb_agg(t->'value') AS codeFROM products, jsonb_array_elements(products.product) t
WHERE t->>'name'='Orange Gala'
GROUP BY name
I hope this simple example will benefit you.
Friday, January 22, 2021
SQL to replace username field with user id
The scenario is, a table called assets was loaded through a script, but the column updated_by which should contain the user id, is stored with the user name instead. How to replace the updated_by field with the user id?
Here is an example of the table structure;
assets(id, name, description, updated_by)
users(id, name)
Solution
Through the SQL command;
UPDATE assets t2
SET updated_by = t1.id
FROM users t1
WHERE t2.updated_by = t1.user_id;
Wednesday, January 13, 2021
How to install Docker ReportServer Community
ReportServer for Community is a Java based application that is available through Docker. There are options to install manually but some knowledge on Tomcat and Java is required.
The Docker (version 20.10.1) option installs on an image with Debian release 10 (Buster) with ReportServer version 3.3.0.
The ReportServer for community image is available at https://bitnami.com/stack/reportserver/containers
Pre-requisite:
- Installed Docker version 20+
- You have create an account with docker and Docker is running with your signin.
On Windows, open powershell and go to your install folder. In my case its C:\users\tboxmy
Retrieve from the server required image
docker pull bitnami/reportserver
Yet to know if this line was useful, as I did not run docker-compose up -d
curl https://raw.githubusercontent.com/bitnami/bitnami-docker-reportserver-community/master/docker-compose.yml > docker-compose.yml
Configure network and database
docker network create reportserver-tier
docker run -d --name mariadb -e ALLOW_EMPTY_PASSWORD=yes -e MARIADB_USER=bn_reportserver -e MARIADB_DATABASE=bitnami_reportserver --net reportserver-tier --volume C:\Users\nasbo\mariadb-persistence:/bitnami bitnami/mariadb:latest
List the images
docker images
Start ReportServer
docker run -d --name reportserver-community -p 80:8080 -e ALLOW_EMPTY_PASSWORD=yes -e REPORTSERVER_DATABASE_USER=bn_reportserver -e REPORTSERVER_DATABASE_NAME=bitnami_reportserver --net reportserver-tier bitnami/reportserver:latest
Access ReportServer from a web browser
http://localhost/reportserver
Use default username user and password as bitnami
Friday, November 13, 2020
Laravel quick commands for Artisan
Laravel utilise Artisan to help make working with development faster. This allow programmers to focus more on the development than the management of packages and some repeated workflows.
Here I list the top few commands that I use;
For scaffolding
- make:controller
- Create a controller file in app/Http/Controllers
- php artisan make:controller ArticleController
- Create a default model
- php artisan make:model Article
- Create a model along with migration and factory
- php artisan make:model Article -crmf
- Create migration file
- php artisan make:migration create_articles_table
- Process all the migration file that haven't been run before
- php artisan migrate
- Create Seeder file
- php artisan make:seeder CustomerTableSeeder
- Process seeder file
- php artisan db:seed
- php artisan db:seed --class=CustomerTableSeeder
- List command help
- php artisan list
- Routing
- php artisan route:list
- Debugging
- php artisan tinker
- Front-end user interface
- php artisan ui bootstrap|vue|react
- Remove Front-end user interface
- php artisan preset none
- Create front-end with user authentication
- php artisan ui vue --auth
- A stand alone server start, maintenance mode, normal mode
- php artisan serve
- php artisan down
- php artisan up
- Refresh laravel optimisation files
- php artisan dump-autoload
Tuesday, November 10, 2020
Laravel and logging of errors
During the course of development, there are many tools and approaches to debug a programme. In Laravel there is a default logging that supports RFC 5424 and here is how to apply it in a Laravel 7 based application.
As a point of reference, this article is for default Laravel 7 on a Apache2 webserver. Which means, if PHP-FPM is used, check the webserver log files. Additionally, there are many more advanced logging by Laravel, for example use of Rollbar, if you have time to explore.
What is Laravel logging?
Withing Laravel framework, its config/app.php determines classes that does logging. Monolog logging library is used to provide the classes that can be called from the framework. Its flexibility allows logging across different files and even disk.
The default logging uses a channel known as stack and is configured as
'default' => env('LOG_CHANNEL', 'stack'),
This provides logging in several levels of severity that range from in the following order;
- info
- debug
- notice
- warning
- error
- critical
- emergency
Context data is provided for a more consistent format as described in PSR-3.
How to enable default logging?
Edit the file .env and have this line to enable debug mode;
APP_DEBUG=true
Where is the default logging done? It all in the file laravel.log found in <project_folder>/storage/logs. Ensure the application have correct permission to write app/storage and all its subfolders. When using Selinux, also ensure its allowed to write.
When is logging done?
This can be done practically any where, such as within the controller, views and any other executable.
How to do the logging?
Taking that you have by now enabled debug mode.
Lets look at how its done within a Controller.
- Ensure top of the controller file contains the line
- use Illuminate\Support\Facades\Log;
- Write the code to log your message
- Log::info('This is where the code runs');
Once when you run the application and the Log::info( ) gets triggered, have a look at the end of file storage/logs/laravel.log to find the message.
Will consider to write further on formatting of the log in order for logging tools to pull data and generate reports or monitoring
Wednesday, November 4, 2020
Laravel ErrorException file_put_contents
After working on any Laravel project for a period of time, its possible that you would change the project folder to another location or drive. Lets say I have a Laravel project called employeeManagement in C:\users\tboxmy\employeeManagement and I make a copy of this to Z:\tboxmy\workspace\project while renaming the project name.
Problem
For some strange reason, the pages are not loading properly and the following error appears.
ErrorException
file_put_contents(Z:\tboxmy\workspace\project\storage\framework/sessions/c34niIDr5qyV8Fyf0qXFLXSF1IlOv3yOulSC9sHI): failed to open stream: No such file or directory
I have also noticed that the same problem causing that ErrorException SOMETIMES doesn't appear but it is actually loading pages from the original folder location. So when I edit my codes in Z:\tboxmy\workspace\project the changes just doesn't appear in the application. To determine this, just try to rename the original project folder and this error WILL appear.
There are 2 aproches to solve this, which does the same thing.
Solution 1
Step 1
Step 2
Step 3 : Update the cache in all installed plugins/libraries
Solution 2
Step 1
Step 2
Saturday, September 12, 2020
Binding Mouse Buttons on Linux Mint Tricia
Following describes how was the mouse buttons response and configured for
Tinytech GM-924 on Linux Mint 19.3 Tricia.
Initial response
A. Firefox web browser
Within the Firefox web browser, the left and right mouse buttons functioned as normal. The center scroll button caused the audio volume to increase or decrease. When scroll button was clicked, an X appeared.
At the left side were 2 buttons. Both only showed an X when clicked.
Hold down Left+Right button, the auto scroll appears. If this doesn't appear in Firefox web browser, you can set it up in Firefox menu.
Menu ->Preferences. Search for scroll.
Enable "Auto Scrolling", restart Firefox web browser.
Sometimes, there isn't any response to the mouse after I touched the USB connection. I have not found any reason for this. However, you can enable the mouse again by pressing the button above the scroll button.
B. Command prompt window
On the command line terminal window.
Left click on a text line, will highlight a word.
Left double click on a text line, will highlight the whole sentence.
Left+Right button click will paste the last highlight text.
Right button will open the options windows.
Scroll button works the same as Left+Right button click.
Scroll front and back scrolls up and down the screen window.
How does Linux mint detect these buttons?
Open command line terminal and run a simple test by clicking each of the button.
xev -event button
Here are the results I got;
- Left button - Button 1, state 0x100
- Right button - Button 3, state 0x400
- Left+Right button - Button 2, state 0x200
- Scroll button - Button 2, state 0x200
- Scroll button push forwxbindkeys - Associate a combination of keys or mouse buttons with a shell commandard - Button 5, state 0x1000
- Scroll button pull backwards - Button 4, state 0x800
- Side forward button - Button 9, state 0x0
- Side back button - Button 8, state 0x0
How to program the side forward and back buttons?
Install the package xbindkeys and xvkbd, from the description it says;
xbindkeys - xbindkeys is a program that allows you to launch shell commands with
your keyboard or your mouse under the X Window System.
It links commands to keys or mouse buttons, using a configuration file.
It's independent of the window manager and can capture all keyboard keys
xvkbd - xvkbd is a virtual (graphical) keyboard program for X Window System
which provides facility to enter characters onto other clients
(software) by clicking on a keyboard displayed on the screen. This
may be used for systems without a hardware keyboard such as kiosk
terminals or handheld devices. This program also has facility to
send characters specified as the command line option to another
client.
I refer to syntax at http://xahlee.info/linux/linux_xvkbd_tutorial.html
The configuration here is per user. It means, the file must be configured for each user in the system.
- Edit the file ~/.xbindkeys
- Restart xbindkeys service
pkill -f xbindkeys
xbindkeys
Here are 2 example of the file ~/.xbindkeys
Example 1: Launch xed and nemo
In order launch nemo file manager, with the side front button AND to lauch xed text editor with the side back button.
# bind side left forward button
"xed"
m:0x0 + b:8
"nemo"
m:0x0 + b:9
Example 2: Supertuxkart
Use the numpad 4 is view from left and numpad 6 is view from right. This is for laptops that doesn't have the side full numeric keypad that is normally found on desktop keyboards.
Lets program the side front for numpad 4, side back button for numpad 6.
"xvkbd -text '\[KP_4]' "
m:0x0 + b:8
"xvkbd -text '\[KP_6]' "
m:0x0 + b:9
Thursday, July 16, 2020
Create a local Git Repository
How to create a remote GIT repository and connect to it.
Sunday, June 14, 2020
Install Postgresql 12 on Linux Mint
Overview
- It is a long term support (LTS) which means, patches will be maintained till 2023.
- Installation of Linux Mint have better hardware detection and supports modern BIOS installation to utilise password at BIOS.
- Include a movie player that utilises hardware optimisation.
- Its Linux desktop environment called Cinnamon, is light weight enough for many lower spec computer. Computers with lower speed hard disk have always suffered in a windows environment, Cinnamon greatly improves any windows experience.
- Higher level of security for those who are paranoid about PC security.
Postgresql 12
- Improved table indexing features. Such as rebuild index table without blocking writes to an index, and this reduces down time.
- Partitioning of tables to improved queries from a limited set of data.
- JSON document query support.
- Just-in-time compilation to process large data (data warehouse) more efficiently.
Installation
- Add Postgresql repository
- Update existing system
- Install Postgresql 12 server. This includes the server (postgresql-12) and client (postgresql-client-12) application.
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt update
sudo apt upgrade
- The database will be stored at /var/lib/postgresql/12/main
- Logging information at /var/log/postgresql/postgresql-12-main.log
Accessing the server
Display server version (the Uppercase is a matter of good practice)
SELECT version();
List database schema
\l
Switch database schema
\c database_name
Describe a table
\d table_name
Get the last command
\g
Show history of commands
\s
Help with a command
\h command_name
Exit Postgresql client
\q
Friday, June 5, 2020
Install Tensorflow and Keras on Centos 7 Linux
Thursday, June 4, 2020
Install Python on Centos 7 Linux
- Back-end web application
- Desktop application
- Processing huge amount of data
- Control a computer
Install Python
Extra pip example
Saturday, May 16, 2020
Postgresql 10: Create database and user
Default user created by Postgresql is named postgres, that can be used to create any database schema and user roles. For this tutorial, Postgresql is installed on Centos Linux 7. To start postgresql client and access the default user, at the terminal type;
Steps to create the database are as follows;
- Create the database. In this case we call it student_management.
- Create user and assign password for login. We call out user student and password is 123456
- Assign the access to the database. We give full privileges to read, write.
- Enable the user to login.
- Exit from client (optional)
CREATE ROLE student WITH PASSWORD '123456';
GRANT ALL PRIVILEGES ON DATABASE student_management TO student;
ALTER ROLE student WITH LOGIN;
Next, test by login with that user account and password.
There is an alternative approach for a dedicated database server that require users to have their own databases. This approach doesn't require you to use the psql client. It is useful when you plan to have scripts that auto generate the process.
sudo -u postgres createuser --interactive
sudo adduser developer
sudo passwd developer
The user "developer" can login and get connected to the default database with the same name as the user. In this case the database name is "developer".
Login as the user.
Friday, May 15, 2020
Laravel: Getting started
In order to get started with Laravel, there are required software to run composer and laravel that needs to be installed. This includes;
- Web server
- PHP
- Composer
- Node JS
Step 1. Install PHP 7.3 or newer.
If you havent installed PHP, follow notes from previous post.After installing PHP, install all the regular extensions. Ensure PHP is working with the web browser.
Step 2. Web server.
In this case, I am using Apache HTTPD. Install this and test that the php is working.Step 3. Composer
Download the installer.sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Step 4. Node JS
sudo yum install nodejs
You are ready to work with Laravel projects. Here are links to the remainder tutorials
Part 1, Part 2,
Thursday, May 14, 2020
Install Postgresql 10 database on Centos 7
Installation and configuration of Postgresql 10 on Centos 7
Installation
Centos Linux 7 by default installs Postgresql version 9. These are summary of steps in order to install Postgresql version 10, the following steps can be taken.- Yum manages the installation of software, and utilises a list of repositories of there to locate its repository. It is highly advised to update existing software with yum before proceeding with software installations. Add the additional repository site must be added for Postgresql 10 from postgresql.org
- Install the version of Postgresql database client software that is needed to open the database.
- Install the version of Postgresql database server software. This will hold the database files and controlling software.
- Initialise Postgresql database files. This will create the username "postgres" where it is configured to run all the client commands.
- Start Postgresql database server.
- Test the server by requesting info.
- Configure Centos 7 to automatically start at boot up.
At a terminal, execute the commands
# yum install postgresql10
# yum install postgresql10-server
# /usr/pgsql-10/bin/postgresql-10-setup initdb
# systemctl start postgresql-10
# /usr/pgsql-10/bin/postgres -V
# systemctl enable postgresql-10
Using the client
For those who wish to use the postgres clients, here are commands to get started.Login as user "postgres" and use the Postgresql client.
# sudo -u postgres psql
Once in psql, here are several commands to browse the database;
Display server version (the Uppercase is a matter of good practice)
SELECT version();
List database schema
\l
Switch database schema
\c database_name
Describe a table
\d table_name
Get the last command
\g
Show history of commands
\s
Help with a command
\h command_name
Exit Postgresql client
\q
Remote access and firewall
In development databases, many users may require to access the database from remote computers. On the default Centos 7, with firewall running this require some configuration. The steps involved;
- Add httpd and postgresql service rule to the firewall. The httpd is an additional web service I am demonstrating here.
- Restart firewall
- Configure postgresql to listen from incoming networks, or all networks. Replace the line listen_addresses = 'localhost'
- Allow user authentication from incoming networks, or all networks. Replace the line with 127.0.0.1/32
- Restart postgresql
listen_addresses = '*'
host all all 0.0.0.0/0 md5
Tuesday, May 5, 2020
Laravel 6 Step by Step Tutorial Part 2
In order to proceed with part 2 of the tutorial, please complete part 1 as posted in
First of Laravel 6 step by step guide.
The tutorial can be followed by having your copy of PHP 7.3 onwards and a database. Notes are provided for MySQL and Postgresql database.
This demonstrates how to implement data relationships of has one. In Laravel this is implemented with the function belongsTo. The idea is to maintain a list of articles where each have one author. That author could essentially have written many articles.
Saturday, January 18, 2020
Install MongoDB database on Centos 7
MongoDB is a noSQL database and is available on Centos Linux 7. Ensure that SElinux is only on permissive.
For cases SElinux is enforcing, additional steps need to be taken which is outside of this installation note.
Step 1: Configure the repository
Create the file /etc/yum.repos.d/mongodb-org.reponame=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
Step 2: Install and start
sudo yum install -y mongodb-orgsudo systemctl start mongod
If all is running good, then allow it to start at boot time.
sudo systemctl enable mongod
Step 3: Verify
mongo
db.version()
exit
Further configuration can be done with the file /etc/mongod.conf
Allow database through the firewall
sudo firewall-cmd --zone=public --add-port=27017/tcp --permanent
sudo firewall-cmd --reload
Those with Selinux in mode Enforcing, allow the default mongodb port.
sudo semanage port -a -t mongod_port_t -p tcp 27017


