How to Install WordPress multisite

Step#1

First you need to finish installing WordPress.  Please refer to “How to install WordPress” to get started.

Step#2

You need to add following line just above the line /* That’s all, stop editing! Happy blogging. */ inside wp-config.php file.

/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );

Now save wp-config file and login as admin to your WordPress site. Go to tools>Network Setup. This option is not available by default, its visible after you have made above changes in wp-config.php file

You will see following scree:

Now select your multisite option with subdirectory or subfolder as per your requirement. Whether to choose subdirectory or subfolder, its completely dependent on your requirement.

It will take few second to install multisite, once done following screen will appear.

Now add following settings just above the line reading /* That’s all, stop editing! Happy blogging. */ Below code is for subdomain, if you have selected subdirectory, it will be slightly different. Please use whichever code is displayed in your admin section.


define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'localgoingplaces.me');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Step#3

You can manually add each site, however when there are multile sites, this ecomes tedious process. This can be automated by using a plugin called nginx helper. Install plugin called as nginx-helper from install plugin section.

nginx-helper settings

You don’t have to network activate this plugin. Simply to go your base site plugin section and activate this simillar to other plugins.

Now to to Network Admin–>Settings–>Nginx Helper”. This option will be available only after you have activated the plugin (No Network activation is needed)

Please select enable nginx map and enable nginx logging

Update file nginx file

You would have already created nginx file while installing WordPress as per “How to install WordPress” post.  Now add following code at the start of nginx file.

Don’t copy below code as is. Use the line displayed in previous step in nginx-helper settings page


map $http_host $blogid {
default 0;
include /var/www/wordpressmultisite1/wp-content/uploads/nginx-helper/map.conf;
}

Also if you are planning to use subfolder option, please add following code just before closure of sever block


if (!-e $request_filename) {
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}

Now your multi-site is ready for the use

How to calculate Euclidean and Manhattan distance by using python

Euclidean Distance

Euclidean metric is the “ordinary” straight-line distance between two points.

if p = (p1, p2) and q = (q1, q2) then the distance is given by

Euclidean distance
Euclidean distance

For three dimension1, formula is

Euclidean distance
Euclidean distance

################################################################################################
#	name:	eudistance_samples.py
#	desc:	Simple scatter plot 
#	date:	2018-08-28
#	Author:	conquistadorjd
################################################################################################
from scipy import spatial
import numpy
from sklearn.metrics.pairwise import euclidean_distances

import math

print('*** Program started ***')


######################################################################### Calculating distance by using  python math function
############################################################# 2 D array
x1 = [1,1]
x2 = [2,9]
eudistance =math.sqrt(math.pow(x1[0]-x2[0],2) + math.pow(x1[1]-x2[1],2) )
print("eudistance Using math ", eudistance)

############################################################# 3 D array
# x1 = [1,1,4]
# x2 = [10,2,7]
# # Calculating distance by using math
# eudistance = math.sqrt(math.pow(x1[0]-x2[0],2) + math.pow(x1[1]-x2[1],2) + math.pow(x1[2]-x2[2],2) )
# print("eudistance Using math ", eudistance)

######################################################################### Calculating distance by using scipy
eudistance = spatial.distance.euclidean(x1, x2)
print("eudistance Using scipy", eudistance)


######################################################################### Calculating distance by using numpy
x1np=numpy.array(x1)
x2np=numpy.array(x2)
eudistance = numpy.sqrt(numpy.sum((x1np-x2np)**2))
print("eudistance Using numpy", eudistance)

eudistance = numpy.linalg.norm(x1np-x2np)
print("eudistance Using numpy", eudistance)


######################################################################### Calculating distance by using sklearn
eudistance =  euclidean_distances([x1np], [x2np]) # for some strange reasons, values needs be in 2-D array
print("eudistance Using sklearn", eudistance)

print('*** Program ended ***')

Manhattan distance

The distance between two points measured along axes at right angles.The Manhattan distance between two vectors (or points) a and b is defined as ∑i|ai−bi| over the dimensions of the vectors.

Manhattan distance
Manhattan distance

all paths from the bottom left to top right of this idealized city have the same distance.

Manhattan Distance
Manhattan Distance
1.
scipy.spatial.distance.euclidean. scipy.spatial.distance.euclidean. https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.distance.euclidean.html. Published August 28, 2018.

How to list All Installed packages – Ubuntu – sudo apt list

Many a times, we need to know list of installed packages on Ubuntu. We will achieve required task by using apt command. apt is a command-line interface which allows actions such as installing new software packages, removing unnecessary software packages, it can be used for updating the existing software packages as well as  searching for specific software packages etc.

sudo apt list --installed

This output might overwhelm you, if you want to check if specific package is installed, you can check this by following command

sudo apt list --installed | grep -i google

If you want to remove any application, use following commaand

sudo apt-get remove <application_name>

Sometimes applications is split up into multiple packages. In such cases, to uninstall all related packages and configurations, use following command

sudo apt-get purge <application_name> 

How to Install Google Chrome on Ubuntu

Gone are the days where you had to find a hack to install chrome on ubuntu. Google now officially provide *.deb package for installation on Ubuntu ( and *.rpm for fedora).

Step#1 Download the google package

Go to this link https://www.google.com/intl/en_in/chrome/ and click on download

 

Once you click on “Accept and Install”, following pop up will come.

Step#2 Install the package

If you have chosen to open with software package, once download is completed, it will open with software installer, as shown below

If you want to install it later, simply double click on google-chrome-stable_current_amd64.deb file and it will open with software installer, just like windows.

If you want to install using terminal use following commands. Run second command only if there are errors with unresolved dependencies.

sudo dpkg -i google-chrome-stable_current_amd64
sudo apt-get install -f

 

 

 

 

How to delete or renew Letsencrypt Certificate

I Normally we will let issues certificate to expire as per timeline but sometimes we might have to revoke or delete the SSL certificate. Please follow below steps to do so.

Checking where files are stored.

Let us go to/etc/letsencrypt and you will find following folder structure

/etc/letsencrypt$ ls -la
total 56
drwxr-xr-x  9 root root 4096 Aug 19 17:12 .
drwxr-xr-x 99 root root 4096 Aug 15 06:39 ..
drwx------  4 root root 4096 May  1 12:24 accounts
drwx------  8 root root 4096 Aug 19 12:27 archive
-rw-r--r--  1 root root  121 Mar 21 10:24 cli.ini
drwxr-xr-x  2 root root 4096 Aug 19 12:27 csr
drwx------  2 root root 4096 Aug 19 12:27 keys
drwx------  8 root root 4096 Aug 19 12:27 live
-rw-r--r--  1 root root 1143 May  1 11:50 options-ssl-nginx.conf
drwxr-xr-x  2 root root 4096 Aug 19 12:27 renewal
drwxr-xr-x  5 root root 4096 May  1 11:50 renewal-hooks
-rw-r--r--  1 root root  424 May  1 11:50 ssl-dhparams.pem
-rw-r--r--  1 root root   64 May  1 11:50 .updated-options-ssl-nginx-conf-digest.txt
-rw-r--r--  1 root root   64 May  1 11:50 .updated-ssl-dhparams-pem-digest.txt

I tried to access account and archive folder but it did not let me

/etc/letsencrypt$ cd accounts/
-bash: cd: accounts/: Permission denied

Let us find where required domains are stored

/etc/letsencrypt$ sudo find /etc/letsencrypt/ -name "*techtrekking*"
/etc/letsencrypt/archive/techtrekking.net
/etc/letsencrypt/live/techtrekking.net
/etc/letsencrypt/renewal/techtrekking.net.conf

Deleting the required certificate

sudo certbot delete is the simple command to delete certificates.

/etc/letsencrypt$ sudo certbot delete 
Saving debug log to /var/log/letsencrypt/letsencrypt.log

Which certificate(s) would you like to delete?
-------------------------------------------------------------------------------
1: mydomain.com
2: mydomain.com
3: mydomain.me
4: techtrekking.net
5: mydomain.com
6: mydomain.me
-------------------------------------------------------------------------------
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 4

-------------------------------------------------------------------------------
Deleted all files relating to certificate techtrekking.net. ------------------------------------------------------------------------------- 

How to renew letsencrypt certificate manually

Is the simpler that i thought. simply run command sudo certbot renewand it will renew whichever certificate is due for renewal. For others, you will get message that that domain is not due for renewal yet.

/etc/letsencrypt$ sudo certbot renew
Saving debug log to /var/log/letsencrypt/letsencrypt.log

-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/mydomain.com.conf
-------------------------------------------------------------------------------
Cert not yet due for renewal

-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/mydomain.me.conf
-------------------------------------------------------------------------------
Cert not yet due for renewal

-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/mydomain.net.conf
-------------------------------------------------------------------------------
Cert not yet due for renewal

-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/mydomain.com.conf
-------------------------------------------------------------------------------
Cert not yet due for renewal

-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/mydomain.me.conf
-------------------------------------------------------------------------------
Cert not yet due for renewal

-------------------------------------------------------------------------------

The following certs are not due for renewal yet:
  /etc/letsencrypt/live/mydomain.com/fullchain.pem expires on 2018-09-28 (skipped)
  /etc/letsencrypt/live/mydomain.me/fullchain.pem expires on 2018-11-09 (skipped)
  /etc/letsencrypt/live/techtrekking.net/fullchain.pem expires on 2018-09-28 (skipped)
  /etc/letsencrypt/live/mydomain.com/fullchain.pem expires on 2018-11-17 (skipped)
  /etc/letsencrypt/live/mydomain.me/fullchain.pem expires on 2018-11-09 (skipped)
No renewals were attempted.

How to add custom css file in WordPress?

One of the best thing about CSS is plug-able components, however this comes with following certain way of WordPress. Adding CSS from external files.

Adding Bootstrap CSS and JS files to WordPress


function my_scripts_enqueue() {

wp_register_script( 'jquery-slim-js', 'https://code.jquery.com/jquery-3.3.1.slim.min.js', array('jquery'), NULL, true );
wp_register_script( 'popper-js', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js', array('jquery'), NULL, true );
wp_register_script( 'bootstrap-js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js', array('jquery'), NULL, true );
wp_register_style( 'bootstrap-css', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css', false, NULL, 'all' );
wp_enqueue_script( 'jquery-slim-js' );
wp_enqueue_script( 'popper-js' );
wp_enqueue_script( 'bootstrap-js' );

wp_enqueue_style( 'bootstrap-css' );
}
add_action( 'wp_enqueue_scripts', 'my_scripts_enqueue' );

Adding custom CSS file to WordPress theme.

Now let us create a folder called css inside theme folder “twentyseventeen”. Following is the code to custom “carousel.css file.


function my_scripts_enqueue() {

wp_register_script( 'jquery-slim-js', 'https://code.jquery.com/jquery-3.3.1.slim.min.js', array('jquery'), NULL, true );
wp_register_script( 'popper-js', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js', array('jquery'), NULL, true );
wp_register_script( 'bootstrap-js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js', array('jquery'), NULL, true );
wp_register_style( 'bootstrap-css', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css', false, NULL, 'all' );
wp_register_style( 'carousel-css',get_template_directory_uri().'/css/carousel.css', array() );

wp_enqueue_script( 'jquery-slim-js' );
wp_enqueue_script( 'popper-js' );
wp_enqueue_script( 'bootstrap-js' );

wp_enqueue_style( 'bootstrap-css' );
wp_enqueue_style( 'carousel-css' );
}
add_action( 'wp_enqueue_scripts', 'my_scripts_enqueue' );

Adding custom CSS toWordPress child theme

But if you are using child them above will not work, you need to use following. Please note that, you need to useget_stylesheet_directory_uri() instead of get_template_directory_uri()


function my_scripts_enqueue() {

wp_register_script( 'jquery-slim-js', 'https://code.jquery.com/jquery-3.3.1.slim.min.js', array('jquery'), NULL, true );
wp_register_script( 'popper-js', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js', array('jquery'), NULL, true );
wp_register_script( 'bootstrap-js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js', array('jquery'), NULL, true );
wp_register_style( 'bootstrap-css', 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css', false, NULL, 'all' );
wp_register_style( 'carousel-css', get_stylesheet_directory_uri().'/css/carousel.css', array() );

wp_enqueue_script( 'jquery-slim-js' );
wp_enqueue_script( 'popper-js' );
wp_enqueue_script( 'bootstrap-js' );

wp_enqueue_style( 'bootstrap-css' );
wp_enqueue_style( 'carousel-css' );
}
add_action( 'wp_enqueue_scripts', 'my_scripts_enqueue' );

How to Install Hindi Fonts on Windows 10

Many times we need hindi typing to be done but we struggle to install hindi font. Intstalling hindi font is very simple process. Kindly follow below steps.

  • Download required front from internet.

You can download font from any of the following location ( I am not aware of copyright and user licensing at below locations, there are shared for reference only).

http://www.easynepalityping.com/download-hindi-fonts

http://indiatyping.com/index.php/download/hindi-fonts

  • Installing fonts

got to Control Panel –> Appearance and Personalization –> Fonts

or simple type fonts in Cortana search box and it will take you to required folder.

(For Windows 7 please go to “Control Panel->Fonts” )

To install newly downloaded font, simple drag *.ttf file. It will install the required font by itself after moving *.ttf file into this.

Installing Hindi font on windows 10
  • Using newly installed fonts

Reopen Microsoft Word and select font type as newly installed font as below.

Selecting Hindi Font Windows 10

After selecting font start typing using English keyboard and word will automatically convert it into required Marathi text.

Please let me know if you run into any issues while following above steps

Multi threading in Python

Multi-threading is a way of achieving multitasking. Many times we run into a situation where do done need to run code sequentially and would like to run two processes (functions ) in parallel so save some time.

Typically python executes code sequentially. For example, if you have called a function, next sentence will be executed only after function in previous row has completed execution.

Here is the sample code for multi-threading. We will be using python module threading


import threading
import time
from threading import Thread

def function1():
	print('Inside Function1. Now going to sleep')
	time.sleep(5)
	print('Function1 woke up from sleep')

def function2():
	print('Inside Function2. Now going to sleep')
	time.sleep(3)
	print('Function2 woke up from sleep')

if __name__ == '__main__':
    Thread(target = function1).start()
    Thread(target = function2).start()

Here is the output


python3.6 multithreading.py 
Inside Function1. Now going to sleep
Inside Function2. Now going to sleep
Function2 woke up from sleep
Function1 woke up from sleep

As you can see function2 and function1 are running in parallel. You can see function2 woke up first from sleep

Returning Multiple Values in Python using function

Functions are use to some repetitive activity to avoid adding same code multiple times. Functions sometime return a value  but sometimes may not even return anything, however, you might run into situations where you may want to return multiple values by using function. When you use return statement, it will return the  only one variable. But if you need multiple values, what can be done ?

This can be achieved by using multiple ways, your creativity is the limit, thats the beauty of any programming language.

Two most easiest ways are as below

  1. Return dictionary, tuple or list
  2. Return multiple variables at the same time

Returning dictionary, tuple or list

Here, you simply create a variable of datatype that can store multiple values such as dictionary, tuple or list.  This will add few lines of coding and code might not look as structured and beautiful as you wish but this works

Return multiple variables at the same time

This is nothing but above mentioned method, except, you delegate variable creation to python. Python will create a return a tuple having required values. You still need to take care while receiving the values.

Here is the sample code

def get_add_and_multi(num1,num2):
add = num1+num2
mult = num1*num2
return add,mult

result = get_add_and_multi(2,3)

add, mult = get_add_and_multi(2,3)

print("result :", result, "Datatype is :", type(result))
print("add :", add , "Datatype is :", type(add))
print("mult :", mult,"Datatype is :", type(mult))

As you can see, there are two ways of receiving data.

Output of this code is as below. Please note the data types

$ python3.6 returnmultiple.py 
result : (5, 6) Datatype is : <class 'tuple'>
add : 5 Datatype is : <class 'int'>
mult : 6 Datatype is : <class 'int'>

Plotly Dash folder Structure for Multi Page application

Normally whenever we present data, we need following two things

  1. Interactivity
  2. Different view of same or related data

So far we have looked at creating simple single page single graph applications. If you want to show multiple graphs on the same page, you can use multiple dcc.graph function. However, to make applicationmore userfriendly, providing different views at different pages which has different url is more user freindly. Please find below folder structure for creating some application.


├── app.py
├── index.py
└── apps
    ├── barchart.py
    ├── commonmodules.py
    ├── home.py
    ├── linechart.py
    └── scatterplot.py

You can find the code for this boiler plate here