array_diff in excel – finding missing values from column B that exist in column A

Fill column A with bigger sample space, aka the longer array.

Fill column B with smaller array, that has few or none of the elements from column A

Now, you need to find out values that are in column A but not in column B, here is what you do.
Create a separate column C and put this formula in cell C1 or $C$1

=IF(ISERROR(MATCH(A1, $B$1:$C$<LAST_ROWNUMBER_THAT_EXISTS_IN_COLUMN_B>, 0)), A1, "")

Ultimately your formula becomes match function dependable for whole column A. You just have to drag the cell C1 downwards.

How to fix CORS error for amazon s3 files and resources?

Go to bucket

In the bucket permissions tab

There is a section for CORS, put the following in it and save.

[
    {
        "AllowedOrigins": [
            "*"
        ],
        "AllowedMethods": [
            "GET"
        ],
        "MaxAgeSeconds": 3000,
        "ExposeHeaders": [
             "Content-Range",
             "Content-Length",
             "ETag"
        ],
        "AllowedHeaders": [
            "Authorization",
            "Content-Range",
            "Accept",
            "Content-Type",
            "Origin",
            "Range"
        ]
    }
]

centos web panel – vhost templates for proxying websocket traffic

http://wiki.centos-webpanel.com/webservers-vhost-templates

Templates location: /usr/local/cwpsrv/htdocs/resources/conf/web_servers/
– Folder main contains main configuration for WebServers
– Folder vhosts contains vhosts configuration for domains (this is what you need)

How to create a template file
The easiest way to do that is to simply copy an existing file and then edit a new file you have created.
Note that you need to have .tpl and .stpl files (tpl is for http and stpl is for https version)

Let’s do one example for apache vhost with nginx

cd /usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/nginx/
cp default.tpl my-template.tpl
cp default.stpl my-template.stpl

Now you can edit these newly created template files.

Template folders explained
List from folder: /usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/

httpd = apache templates
nginx = nginx templates
varnish = varnish templates
php-fpm = php-fpm service templates (used for all php-fpm versions)

add a block

map $http_upgrade $connection_upgrade {
	default upgrade;
	'' close;
}

also add these inside “location /” block

		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection $connection_upgrade;
		proxy_set_header Host $host;

basic cwp with jenkins and nodejs

hostname srv1.example.com
yum -y install wget
yum -y update
reboot


cd /usr/local/src
wget http://centos-webpanel.com/cwp-el7-latest
sh cwp-el7-latest -r no --phpfpm 7.3 --softaculous no



reboot



sudo wget -O /etc/yum.repos.d/jenkins.repo \
    https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum upgrade
sudo yum install epel-release java-11-openjdk-devel
sudo yum install jenkins
sudo systemctl daemon-reload
curl -sL https://rpm.nodesource.com/setup_12.x | bash -
sudo yum install nodejs npm -y
sudo npm install pm2@latest -g

How to generate a patch with edited files? How to zip latest committed changes only

zip archive.zip $(git diff-tree --no-commit-id --name-only -r latest-commit-id)

Reference: https://stackoverflow.com/a/42971972/2229148

sometimes you need all the files that were updated so you can patch an external app which doesnt uses same git project or many other scenarios in which we need a zip or tar of those files. Use the above command to do so

There is a smarter way also, if you want all the changes from last 5 commits, use the command like this:

zip archive.zip $(git diff-tree --no-commit-id --name-only -r HEAD~5 HEAD)

Basic Authentication in nginx for any domain, server or location block

sudo yum install httpd-tools
sudo htpasswd -c /etc/nginx/conf.d/vhosts/.htpasswd USERNAME
Enter Password: xxxxx
sudo chmod 644 /etc/nginx/conf.d/vhosts/.htpasswd

Update the domain.conf file like /etc/nginx/conf.d/vhosts/myrestricteddomain.com.ssl.conf

Ideally, use it in server config

server {
satisfy all; 
auth_basic "Restricted Area";
auth_basic_user_file /etc/nginx/conf.d/vhosts/.htpasswd; 
	location / {

Save and restart nginx

Installing a testing instance for Magento CLI only

Prerequisite:

  • Magento repo access keys
  • Mysql Database, username and password
  • a domain name pointing to a server

if you dont have access key, get a pair here :

https://marketplace.magento.com/customer/accessKeys/

php -d memory_limit=-1 /bin/composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.2.11 ./

In the above command, you can change version/subversion of magento repo. You can also change the install directory

After the successful run of above command:

bin/magento setup:install \
--base-url=https://testmagento.domain.com \
--db-host=localhost \
--db-name=testmage_x1 \
--db-user=testmage_x1 \
--db-password=WEux3dxxxxw \
--admin-firstname=xxx \
--admin-lastname=yyy \
[email protected] \
--admin-user=admin \
--admin-password=WwKhxxxxxxEK \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1



YOu will see Magento Admin URI: /admin_10lf7y after successful run

Next is installing sample data: totally optional

php -d memory_limit=-1 bin/magento sampledata:deploy

OPtional: install or update composer version

composer self-update --2

https://blog.packagist.com/composer-2-0-is-now-available/
https://getcomposer.org/

Jenkins auto deploying flask in test env with last build process kill and pipenv

#!/bin/sh
cd $WORKSPACE
export PY=/usr/local/bin/python3
export FLASK_RUN_PORT=4005
$PY -m pip install pipenv
$PY -m pipenv install --dev
export VENV_HOME_DIR=$($PY -m pipenv --venv)
source $VENV_HOME_DIR/bin/activate
flask db upgrade
flask populate-initial-data
export BUILD_ID=XYZapi
$WORKSPACE/killlastbuild.sh
flask run &
deactivate

killlastbuild.sh can have anything inside it depending upon your project requirements. I put 2 process killers to kill background-ed daemon processes from previous build command

ps -Af | grep "xyzapi" | grep -v grep | awk '{print$2}' | head -1 | xargs kill -9
ps -Af | grep "xyzapi" | grep -v grep | awk '{print$2}' | head -1 | xargs kill -9

A basic time difference calculator in google script js

In your Google Sheet, Click “Tools” and then choose “Script Editor“. Put the code given below. Don’t forget to use function in your result column as “=dodiff(cell1,cell2)

function dodiff(a, b) {
    if (a)
        a = fix(a);
    if (b)
        b = fix(b);
    if (Array.isArray(a) && Array.isArray(b)) {
        if (b[1] > a[1]) m = b[1] - a[1];
        else {
            m = b[1] - a[1] + 60;
            b[0]--;
        }
        if (b[0] >= a[0]) h = b[0] - a[0];
        else {
            h = b[0] - a[0] + 12;
        }
        m = m / 60;
        return (h + m).toPrecision(4);
    }
}

function fix(a) {
    if (a)
        x = a.toString().replace(" ", '').replace("am", "").replace("pm", "").replace("PM", "").replace("AM", "");
    x = x.split(":");
    x[0] = parseInt(x[0]);
    x[1] = parseInt(x[1]);
    return x;
}