Wednesday, May 31, 2017

Privacy Policy

Privacy Policy

Last updated: 25th November 2023

Introduction

This privacy policy applies to the "Javascript Programming Practice" mobile application. This document clarifies our stance regarding any personal information you might supply to us (which is none) when you use this application.

Data Collection and Use

"Javascript Programming Practice" does not collect, store, or share any personal data, information, or usage statistics of its users. The app is designed to be used without requiring any personal information from its users.

No Third-Party Services

This app does not use any third-party services that collect information used to identify you.

Compliance with Laws

The "Javascript Programming Practice" app respects and complies with the relevant legal frameworks concerning data privacy and protection.

Contact Us

If you have any questions or suggestions about our Privacy Policy, do not hesitate to contact us at nakanishi.shu@gmail.com

Changes to Our Privacy Policy

We reserve the right to update or change our Privacy Policy at any time and you should check this Privacy Policy periodically. Your continued use of the service after we post any modifications to the Privacy Policy on this page will constitute your acknowledgment of the modifications and your consent to abide and be bound by the modified Privacy Policy.

Saturday, May 27, 2017

PHP

This post is one of a series

Create an environment for Web development
  1. Vagrant/Virtualbox
  2. Install Apache or Nginx for PHP or Nginx for Python
  3. Install MySQL OR Install MariaDB
  4. Install PHP - You are here  / Install Python

PHP

You can check which is PHP is available from the current repository:
$ sudo yum list php*
I think there are only old versions of php in the list. So we will make newer ones available. Make IUS repository available by the following commands:
$ sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ sudo yum install https://centos7.iuscommunity.org/ius-release.rpm
Then install PHP and useful relevant modules:
$ sudo yum -y install php72u php72u-mysqlnd php72u-gd php72u-mbstring php72u-opcache php72u-xml php72u-pecl-xdebug php72u-pdo php72u-devel php72u-json
When the installation is complete, restart httpd:
$ sudo systemctl restart httpd
Now php7 should be working in your virtual machine. Make a text file in your vagrant share folder and change the name to "info.php":

Open the info.php with Notepad and write as follows:
<php
phpinfo();
?>
Like this.
Then save and close it.
Access to it from a browser. The link should be "http://192.168.33.10/info.php" if you chose private network and didn't change the address:

If the above is shown in your browser, php is working correctly.  :)

FYI commands for CentOS6 

PHP from IUS repository for CentOS6:
$ sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
$ sudo yum install https://centos6.iuscommunity.org/ius-release.rpm
$ sudo yum -y install php72u php72u-mysqlnd php72u-gd php72u-mbstring php72u-opcache php72u-xml php72u-pecl-xdebug php72u-pdo php72u-devel php72u-json
$ sudo service httpd restart

PHP code editor

Choose one from the followings:

What's next

You can try PHP web frameworks.

Develop a python program with PyDev for Eclipse

IDE (integrated development environmen) is essential nowadays to create a program. I will explain how to develop python programs with PyDev in this post.

At first, download and install Ecripse:
http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/marsr




There are some kinds of Eclipse and I think any Eclipse is OK, but I downloaded Eclipse for Java EE developers because I would make web applications.

Install the Eclipse after downloading it, then open Eclipse. Click "Help" from then menu bar and click "install new software". (If you are asked if you will create a workplace, choose yes.)



Add "http://pydev.org/updates" in the "Work with" box and click "Add".


You will see a window like below will pop up. Write "PyDev" in the "Name" box and click OK.



Select "PyDev" and "PyDev Mylyn" then click next.

Then you can install them to Eclipse.


After installing them, click "open perspective" from upper right.


Choose "PyDev" and click OK.


PyDev perspective is shown now.

Click "Window" from the menu and click "Preferences".


"PyDev" --> "Interpreters" --> "Python Interpreter"
Then click "New" and add your python.exe as the interpreter.


Python.exe should be somewhere like here.


Hello World


Enable PyDev window from upper right of Eclipse. Just click the Python mark to enable it:





Make a PyDev project named as "PyDev_test".
File-->New-->PyDev Project


Right click on the project name and choose "New" then "PyDev Module"

Name the module as "test" and click "Finish"


Choose "Module: Main" then "OK"

Change the program code as:
if __name__ == '__main__':
    print("hello world")

Then press CTRL + S. (Or simply save the file from the menu bar). Press the Run button from upper side of Eclipse. You will see "hello world" is displayed on the console.

Sunday, May 14, 2017

Useful regular expressions

Useful regular expressions.
If you intend to use regex for programming, please consider about using xPath (PHPJava)
Depending on situation, you shouldn't use these to precisely match tags.

1.
<div>(?:(?!<div>|<\/div>)[\s\S\n])*?<\/div>
(start from nearest and deepest div)
Or
<div>[\s\S\n]*?<\/div>
(start from leftmost div)

references
https://stackoverflow.com/questions/27938851/regex-select-closest-match


2.
(?<=<div>)(?:(?!<div>|<\/div>)[\s\S\n])*?(?=<\/div>)
(start from nearest and deepest div)
Or
(?<=<div>)[\s\S\n]*?(?=<\/div>)
(start from leftmost div)

This matches only inside between  <div> </div> tags.



3.
<div>(?=(?:(?!<div>|<\/div>)[\s\S\n])*?<\/div>)|(?<=<div>(?:(?!<div>|<\/div>)[\s\S\n])*?)<\/div>
(start from nearest and deepest div)
Or
<div>(?=[\s\S\n]*?<\/div>)|(?<=<div>[\s\S\n]*?)<\/div>
(start from leftmost div)

This matches tags but not the inside between them.
Try it here.

But please note that infinite lookahead can be used for only .NET, Matthew Barnett's regex module for Python and JGSoft. (reference)

Or 
<a[^>]*>|</a>
To match only a tags.

4.
<("[^"]*"|'[^']*'|[^'">])*>

This matches all tags but not the inside between them.


Hello World with Python

Contents

1.  Virtual box and Vagrant

2.  Install Apache

3.  Install MySQL

4.  Install Python

5.  Hello World with Python

Hello World with Python 3.5

We will create a "index.py" file to display "<H1>This is my first CGI script</H1> Hello, world!" in a browser. Create a file named as "index.py" at C:\MyVM\MyCentOs\. (I mean, inside the share folder of Vagrant). Inside index.py, write as follows:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

print("Content-Type: text/html\n\r")
print ("""
    <TITLE>CGI script ! Python</TITLE>
    <H1>This is my first CGI script</H1>
    Hello, world!
""")


Be careful, the line break type must be LF, not CR. Because we are using Linux that uses LF, if the line break type is CR, python doesn't work because it can't recognize the line breaks. 

Now do the following command on the Teraterm:

$ sudo vi /etc/httpd/conf/httpd.conf

To change the text, hit "a" on your keyboard then insert mode will start.
Detailed explanation (if you need it):
Press a on your keyboard to go into insert mode, then you can edit the file. Press escape key to stop the insert mode. After stopping the insert mode, press shift key + g to go to the lowest row. :wq or Shift + zz to save and close the file. You can go to command mode by pressing : on your keyboard. To save and quit by the command mode, input :wq and enter. To exit the file without saving the file, inout :q! and enter. To search a word, press ? then write a word what you want to search. For example, if you write ?aaa and press enter, "aaa" is searched and highlighted in the file. Press n to jump to next match.)
Add "ExecCGI" in the lines of "/var/www/html" as follows:

<Directory "/var/www/html">
    Options Indexes FollowSymlinks ExecCGI
    AllowOverride None
    Require all granted
</Directory>

And add .py to Access handler:
AddHandler cgi-script .cgi .py

Directory

Access handler

By the way, maybe Access handler is a comment at first:

Un-comment the AddHandler line:


Save and close it by ":wq".

Re-start Apache (httpd):

$ sudo systemctl restart httpd

If SELinux is enabled, we need to change the context too. Change it as follows:

$ sudo chcon -R -t httpd_sys_script_exec_t /var/www/html/index.py

Then, access to your index.py from your browser as follows:
http://192.168.33.10/index.py

Hello World!!

If it doesn't work and it shows 500 or 404 errors, do the following command to check the errors:

$ sudo less /var/log/httpd/error_log

You can see errors. Google the errors to deal with them.



Install Python

This post is one of a series

Create an environment for Web development
  1. Vagrant/Virtualbox
  2. Install Apache or Nginx for PHP or Nginx for Python
  3. Install MySQL / Install MariaDB
  4. Install PHP / Install Python - You are here

Install Python3.6

We will install Python 3.6. At first, we will check what is installed and what is not:
$ yum list python* 
Seems like Python 2.7 is installed in Cent OS 7 by default. But there is not Python 3.6 in this list. Seems like Python 3.5 is not installed in this OS by default. Do the following command to make a repository available to install Python 3.6:
$ sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm
This enables the repository of IUS Community Project. To install Python 3.6 from this repository, do this command:
$ sudo yum install -y python36u python36u-libs python36u-devel python36u-pip python-pip
To check if Python 3.6 is successfully installed, do the following command:
$ sudo python3.6 -V 
$ sudo which python3.6
If the version is displayed, it is success.
Re-start your Apache (httpd) after the installation.
$ sudo systemctl restart httpd

FYI commands for CentOS6 

$ sudo yum install -y https://centos6.iuscommunity.org/ius-release.rpm
$ sudo yum install -y python36u python36u-libs python36u-devel python36u-pip python-pip
$ sudo locate python3.6
$ sudo service httpd restart

Versions of Python

But even if you install python 3.x, the python called by "python" command on the console is usually python2.7. You can check it by running this command:
$ python -V
This is because python2.7 is sometimes used by system. Don't change the "python" symlink.
To use python3.6, run commands like this:
$ python3.6 -V
pip for Python2.7:
$ pip
pip for python3.6:
$ pip3.6

Hello World with Python

We will create a "index.py" file to display "<H1>This is my first CGI script</H1> Hello, world!" in a browser. Create a file named as "index.py" at C:\MyVM\MyCentOs. (I mean, inside the share folder of Vagrant). Inside index.py, write as follows:
#!/usr/bin/env python
# -- coding: UTF-8 --

print("Content-Type: text/html\n\r")
print ("""
    <TITLE>CGI script ! Python</TITLE>
    <H1>This is my first CGI script</H1>
    Hello, world!
""")
Please note that the line break type must be LF, not CR/RF. Python doesn't work without linebreaks because of its syntax. Use Visual studio code to see what linebreaks are used in the file.

Now do the following command to change the apache's config file:
$ sudo vi /etc/httpd/conf/httpd.conf
To change the text, hit "a" on your keyboard then insert mode will start.
Press a on your keyboard to be insert mode and you can edit the file. Press escape key to stop the insert mode. After stopping the insert mode, press Shift + g to go to the lowest row. :wq or Shift + zz to save and close the file. You can go to command mode by pressing : on your keyboard. To exit the file without saving the file, inout :q! and enter. To search a word, press ? then write a word what you want to search. For example, if you write ?aaa and press enter, "aaa" is searched and highlighted in the file. Press n to jump to next match.)
Add "ExecCGI" in the lines of "/var/www/html" as follows:

<Directory "/var/www/html">
    Options Indexes FollowSymlinks ExecCGI
    AllowOverride None
    Require all granted
</Directory>

And add .py to Add handler:
AddHandler cgi-script .cgi .py

Directory

Add handler

Add handler is a comment at first:

Un-comment the AddHandler line and add .py:


Save and close it by ":wq".

Re-start Apache (httpd):
$ sudo systemctl restart httpd
If SELinux is enabled, we need to change the context too. Change it as follows:
$ sudo chcon -R -t httpd_sys_script_exec_t /var/www/html/index.py
Then, access to your index.py from your browser as follows:
http://192.168.33.10/index.py
Hello World!!

If it doesn't work and it shows 500 or 404 errors, do the following command to check the errors:
$ sudo less /var/log/httpd/error_log

You can see errors. Google the errors to deal with them.

What's next

Maybe you can try Django, the Python web framework.

Install MySQL

Contents

1.  Virtual box and Vagrant

2.  Install Apache

3.  Install MySQL

4.  Install Python

5.  Hello World with Python


MySQL

We will install MySQL this time. MySQL is a famous software that is used to use database and SQL. MySQL is a free opensource software, so it is used widely in the world.

At first, we need to uninstall MariaDB that is by default installed in the Cent OS 7:

$ sudo yum remove mariadb-libs 
$ sudo rm -rf /var/lib/mysql/

Then your MariaDB is removed. We will install MySQL now.
Go to the link:  https://dev.mysql.com/downloads/repo/yum/
Note the information highlighted by red underline. We are using Cent OS 7 (Linux). Cent OS is a very similar OS to Red Hat Enterprise Linux, so we can use same MySQL as Red Hat Linux. We will download this package for our Cent OS.


But if you are using CentOS 6, you need to use the following:



Do the following commands:
For CentOS 7
$ wget https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm 
$ sudo rpm -ivh mysql57-community-release-el7-10.noarch.rpm 
$ sudo yum install mysql-server

For CentOS6
$ wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
$ sudo rpm -ivh mysql57-community-release-el6-11.noarch.rpm
$ sudo yum install mysql-server


Then MySQL is installed in your virtual machine.

If you made any mistake and want to uninstall the rpm package, run the following to find the exact package name:
$ sudo rpm -qa | grep -i mysql
Then run
$ sudo rpm -e <the exact package name>
to uninstall it.

Start MySQL with this command:
(For CentOS7)
$ sudo systemctl start mysqld

(For CentOS6 or older)
$ sudo service mysqld start

To check the status of MySQL, do this command:
(For CentOS7)
$ sudo systemctl status mysqld

(For CentOS6 or older)
$ sudo service mysqld status

Register mysqld to make it start from the beginning:
(For CentOS7)
$ sudo systemctl enable mysqld

(For CentOS6 or older)
$ sudo chkconfig mysqld on

Now we will set up our MySQL that is needed when we start MySQL for the first time. Do the following command:

$ sudo grep 'temporary password' /var/log/mysqld.log

The text underlined with red is the temporary password

We have a temporary password now. Do the following:

$ sudo mysql_secure_installation

You will be asked password, so use the temporary password that we obtained just now. Every question other than it should be ok to answer yes (y). Maybe you will be asked a new password, but the new password must contain a big letter, a small letter and a special letter like "@" and it must be longer than 8 letters.

Do the following command to log into MySQL with the new password you created just now:

$ mysql -u root -p


But I think 8 letters with a big letter, a small letter and a special letter is not useful if we often login and logout. So we will change the password and the password rule. At first, we will check current password rule:

mysql> SHOW VARIABLES LIKE 'validate_password%';

The condition for password creation

Then do the following commands to change the rule:

mysql> SET GLOBAL validate_password_length=4; 
mysql> SET GLOBAL validate_password_policy=LOW;

Conditions are changed

We will define the password as "root". Do the following command:

mysql> set password for root@localhost=password('root');


Now your password for MySQL is changed to "root". User name is also "root". To quit MySQL, do the following command:

mysql> quit