กรองเอาเฉพาะตัวเลข (digit) จาก string

ใช้ regular expression

using System;
using System.Text.RegularExpressions;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string ipString = "(66)123-456-7890 เบอร์มือถือ ";
                string opString = null;
                Console.WriteLine(ipString);

                Regex regex = new Regex(@"[^\d]");
                opString = regex.Replace(ipString, "");
                Console.WriteLine(opString);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

จะได้

(66)123-456-7890 เบอร์มือถือ
661234567890

การใช้งาน Line Notify

1.เพิ่มเป็นเพื่อนกับ Line Notify

ไปที่ Home แล้วเลือก Official accounts จากนั้นค้นหา Line Notify

2. สร้าง Token

ไปที่ https://notify-bot.line.me/th/ แล้วลงชื่อเข้าใช้งานด้วย account line

เลือกเมนู My Page ด้านขวาบนตรงชื่อ account ของเรา

เลือก Generate access token (For developers) จากนั้นตั้งชื่อ และเลือกว่าจะส่งให้ใคร

3.ส่งด้วย Postman

ส่งแบบ POSTโดยมี url เป็น https://notify-api.line.me/api/notify

ที่ Authorization เลือกเป็น Bearer แล้วใส่ Token ที่ Generate ได้

ที่ Body เลือก x-www-form-urlencoded

ใส่ Key เป็น message และใส่ Value เป็นข้อความที่ต้องการส่ง

พอส่งมาก็จะได้ประมาณนี้

ติดตั้ง phpMyAdmin ให้ Nginx บน Ubuntu 18.04

1.Installing phpMyAdmin

$ sudo apt update
$ sudo apt install phpmyadmin

During the installation process, you will be prompted to choose the web server (either Apache or Lighttpd) to configure. Because we are using Nginx as a web server, we shouldn’t make a choice here. Press tab and then OK to advance to the next step.

Next, you’ll be prompted whether to use dbconfig-common for configuring the application database. Select Yes. This will set up the internal database and administrative user for phpMyAdmin. You will be asked to define a new password for the phpmyadmin MySQL user. You can also leave it blank and let phpMyAdmin randomly create a password.

ถ้าจะ recofig ก็

sudo dpkg-reconfigure phpmyadmin

สร้าง link

$ sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
https://server_domain_or_IP/phpmyadmin

แต่น่าจะติด 403 Forbidden

ให้ เพิ่ม index.php ในไฟล์ /etc/nginx/sites-available/example.com

$ sudo nano /etc/nginx/sites-available/example.com
server {
        listen 80;
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html index.php;
        server_name example.com;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}

ทีนี้จะเข้าได้ละ

ติดตั้ง MySql บน Ubuntu 18.04

1.Installing MySQL

sudo apt update
sudo apt install mysql-server

2.Configuring MySQL

sudo mysql_secure_installation

In order to use a password to connect to MySQL as root, you will need to switch its authentication method from auth_socket to mysql_native_password. To do this, open up the MySQL prompt from your terminal:

sudo mysql

Next, check which authentication method each of your MySQL user accounts use with the following command:

SELECT user,authentication_string,plugin,host FROM mysql.user;
Output
+------------------+-------------------------------------------+-----------------------+-----------+
| user             | authentication_string                     | plugin                | host      |
+------------------+-------------------------------------------+-----------------------+-----------+
| root             |                                           | auth_socket           | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.00 sec)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;

Check the authentication methods employed by each of your users again to confirm that root no longer authenticates using the auth_socket plugin:

SELECT user,authentication_string,plugin,host FROM mysql.user;
Output
+------------------+-------------------------------------------+-----------------------+-----------+
| user             | authentication_string                     | plugin                | host      |
+------------------+-------------------------------------------+-----------------------+-----------+
| root             | *3636DACC8616D997782ADD0839F92C1571D6D78F | mysql_native_password | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.00 sec)

ทีนี้ก็จะ login ด้วย $ mysql -u root -p ได้ละ

3.Adjusting User Authentication and Privileges

$ mysql -u root -p
mysql> GRANT ALL ON *.* TO 'sammy'@'localhost' IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;

4.Testing MySQL

$ systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-02-06 15:32:25 +07; 17min ago
 Main PID: 3831 (mysqld)
    Tasks: 28 (limit: 4915)
   CGroup: /system.slice/mysql.service
           └─3831 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

ถ้า mysql ไม่ start ให้ start ด้วย

$ sudo systemctl start mysql 

ดูเวอร์ชันของ mysqladmin

$ sudo mysqladmin -p -u root version
Enter password: 
mysqladmin  Ver 8.42 Distrib 5.7.29, for Linux on x86_64
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version		5.7.29-0ubuntu0.18.04.1
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/var/run/mysqld/mysqld.sock
Uptime:			18 min 31 sec

Threads: 1  Questions: 21  Slow queries: 0  Opens: 113  Flush tables: 1  Open tables: 106  Queries per second avg: 0.018

5.ติดตั้ง Workbench

sudo apt install mysql-workbench

ติดตั้ง Nginx บน Ubuntu 18.04

1.Installing Nginx

$ sudo apt update
$ sudo apt install nginx

2.Adjusting the Firewall

$ sudo ufw app list
Available applications:
  CUPS
  Nginx Full
  Nginx HTTP
  Nginx HTTPS
  • Nginx Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
  • Nginx HTTP: This profile opens only port 80 (normal, unencrypted web traffic)
  • Nginx HTTPS: This profile opens only port 443 (TLS/SSL encrypted traffic)
$ sudo ufw allow 'Nginx Full'
$ sudo ufw allow 'Nginx HTTP'
$ sudo ufw status
Status: inactive
$ sudo ufw enable
$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
Nginx Full                 ALLOW       Anywhere
Nginx HTTP                 ALLOW       Anywhere
Nginx Full (v6)            ALLOW       Anywhere (v6)
Nginx HTTP (v6)            ALLOW       Anywhere (v6)

เปิดพอร์ทแบบกำหนดไปเลย

$ sudo ufw allow 22/tcp
$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp

3.Checking your Web Server

$ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-02-06 14:26:15 +07; 33min ago
     Docs: man:nginx(8)
 Main PID: 5720 (nginx)
    Tasks: 5 (limit: 4915)
   CGroup: /system.slice/nginx.service
           ├─5720 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           ├─5721 nginx: worker process
           ├─5722 nginx: worker process
           ├─5723 nginx: worker process
           └─5724 nginx: worker process

ติดตั้ง Visual Studio Code บน Ubuntu 18.04

ติดตั้งด้วย Snap

sudo snap install --classic code

Once installed, the Snap daemon will take care of automatically updating VS Code in the background. You will get an in-product update notification whenever a new update is available.

เรียกใช้ vscode

code .
code . &

ดูต่อที่ Visual Studio Code | Phaisarn.com