Author Archives: admin

Reset MySQL root password on Windows

Steps

  1. Open command line with administrator permission
  2. Stop mysql service (2 ways)
    1. net stop mysql
    2. administrator tools -> services
  3. Create a mysql_init.txt file with this command line:
    ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘new password’;
  4. cd C:\Program Files\MariaDB 10.3\bin
  5. mysqld –init-file=C:\\mysql-init.txt
  6. Done, password of root has been reset

Reference:

  1. https://dev.mysql.com/doc/mysql-windows-excerpt/5.7/en/resetting-permissions-windows.html
  2. https://dev.to/oneearedmusic/access-denied-reset-mysql-root-user-password-2hk4

Model Trait for Laravel

Trait

Usage

 

Socket in PHP

Server:

Client:

Commands:

php server.php
php client.php

Reference:

  1. https://www.php.net/manual/en/function.socket-read.php
  2. https://xyz.cinc.biz/2016/12/php-socket-client.html
  3. socket_create() not found
    https://blog.johnsonlu.org/freebsdinstall-php-sockets-so/

Line break in PHP \r\n

If you want to print special characters like \r\n, you must use double quote, single quotes won’t work.

 

Reference:

  1. https://php.net/manual/en/language.types.string.php
  2. https://stackoverflow.com/questions/7890217/making-a-new-line-with-single-quotes

條件格式化整列格式 – Excel / Google試算表

目的:

根據某一欄位的值,改變整列的背景顏色

範例:

  1. A2:L42
    範圍要選擇整個資料表,而不是只有一列A2:L2
  2. =$L2=”V”
    1. 開頭要是=
    2. $L2前面要加上$(絕對位置)
    3. “V” 字串前後要加上雙影號

Reference:

  1. https://isvincent.pixnet.net/blog/post/37181644-excel-%E8%BC%B8%E5%85%A5%E8%B3%87%E6%96%99%E5%BE%8C%E6%95%B4%E5%88%97%E8%AE%8A%E8%89%B2
  2. https://support.google.com/docs/answer/78413?co=GENIE.Platform%3DDesktop&hl=zh-Hant

Advanced Regular Expression

String:

Ventilator Set:\n FiO2 ≤ 40%\nDrug use:\n NO\nWeaning trials:\n NO\nStop reason:\n neurologic factors\n備註:\n

Purpose

Find the second \n and replace it with another character

Solution

https://regex101.com/r/t9gozM/1

Pattern Explanation: 在\n後面找一個最近的\n或是結尾之間的字串

Notes:

  • (?:)
    括號裡面的內容不產生指標($1之類的)
  • ^
    一行的開始
  • $
    一行的結束
  • (?=p)
    正前向聲明,要求接下來的字元都與樣式p相符,但是不包括比對中的那些字元
  • (?!p)
    反前向聲明,要求接下來的字元不與樣式p相符
  • 重複字元(如*)後加上? – 非貪婪的重複比對
    /a+/
    /a+?/ -> 只符合一個以上的字母a

Image Library – intervention/image

Official Site:

http://image.intervention.io/getting_started/installation

Resize and Crop Example: