Yahoo deleted all my emails !

I had created yahoo account way back when I was doing engineering. It was primarily used to forward and receive funny emails and class assignment files. I used to login once in a while, this email has always been my backup email.

After lot of time (certainly after 12 months ) I logged in to yahoo to find out all my emails are gone. Firstly I thought it still syncing, like outlook program but then I though, this is not a desktop application which needs to be synced. I have logged into their website but still I could see zero emails in inbox and zero emails in sent folder.

I thought something is wrong, I  tried reloading but nothing changed. Then I sent test email from my other email account and after few seconds, I could see my inbox has one email. So this certainly not an issue with the loading of email.

That’s when I googled to find an horrifying fact. Yahoo has deleted all emails from users who has not logged in for over a 12 months !

They think account is abandoned if someone has not logged in for 12 month.

Well, its free account and they can do whatever they want but at least I expected an email on my back up email saying my account will be deleted since I have not logged in for 12 months and asking me to take corrective action. I got it from dropbox in similar scenario

You can refer to this link for more information.

Yes, I checked by back up email box and I don’t see any notification before yahoo deleted my email box !.

Over the period of time, I created many email IDs and I deleted or stopped using many of those which I though were unnecessary but never ever I though to give up my Yahoo account. I was like me bench-marking stone on internet. This account was special to me because it was first email that I created and It had lot of my old emails from my buddies. But now, without data this email is no longer special. Thanks Yahoo for helping me make this decision to give up this account itself.

I guess this is adios Yahoo.

How to Install Notepad++ on Ubuntu

Notepad++ is one the best tool for developers. Notepad++ is a free and powerful source code editor and Notepad replacement that supports several languages. There are 3rd party plugins available to extend the functionality of the Notepad++.

If you are using windows, you can simply go to this link and download exe file to install it.

If you want to use it on Ubuntu, you would need to make some changes. Good news is that Notepad++ is now (unofficially) available as a Snap package for Linux user.

Step#1 install snapd

check if you have snapd install on your machin by using following command

$ sudo apt list --installed | grep -i snapd

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libsnapd-glib1/now 1.13-0ubuntu0.16.04.1 amd64 [installed,upgradable to: 1.33-0ubuntu0.16.04.1]
snapd/xenial-updates,now 2.34.2 amd64 [installed,automatic]
snapd-login-service/now 1.13-0ubuntu0.16.04.1 amd64 [installed,upgradable to: 1.33-0ubuntu0.16.04.1]
snapd-xdg-open/xenial-updates,now 2.34.2 amd64 [installed]

If you don’t see last line “snapd-xdg-open”, please run following command

sudo apt-get install snapd snapd-xdg-open

Step#2 Install Notepad++

After snap installation is completed, you can install notepad++ using following command

sudo snap install notepad-plus-plus

it will take some time based on your network speed. in my case, it was stuck at following for lot longer

Automatically connect eligible plugs and slots of snap "notepad-plus-plus"

Once installation is complete, you can start using notepad++

How to get post tags and categories

Many times you might need to display post tags or categories along with the post. This can be achieved by using following code


<?php
echo get_the_tag_list('<p>Tags: ',', ','</p>');
?>

If you are using custom taxonomy, you can use following code


<?php echo get_the_term_list( $post->ID, 'modernquotetaxonomy', 'Tags: ', ', ' ); ?>

Using WP Query for Custom Posts

WP Query can be used to fetch posts as per your requirement. Simple syntax for WP_Query is as below

WP_Query for Custom Posts

  <?php  $args = array(
    'post_type' => 'modernquote',
    'tag' => 'success',       
     'orderby' => 'post_date',
     'order'   => 'ASC');
   
  // Custom query.
  $query = new WP_Query( $args );
   
  // Check that we have query results.
  if ( $query->have_posts() ) {
   
      // Start looping over the query results.
      echo "<ul class='list-group '>";
      while ( $query->have_posts() ) {
          $query->the_post();
      // echo '<a href="' .get_post_permalink() .'"><li class="list-group-item">'. get_the_title() . '</li></a><br>';
      echo '<a href="' .get_post_permalink() .'" class="list-group-item">'. get_the_title() . '</a>';
      }
      echo "</ul>"; 
  }
  // Restore original post data.
  wp_reset_postdata();
  
  ?> 

WP_Query for Custom Posts with conditions

  <?php  $args = array(
    'post_type' => 'modernquote',
    'tax_query' => array(
        array (
            'taxonomy' => 'modernquotetaxonomy',
            // 'field' => 'slug',
            'terms' => 'love hindi',
        )
    ),      
     'orderby' => 'post_date',
     'order'   => 'ASC');
   
  // Custom query.
  $query = new WP_Query( $args );
   
  // Check that we have query results.
  if ( $query->have_posts() ) {
   
      // Start looping over the query results.
      echo "<ul class='list-group '>";
      while ( $query->have_posts() ) {
          $query->the_post();
      // echo '<a href="' .get_post_permalink() .'"><li class="list-group-item">'. get_the_title() . '</li></a><br>';
      echo '<a href="' .get_post_permalink() .'" class="list-group-item">'. get_the_title() . '</a>';
      }
      echo "</ul>"; 
  }
  // Restore original post data.
  wp_reset_postdata();
  
  ?> 

How to generate letsencrypt Wildcard SSL certificate Step-By-Step

In 2017 letsencrypt announced that it will begin issuing wildcard certificates in January of 2018.  While installing it, I faced lots of issues but thanks to letsencrypt community and support, I was able to do it. Here is documentation of whole process which will help you do this quickly.


sudo certbot --server https://acme-v02.api.letsencrypt.org/directory -d example.com -d *.example.com --manual --preferred-challenges dns-01 certonly

After you run this command, you need to accept logging your servers IP publicly.

Also, you need to have access to add TXT record in your hosting provider. Here is screenshot of adding TXT record in digital ocean.

Once you add TXT record as required, please wait for 1-3 seconds before hitting enter.

$sudo certbot --server https://acme-v02.api.letsencrypt.org/directory -d goingplaces.me -d *.goingplaces.me --manual --preferred-challenges dns-01 certonly
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for goingplaces.me
dns-01 challenge for goingplaces.me

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.

Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.goingplaces.me with the following value:

xxxxxxxxxxxxxx_yyyyyyyyyy_zzzzzzzzzzzzzzzzz

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.goingplaces.me with the following value:

xxxxxxxxxxxxxxxxxxxx_yyyyyyyyyyyy_zzzzzzzzz

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2018-12-27. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le

Above command is run with certonly, meaning you need to add configuration manually in your nginx file.

add below to main server block


 # managed by Certbot

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

and new server block


server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    server_name example.com www.example.com;
    listen 80;
    return 404; # managed by Certbot
}

How to move WordPress site to new domain without losing SEO

Sometimes after starting a website or a blog, user might recognises that, he needs a different domain name or he would like to move to different domain suffix (he might want to move from *.net to *.com or he might would like to move to country specific domain suffix like *.in for India, *.de for Germany ,*.fr for France etc). Whatever might be the reason, following steps needs to be followed for effective movement without losing SEO

Before you start further, current website is the live example of domain migration. I had started this website with domain name as www.techtrekking.net, I was owning domain www.techtrekking.com but I was planning to use it for one of my other requirement. After realising that its not a good idea to use same domain name for two different ideas, I decided to move from .net to .com domain.

To test how this is working, please click following .net links and please see yourself, what is the actual site its opening

You can test this for any other url on this website and validate its functioning.

Before you start

You have two options for doing this change 1. Do the change on the live site 2. Do the changes on backup.

I suggest to use the second approach. Here, you don’t touch existing WordPress folder, you create a copy of current WordPress installation with new domain and simply change nginx config of old domain.

Step#1 Take Backup

This is the most important as you dont know what can go wrong during the migration. If something goes wrong, you can simply override the changes with the backups that you have. You need to take backup of three things

  • MySQL Database backup.
mysqldump -u [username] -p [databaseName] > [databaseName].sql
  • Folder which has your code (WordPress folder, including themes and plugins

Connect to your server using filezilla and copy folder as well as  MySQL dump to your location machine.

  • Back up NGINX config file

NGINX config file for any domains are located @ /etc/nginx/sites-available on a Ubuntu server

Step#2 Configure new domain on server

You need to make sure you have added A and CNAME records correctly. On your server as well as your domain registrar. This is exactly same as that of your earlier domain nothing different.

Once done, please create a nginx config file as explained in this post. Please refer to “Configure nginx” of this post.

This step is nothing new, it’s same that you would have followed while setting up your earlier domain which you need to be replaced with new domain.

Step#3 Changing the domain name

Go to Settings–>General and change the URLs from existing domain name to desired domain name.

Once you save this, you might get automatically logged off and you will have to login again. This will login using new domain

Step#4 Update internal and hard-coded links

You might have internal reference to your sites between different posts. Also, some links might be hard-coded in navigation bar. You need to get these changed. Changing this manually is easy if you have very few posts but if you have 50+ posts on your blog, doing this manually is not a good choice from efficiency and effectiveness point of view. You have following options to do this.

  1. Use the Velvet Blues Update URLs plugin if you can access your WP Admin Dashboard.
  2. Use the Better Search Replace plugin if you can access your WP Admin Dashboard.
  3. Use WP-CLI’s search-replace if your hosting provider (or you) have installed WP-CLI.
  4. Use the Search and Replace for WordPress Databases Script to safely change all instances on your old domain or path to your new one. (** only use this option if you are comfortable with database administration ** )

I personally used Velvet Blues Update URLs and it was effective.

Step#5 Adding 301 redirect.

Now you have moved to new blog, your internal links are taken care of but what about external links ? Someone might have hard-coded you link ? For example, one of my post was mentioned in a GitHub issue as a solution. This issue is already closed, I can not ping everyone to change the user reference. Then how to handle it ?

Best solution is using 301 redirect in your old domains server. I am using NGINX and this can be achieved using below

server {

    server_name techtrekking.net www.techtrekking.net;
    return 301 $scheme://techtrekking.com$request_uri;
}

Note: You need to continue owning old domain to ensure redirect is happening

Step#6 Updating Google and Bing webmaster

Since, Google and Bing will crawl your websites based on details you have provided in webmaster tools, updating your website with correct domain is very crucial.

Most important part is you update you sitemaps.

Step#6 Update Google Analytics (Optional, needed only if you are using Google Analytics)

Once this is done, you will continue to get new visitors using SEO as well as you will not lose your existing visitors due to

Getting Started with Mathematics – Again

We all know mathematics ( Well I mean, you know there is something called as mathematics, you or rather most are not aware of mathematics). This is a quick refresher and a handy reference for Mathematics.

What is Math?

Well, we all know what is math. It deals with numbers and only some of us seems to know it and most of us hate it. So we will know what math is, however, its difficult to define it and define scope of mathematics.

The Merriam-Webster dictionary defines mathematics as “the science of numbers and their operations, interrelations, combinations, generalizations, and abstractions and of space configurations and their structure, measurement, transformations, and generalizations.” Well, the defination makes it more complex.

We will leave mathematics definition to experts and we will look at what constituents mathematics.

Major Division of Mathematics

There are various ways of classifying different sub-streams of mathematics, some varies a lot and some have similarity. Mathematics is still heavily researched areas and who knows, there will be another sub-stream of mathematics.

  • Pure Mathematics
    • Arithmetic
      • Number Theory
    • Algebra
      • Elementary Algebra
      • Linear, Multilinear Algebra
      • Order Theory
      • Field Theory
    • Geometry
      • Discrete Geometry
      • Algebric Geometry
      • Trignometry
      • Differencial Geometry
      • Finite Geometry
      • Topology
    • Combinatorics
    • Calculas
      • Differential Equation
      • Numerical Analysis
      • Functional Analysis
  • Applied mathematics
    • Probability
    • Mathematics Statistics
    • Computational Science
    • Mathematical Physics
    • Game Theory
    • Information Theory

Some of these sections can be debated as whether they are mathematics or physics etc, however, I have kept them as per my understanding. I will keep reviewing this list as and when my understanding matures.

It is practically impossible to create blog for these topics as each of them are huge topic and more and more dept is being uncovered everyday. I will try to create some notes which will be handy.

Thanks

Using templates in Python Flask framework

Flask will look for templates in the templates folder. So if your application is a module, this folder is next to that module, if it’s a package it’s actually inside your package:

Currently our application is developed as module. We will see the difference between module and package later.

Adding Templates

Now let us add a folder called templates inside application directory and add required html files here. Update application file to use html files

from flask import Flask
from flask import render_template
app = Flask(__name__)

@app.route('/')
def index():
	return render_template('index.html')

@app.route('/aboutus')
def aboutus():
	return render_template('aboutus.html', name="techtrekking.net")

@app.route('/contactus')
def contactus():
	return render_template('contactus.html')

Please note  following changes to the base file:

  1. we have imported “render_template”
  2. usage of render_template for creating output
  3. Usage of parameter “name” while rendering the html file. This keyword will be accessible in template and will be displayed within {{}}

This is simple example  of using separate template files for each route. Here none of the code is shared across views

Advanced templates

Many times we have few fixed parts of the website, irrespective of the page, such as navigation bar and footer. If you have to keep this code in each html page, making any change in this code will be cumbersome process. Flask has a great feature to make this change once and apply this to all pages. This is achieved by creating base template and extending the base template for individual pages.

Here we will create a base template having navigation bar, footer and different section. When we have to render different pages, we will simple reuse this base template and replace the required section run time.

Here is sample folder structure


├── myapp.py
└── templates
     ├── aboutus.html
     ├── base.html
     ├── contactus.html
     └── index.html

Base file structure


<!doctype html>
<title>{% block title %}{% endblock %}</title>
<a href="/">home</a>
<a href="/aboutus">about us</a>
<a href="/contactus">contact us</a>

<header>
{% block header %}{% endblock %}
</header>
{% block content %}{% endblock %}

About us file is as below


{% extends 'base.html' %}

{% block title %} about us{% endblock %}

{% block header %}
<h1>About us header</h1>
{% endblock %}

{% block content %}
<h4>About us</h4>
<p>lorum ipsum text here</p>
<p>this is {{ name }}</p>
{% endblock %}

Now whenever you want to  change header or footer, you need to change only at one place.

Please note following

  • I have created blocks in base file. More the number of blocks, more the flexibility
  • Blocks will be replaced in the individual templates.
  • Base code outside the blocks gets copied as is.
  • If base block is not placed in individual template, base block will be displayed

How to plot simple and Candlestick chart using Python – pandas matplotlib

Pandas and Matplotlib can be used to plot various types of graphs. Simple timeseries plot and candlestick are basic graphs used by technical analyst for identifying the trend.

Simple time Series Chart using Python – pandas matplotlib

Here is the simplest graph. It uses close price of HDFCBANK for last 24 months to plot normal graph

Here is the sample output

Candlestick chart using Python – pandas matplotlib

As per this link, module matplotlib.finance is deprecated in 2.0 and has been moved to a module called mpl_finance. This is still working when I have motplotlib version 2.1.2. This may stop working in any future releases, however, you can use mpl_finance module to use this feature. Please note that mpl_finance is no longer maintained.

 

Here is the output

Candlestick chart with SMA overlay using Python – pandas matplotlib

here is the output

Scatter plots in Matplotlib – Data Visualization using Python

Scatter plots are one of the basic graphs used for data visualization. Scatter plot has following options, only first two are mandatory, rest all are optional.

plt.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, hold=None, data=None, **kwargs)

Here is simple program using scatter plot

Output of this program is as below

Here is a bit complex scatter plot using matplotlib

Output of above program

 

You can read documentation about scatter plot here.