Skip to main content

Posts

How to start python script by batch file on window

How to start python script by batch file on window Reference https://datatofish.com/batch-python-script/ Assumption - Your python script is manage.py - Create a batch file "run.bat" which is placed in the same directory with your python script. run.bat source code :: find python.exe path @ for %%i in (python.exe) do @ set py = %%~$PATH:i ::run main program %py% %CD% \manage.py ::wait for stop pause manage.py source code print ( "Surprisingly, The naughty kitten defeated a giant python" ) Looking more sample batch file https://www.robvanderwoude.com/batexamples.php

Develop the first python client test application by Paho mqtt

Develop the first python client application by Paho I. Purpose: 1. Try to send messages between 2 clients via MQTT protocol. Then, we will create 2 clients: - One for publishing (or send) the message. Other for subscribing (or receive message). II. Pre-condition: - You already installed Mosquitto broker, Python. III. Step by step 1. Download example from Github https://github.com/eclipse/paho.mqtt.python 2. Modify subscriber(client) source In folder example/client_sub.py. Modify some pieces of source code. before mqttc.connect("mqtt.eclipse.org", 1883, 60) mqttc.subscribe("$SYS/#", 0) after mqttc.connect("192.168.203.76", 1883, 60) mqttc.subscribe("test/topic1", 0) note: "192.168.203.76": IP address of machine which Mosquito broker installed on. 1883: mqtt port 3. Modify publisher(client) source In folder example/publish_single.py. before: publish.single("paho/test/sing...

How to test Mosquitto broker on Windows machine

Install Mosquito broker https://mosquitto.org/download/ 1. Install service easily by some click. 2. Check operation Reference: http://www.steves-internet-guide.com/install-mosquitto-broker/ - open command prompt and check installed directory cd C:\Program Files\mosquitto mosquitto -h or mosquitto -v - start service mosquitto -p 1883 - check port 1883 is listening or not netstat -a - add system environment variables. Add below string to the system environment path. It helps you call mosquito in the command line window. ;C:\Program Files\mosquitto Example Reference: https://www.win.tue.nl/~lrahman/iot_2016/tutorial/MQTT_2016.pdf 1. Open the first command windows 2. Start mosquitto by command mosquitto -p 1883 3. Open the second command windows 4. Allow client subcribe the topic by command mosquitto_sub -t 'test/topic' -v This time, a client has the ability to handle the message from publisher. 5. Open the third command windows 6. Publish message...

[Bài dịch] Độ phủ của test case bao nhiêu là đủ? Code Coverage ?

Trên một ngôi chùa nhỏ tên là Toàn Âm Tự trên núi Lỗ Tề (Lotte Tower) Dự án kiểm thử phần mềm đếm số hạt bụi mịn 2.5pm ở kinh đô Hà Nộ đang bắt đầu triển khai phase Unit test. Sáng sớm, một hòa thượng mới nhập chùa một năm hỏi đại sư Thích Đề Mô - trưởng dự án.  Thưa đại sư, con sẵn sàng chạy Unit test cho chức năng đo bụi mịn, vậy chẳng hay đại sư muốn tỷ lệ phủ (code coverage) là bao nhiêu? Đại sư nhìn chú với ánh mắt hiền từ và nói: "Con ah, đừng lo lắng quá về tỷ lệ phủ, con hãy cố gắng viết thật nhiều những test case tốt." Chú vâng lời, cúi chào và rời đi. Ánh nắng cuối thu len lói qua những màn sương lờ mờ chiếu rọi khắp sân chùa. Mặt trời đã lên quá ngọn tre đằng ngà. Một hòa thượng khác đến hỏi câu hỏi tương tự cho chức năng hiển thị trên mobile app. Đại sư từ tốn chỉ vào nối nước đang sôi dưới bếp và hỏi: "Con hãy cho ta biết, ta nên cho bao nhiêu gạo vào nồi nước đang sôi kia?" Chú hòa thượng lúng túng đáp: "Thưa đại s...

[OpenCV] Simple example C++ and ubuntu

Prerequisite: Opencv is already installed. Source code: //include high gui headers #include "opencv2/highgui/highgui.hpp" //we are using standard and OpenCV namespaces using namespace cv; using namespace std; int main( int argc, const char** argv ){ //create a window named theWindow namedWindow("theWindow", CV_WINDOW_AUTOSIZE); //wait user hit some key waitKey(0); //destroy window named theWindow destroyWindow("theWindow"); return 0; } Build command: g++ -o firstcv $(pkg-config --libs --cflags opencv) main.cpp if error happened. /tmp/cceyijPd.o: In function `main': main.cpp:(.text+0x3d): undefined reference to `cv::namedWindow(cv::String const&, int)' main.cpp:(.text+0x53): undefined reference to `cv::waitKey(int)' main.cpp:(.text+0x70): undefined reference to `cv::destroyWindow(cv::String const&)' /tmp/cceyijPd.o: In function `cv::String::String(char const*...

[Rust] How to install Rust on ubuntu

This is fast food, No more detailed explanation. Open your terminal. Just type and type a dozen of commands as below: //download curl software sudo apt-get install curl //using curl to download rust curl https://sh.rustup.rs -sSf | sh //type 1 to install Rust by default //after install completely, set PATH environment source ~/.profile source ~/.cargo/env //Check version rustc --version //Write the first program //Create directory mkdir  rs_dir cd rs_dir //Open vi editor to write source code vi first_proc.rs //Copy and paste below code in vi editor fn main()  {      println!("Hello World again!");  } //Save source code by vi manipulators with a keyboard. press "i" press "shift+insert" press ":" type wq enter //compile source code rustc first_proc.rs //run first program ./first_proc.rs More detail, please check out below references: https://www.rust-lang.org/tools/install https://www.tecmint.com/install-r...

[Linux][SSH] Sự khác nhau giữa authorized_keys và known_hosts file trong thư mục ~/.ssh

2 file này xuất hiện khi máy ubuntu của bạn vừa là server vừa là client known_hosts Khi máy của bạn là client, known_hosts sẽ lưu lại public key của những server(host) bạn đã truy cập trước đó. authorized_keys Khi máy của bạn là server, authorized_keys lưu lại public key của những client đã kết nối đến máy của bạn trước đó. Các câu hỏi khác liên quan: 1. Làm thế nào để cấu hình ssh server? 2. Làm thế nào để share public key từ client cho server? 3. Có mấy kiểu giải mã, mã hóa dữ liệu khi sử dụng ssh? 4. Làm thế nào để tạo ra cặp mã hóa private and public? 5. Cơ chế sử dụng key? References: https://security.stackexchange.com/questions/20706/what-is-the-difference-between-authorized-keys-and-known-hosts-file-for-ssh