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

n8n index

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