29 December, 2021

How to Cron Job in CentOS 7/8

 A cron job is scheduled operation which can execute a script or an API at any defined interval.

To create a cron job in a CentOS Server you’ll need to edit a file called CronTab.

CronTab is a configuration file that contained commands that are read by Cronie, a command scheduler that is supposedly already installed in your CentOS server.

To edit the crontab file,

EDITOR=nano crontab -e

To creadte a scheduled task in Cron,

* * * * ping http://www.example.com

The first 5 fields of a crontab command define

  • minute (0-59)
  • hour (0-23)
  • day of the month (1-31)
  • month (1-12)
  • day of the week (0-6)

An asterisk, * in a time runs the command at every valid value.
After first five field that define the schedule, next field is a shell command that is supposed to be executed.

Example,
To ping a web address at every minute,

* * * * ping http://www.example.com

To run a php script at every 2 minutes

*/2 * * * * php /var/www/html/myscript.php

To hit an GET REST API every week

0 0 * * 0 curl https://example.com/api/some_api

You can test out the required fields values for creating a schedule on crontab.guru

Some of the examples for creating a schedule

  • * * * * * – Runs the command every minute.
  • 12 * * * * – Runs the command 12 minutes after every hour.
  • 0,15,30,45 * * * * – Runs the command every 15 minutes.
  • */15 * * * * – Runs the command every 15 minutes.
  • 0 4 * * * – Runs the command every day at 4:00 AM.
  • 0 4 * * 2-4 – Runs the command every Tuesday, Wednesday, and Thursday at 4:00 AM.
  • 20,40 */8 * 7-12 * – Runs the command on the 20th and 40th minute of every 8th hour every day of the last 6 months of the year.

How to LAMP on CentOS 7 with phpMyAdmin

 LAMP stands for Linux, Apache, MySQL and PHP.

If you’re trying to build a web application using PHP you’ll need a server and installing the required applications on it. Collectively called LAMP, we’ll be installing the required applications on a Centos 7 Cloud Server and run a WordPress blog on it in later posts.

====== LAMP on CentOS 7 ======

update system

sudo yum update

check firewall status

sudo systemctl status firewalld

if firewall is not running, run it

sudo systemctl start firewalld

enable firewall to start on boot

sudo systemctl enable firewalld

allow HTTP and HTTPS services through firewall

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https

to open port through firewall

firewall-cmd --permanent --add-port=80/tcp

to check status of opened ports

firewall-cmd --list-all

reload for above rules for them to take effect

sudo firewall-cmd --reload

install APACHE module

sudo yum install httpd

start APACHE

sudo systemctl start httpd.service

to start APACHE on boot up

sudo systemctl enable httpd.service

check status of APACHE

sudo systemctl status httpd.service

check APACHE config status

sudo apachectl configtest

to restart APACHE

systemctl restart httpd.service

to install MariaDB

sudo yum install mariadb-server mariadb

start MariaDB

sudo systemctl start mariadb

setting up MariaDB

sudo mysql_secure_installation

check MariaDB status

sudo systemctl status mariadb

to enable MariaDB statup on boot

sudo systemctl enable mariadb.service

To install PHP on CentOS 7

Enable required repo

yum install epel-release yum-utils -y

download and install required repo

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

based on which php version is needed

yum-config-manager --enable remi-php71

install enabled version

yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql -y

to check its working

sudo nano /var/www/html/info.php

FILE: info.php

<?php
phpinfo();
?>

restart apache for changes to take effect

sudo systemctl restart httpd.service

check php version

php -v

to remove file

sudo rm /var/www/html/info.php

to install phpMyAdmin add EPEL repository

sudo yum install epel-release

install phpMyAdmin

sudo yum install phpmyadmin

to allow outside ip to connect to phpmyadmin

sudo nano /etc/httpd/conf.d/phpMyAdmin.conf

File: phpMyAdmin.conf

 <Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
      #Require ip 127.0.0.1
      #Require ip ::1
      Require all granted
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1
     Allow from ::1
   </IfModule>
</Directory>

restart apache for changes to take effect

sudo systemctl restart httpd.service

This finishes the LAMP stack installation on a CentOS 7 Server. Same could also be used on CentOS 8 as well.

17 December, 2021

DNS Server Addresses to block ads or access blocked content

To change DNS on Android devices, go to Settings > Network and Internet > Advanced > Private DNS

To change DNS on iOS Devices, Settings > WiFi > Select your connected WiFi Network > Configure DNS > Manual and add your preferred DNS server.

To change DNS on Windows PC, Settings > Network and Internet > Under Related Settings - Change adaptor  options > Right Click on your connected Network > Highlight Internet Protocol Version 4 (TCP/IPv4) > Click Properties and add your preferred DNS settings in the following window.




Google DNS

8.8.8.8

8.8.4.4


Open DNS

208.67.222.222

208.67.220.220


Quad9 DNS

9.9.9.9.

9.9.9.9


CloudFlare DNS

101.101.101.101.

101.101.101.101


Comodo DNS

1.1.1.1

1.0.0.1


Quad101 DNS

8.26.56.26

8.20.247.20


For Ad Blocking

dns.adguard.com

us.adhole.org

94.140.14.14 

94.140.15.15

Source: https://kb.adguard.com/en/general/dns-providers#adguard-dns

16 December, 2021

How to drag and drop item in Unity3D

 




For dragging and dropping to work we will need to first grab the Game Object and ensure while the Game Object remains grabbed it's position reciprocates the mouse position. This will work fine for not only PC bug mobile devices as well.


First define GameObject which we will be dragging.


public GameObject selectedPiece;



Now inside Update method we will give reference to touched/clicked object and while there is a reference available to an game object(selectedPiece;) we will move that object to mouse position.

When the reference is remove, object won't move therefore dropped.


void Update(){


RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

if (Input.GetMouseButtonDown(0)){


if(hit.transform != null)

            {

                if (hit.transform.CompareTag("PIECE"))

                {

                    selectedPiece = hit.transform.gameObject;

                }

            }

}


if (Input.GetMouseButtonUp(0))

        {

            selectedPiece = null;

        }


        if (selectedPiece != null)

        {

            Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);


            selectedPiece.transform.position = new Vector3(mousePosition.x, mousePosition.y, 0);


        }


}