FAQs

This is a FAQs file which aims to deal with some small problems or not too much serious problems that may not be able to be categorized or defined, namely, this FAQs may cover a lot of domains of knowledge and focus on how to solve a problem, though most of which are small and simple and easy to deal with.

Let’s just start!

Programming Language

[Python]

How can I check the existence of attributes and tags in XML before parsing?

e.g. if party is None

Refer:
How can I check the existence of attributes and tags in XML before parsing

Fastest way to check if a value exist in a list

e.g. 7 in a

Refer:
Fastest way to check if a value exist in a list

How to judge two dates are within a specific ranger of a period

If you have one variable which is ‘2016-07-23 21:30:34:222’ and another one is ‘2016-07-23 1:00:12:213’ (Both 24-Hour-Time), how can you judge if the two times are within a day? if they are both datetime type variable, you can use the python built-in calculator class, just take a glance at the refers. If they are strings, you can choose to extra 10-character string and use SQL query: something Like ‘%2016-07-23%’ or just use python to judge if the other string contains the substring of one variable(e.g. 2016-07-23).

Refer:
How do I determine if current time is within a specified range using Python’s datetime module?
How to use Python to calculate time
Converting string into datetime

No module named PIL

Use pip install pillow to install the python image library. However, if you OS is macOS(OS X), you will need to use brew link jpeg && brew install libtiff libjpeg webp little-cms2(Provided you’ve installed Homebrew) in advance.

Refer:
ImportError: No module named PIL

Pillow Installation

Operating System

[Ubuntu]

Ubuntu VPN connection failed

PPTP means point-to-point tunneling protocol and VPN means virtual private network.

When I tried to set up a VPN connection using PPTP on Ubuntu, I failed. And the solution was none of service provider, it just needs to change some settings.

Just click on the wifi icon >> VPN connections >> configure VPN >> Choose one >> Edit >> Advanced >> Check Use Point-to-Point Encryption.

Refer:
Ubuntu VPN连接失败解决方案

MySQL remote connection failed

Login server by ssh using root role and login mysql using root role and use following commands to create a database ‘test’ and a user ‘test’ to make a sample, which is accessable to all the sources.

1
2
3
create database test character set utf8;
grant all privileges on test.* to 'test'@'%' identified by '123456';
flush privileges;

Then, use iptables -A INPUT -p tcp --dport 3306 -j ACCEPT to allow the mysql connection from remote. If you’ve done such steps and still get a “Connection Failed” error, it may be the mysql service is bind only on 127.0.0.1. Next, we have to edit /etc/mysql/my.cnf and find “bind-address” and change the ip address from “127.0.0.1” to “0.0.0.0” and use service mysql restart to restart mysql service.

[CentOS]

Tar Extract to specific directory[^How to Extract Tar Files to Specific or Different Directory in Linux]

tar -xf file_name.tar -C /target/directory

tar -xf file_name.tar.gz --directory /target/directory

[^How to Extract Tar Files to Specific or Different Directory in Linux]: How to Extract Tar Files to Specific or Different Directory in Linux

[macOS]

How to install maven on OS X[1]

Download and extract, then get the path, e.g. /opt/apache-maven-3.5.0

Then vi ~/.bash_profile and add following two statements:

export M2_HOME=/opt/apache-maven-3.5.0

export PATH=$PATH:$M2_HOME/bin

Save it and use source ~/.bash_profile to reload this configuration.


  1. Mac OS X下Maven的安装与配置