Tuesday, October 26, 2021

[JavaScript] 深層複製

 https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

[C] continue

#include <stdio.h>


int main()
{
    printf("Start\n");
    
    int max_i = 10;
    int i = 0;
    
    while (i < max_i) {
         i++;
        if ((i/2) == 0) {
            printf("Hello World i:%d\n",i);
            continue;
        } else {
            printf("Hi World i:%d\n",i);
        }
        printf("while end\n");
    }
    return 0;
}
==============================================================

Start
Hello World i:1
Hi World i:2
while end
Hi World i:3
while end
Hi World i:4
while end
Hi World i:5
while end
Hi World i:6
while end
Hi World i:7
while end
Hi World i:8
while end
Hi World i:9
while end
Hi World i:10
while end

Monday, October 25, 2021

[Linux] PS

[root@study ~]# ps aux  <==觀察系統所有的程序資料

[root@study ~]# ps -lA  <==也是能夠觀察所有系統的資料

[root@study ~]# ps axjf <==連同部分程序樹狀態


while true; do
ps -eo pid,ppid,cmd,%mem,%cpu --sort -pcpu,+pmem
ps -eo pid,ppid,%mem,%cpu --sort -pcpu,+pmem | awk '{if ($3!=0){total1 += $3;print "MEM:"$3"%";}} END { print "MEM:"total1"%" }'
ps -eo pid,ppid,%mem,%cpu --sort -pcpu,+pmem | awk '{if ($4!=0){total2 += $4;print "CPU:"$4"%";}} END { print "CPU:"total2"%" }'

sleep 3;
done&

當要刪除 while.... 

先查詢 pid
 PID TTY TIME CMD
15312 pts/84 00:00:00 ps
18095 pts/84 00:00:00 bash

 


kill -9 pid

Reference:

https://linux.cn/article-4743-1.html

https://blog.longwin.com.tw/2017/04/linux-ps-process-show-cpu-memory-2017/


Wednesday, October 20, 2021

[C++程式設計] 字串分割與連線

 

1. 字串分割

#include<string>
#include<iostream>

using namespace std;

vector<string> split(const string& str, const string& delim) 
{
	vector<string> res;
	if ("" == str) return res;
	
	// 先將要切割的字串從string型別轉換為char*型別
	char * strs = new char[str.length() + 1]; //不要忘了
	strcpy(strs, str.c_str());

	char * d = new char[delim.length() + 1];
	strcpy(d, delim.c_str());

	char *p = strtok(strs, d);
	while (p) {
		string s = p; //分割得到的字串轉換為string型別
		res.push_back(s); //存入結果陣列
		p = strtok(NULL, d);
	}
	
	return res;
}

int main()
{
	cout << "=====================================================================" << endl;
	cout << "待分割的字串: " << PATH << endl;

	std::vector<string> res = split(PATH, "/"); // 分割符為“/”
	cout << "字串分割結果:";
	for (int i = 0; i < res.size(); ++i)
	{
		cout << res[i] << " ";
	}
	cout << endl;
	string root = "D:/ClothProject/DataHead/down/down_image/";
	string name_image;
	if (res.size() == 7)
		name_image = res[4] + res[5];
	else
		name_image = res[4];
	cout << "字串連線:" << name_image << endl;
	
	gl.depthImagePath = root;
	for (int i = 1; i < 8; i++)
	{
		if (i == 4)
			continue;
		// 數字與字串連線,需要使用to_string(i)
		imwrite(gl.depthImagePath + name_image + "_" + to_string(i) + ".png", gl.images[i]);
	}
	cout << "=====================================================================" << endl;
	
	return 0;
}


Reference:
https://www.796t.com/article.php?id=184411
https://blog.csdn.net/Mary19920410/article/details/77372828?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1.control

Monday, October 11, 2021

[JavaScript] 分開兩個屬性選擇器

 input[class^='some_starting_constant_string'][class$='some_ending_constant_string']


 console.log( document.querySelectorAll("[class*='start'][class$='end']") ) 

 <div class="start__end"></div> <div class="start_heretoo_end"></div> <div class="sta__end"></div> <div class="rt__end"></div> <div class="start__d"></div> 

Sunday, October 3, 2021

[docker] How to setup personal build environment?

Check images

  docker image list

check your uid/gid

CMD: id johnny

uid=1099(johnny) gid=1099(johnny) groups=1099(johnny),133(docker)

start docker

CMD: docker run -it --name acesetup ace_env:v3 /bin/bash

root@2dac23d862a3:/#

add user

CMD: adduser johnny

finish password setting.

check your uid/gid in docker

CMD: id johnny

uid=1000(johnny) gid=1000(johnny) groups=1000(johnny)

uid/gid is differnet system & docker site. modify in docker container

CMD: usermod -u 1099 johnny

CMD: groupmod -g 1099 johnny

CMD: usermod -aG sudo johnny 

exit docker container, and save the modify. (TAG)

CMD: exit

CMD: docker commit -m "add user johnny" abcsetup ace_env:johnny

check image again

CMD: docker image list

update and commit docker

docker start abcenv_ace

docker attach abcenv_ace

mkdir -p /opt/compiler_tool/selinux-3.1/sbin

ln -s /usr/sbin/setfiles /opt/compiler_tool/selinux-3.1/sbin/setfiles

exit

docker commit -m "ln -s /usr/sbin/setfiles /opt/compiler_tool/selinux-3.1/sbin/setfiles" abcenv_ace_env:ace

docker rm abcenv_ace

docker run --name abcenv_ace--privileged -v /extspace:/extspace -it abc_env:ace /bin/bash

docker start abcenv_ace

docker attach abcenv_ace

remove setup container

docker rm abcsetup


update and commit docker

docker start abcenv_ace

docker attach abcenv_ace

apt install python2

ln -s /usr/bin/python2.7 /usr/bin/python

exit

docker commit -m "ln -s /usr/bin/python2.7 /usr/bin/python" abc_env:johnny

docker rm abcenv_ace

docker run --name abcenv_ace--privileged -v /extspace:/extspace -it abc_env:ace /bin/bash

[docker] Docker image

建立個人專屬的Docker image

  確認系統中,是否有docker image?

  USERNAME@PC:~$ docker images

 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

 android11_en1227         latest              7812c92c2149        2 months ago        7.33GB

查詢自己的UID,因為Docker啟動後,需要存取你在系統的檔案資料,所以需要同步UID

USERNAME@PC:~$ id USERNAME 

uid=1009(USERNAME) gid=1009(USERNAME) groups=1009(USERNAME),133(docker)

啟動Docker容器

docker run -it --name android_build_env android11_en1227:latest /bin/bash

在Docker容器內,新增使用者 (輸入跟本機相同帳號密碼)

root@CONTAINER ID:/#adduser USERNAME

=====================================================

Adding user `USERNAME' ...

Adding new group `USERNAME' (1000) ...

Adding new user `USERNAME' (1000) with group `USERNAME' ...

Creating home directory `/home/USERNAME' ...

Copying files from `/etc/skel' ...

Enter new UNIX password: YOUER PASSWORD

Retype new UNIX password: YOUER PASSWORD

passwd: password updated successfully

Changing the user information for hunglin

Enter the new value, or press ENTER for the default

        Full Name []: USERNAME

        Room Number []: 

        Work Phone []: 

        Home Phone []: 

        Other []: 

Is the information correct? [Y/n] Y

查詢UID,如果與本機不同,請接續下面command修改

id USERNAME Ex. uid=1001(USERNAME) gid=1001(USERNAME) groups=1000(USERNAME),121(docker)

修改UID/GID,與本機相同

usermod -u 1019 USERNAME 

groupmod -g 1019 USERNAME

修改完成後,再透過id command確認,確認後,執行exit離開docker

儲存該階段docker容器

>>> 取得docker容器ID <<<

USERNAME@TPVPC:~$ docker ps -a

CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS                   PORTS               NAMES

7812c92c2149  android11_en1227:latest   "/bin/bash"         20 hours ago        Exited (0) 22 hours ago                       android_build_env


>>> 將這個docker打一個新的tag <<<

USERNAME@PC:~$ docker commit -m "commit message” CONTAINER_ID IMAGE:new_tag


ex. docker commit -m "add USERNAME" 7812c92c2149 android11_en1227:USERNAME

儲存後,將剛剛的docker容器停掉並卸載

停止容器

docker stop [nick_name or id]

ex. docker stop t32_build_env


卸載容器

docker rm [nick_name or id]

ex. docker rm t32_build_env

[docker] How to create docker image

1. 下載一個 ubuntu 18.04

  docker pull ubuntu:18.04

2. 進入docker

  docker run --name yoctoseed -it ubuntu:18.04 /bin/bash

3. 安裝關套件

過程中,會請你選擇一個區域(不確定有沒有什麼影響),選擇Asia,然後選 Taipei。

  wget -O gn http://storage.googleapis.com/chromium-gn/3fd43e5e0dcc674f0a0c004ec290d04bb2e1c60e 

  chmod 777 gn

  mv gn /usr/bin/gn

4. 補充

  apt-get install locales

  dpkg-reconfigure locales

請選擇158. en_US.UTF-8 UTF-8 ,然後選擇 3. en_US.UTF-8

  update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8

完成後,將history清除即可退出docker

  history -c

  exit

5. 將容器轉出來

  docker export yoctoseed > mt7663_yocto.tar

6. 移植到其他主機

  cat mt7663_yocto.tar |docker import - mt7663_yocto


docker command

docker run \

-u johnny \

-v /usr/bin/hexdump:/usr/bin/hexdump:ro \

-v /etc/localtime:/etc/localtime:ro \

-v /mtk_proj/ref_mtkoss:/mtkoss \

-v /home/johnny:/home/johnny \

--name android_build \

-it android001:johnny /bin/bash

Colaboratory

 Colaboratory (簡稱為「Colab」) 可讓你在瀏覽器上撰寫及執行 Python,且具備下列優點:

  • 不必進行任何設定
  • 免費使用 GPU
  • 輕鬆共用

n8n index

 【n8n免費本地端部署】Windows版|程式安裝x指令大補帖  【一鍵安裝 n8n】圖文教學,獲得無限額度自動化工具&限時免費升級企業版功能