[Linux] Get My Public IP

If You are not Behind a Router

  • You can find it out using ifconfig.

If You are Behind a Router

  • Your computer will not know about the public IP address as the router does a network address translation.
curl icanhazip.com

[Linux] Centos7 remove the old kernels

Why removing the old kernels?

  • Even though the old kernels are not harmful to your system, they still take up some space in your disk.
  • The menu of grub2 will become more complex and unuseful, squeezing your custom list to the bottom.

 1.Check Installed Kernels

rpm-qa kernel

 2.Remove Kernels

–count=n, n is the number of kernels YOU WANT TO LEFT.

yum install yum-utils
package-cleanup --oldkernels --count=1

 3.Set Number of Old Kernels Saved

edit /etc/yum.conf

installonly_limit=1

[C++] Tip for Reference

References have to be initialized, and will represent the variables assigned to them.

int x=10,y=5;

//wrong
int &A;
A=x;

//right
int &A=x;

//set x's value by y
A=y;

[C++] typeid()

#include<iostream>
#include<typeinfo>
using namespace std;

int main()
{
    int x;
    cout << typeid(x).name() << endl;
    system("pause");
    return 0;
}

[C++] *x++、*++x、*x+1

*x++ same as *(x++)

*++x same as *(++x)

*x+1 same as (*x)+1

[C++] swap(T &a, T &b)

//#include<algorithm> to use this template

template <class T> void swap (T& a, T& b)
{
    T c(std::move(a)); a=std::move(b); b=std::move(c);
}
template <class T, size_t N> void swap (T (&a)[N], T (&b)[N])
{
    for (size_t i = 0; i<N; ++i) swap (a[i],b[i]);
}