วันพุธที่ 8 พฤษภาคม พ.ศ. 2567

Python 3.12.3 รองรับ MediaPipe แล้ว

ก่อนหน้านี้ถ้าติดตั้ง mediapipe บน Python 3.12.2 จะพบปัญหาว่าไม่สามารถติดตั้งได้ พอไป Search Google ดู จะได้คำตอบว่า Python 3.12 ไม่รองรับการใช้งานร่วมกับ mediapipe ให้ไปใช้ Python 3.7 ถึง 3.10 แทน ทำให้ต้องติดตั้ง Python 3.10.10 เพิ่มเข้าไปเป็น Python สองเวอร์ชันอยู่ในเครื่อง และต้องมา Switch เลือกเวอร์ชันของ Python เพื่อใช้งานอีก





แต่ปัจจุบันปัญหานี้ได้หมดไปแล้วด้วยการมาเยือนของ Python 3.12.3 ที่พึ่ง Release เมื่อวันที่ 9 เมษายน 2024 ที่ผ่านมา ทำให้เราสามารถติดตั้ง mediapipe บน Python 3.12 ได้

วันอังคารที่ 7 พฤษภาคม พ.ศ. 2567

ทำไมขนาด Drive ใน Windows ถึงมีขนาดเล็กกว่า Drive จริง



จริงๆ แล้วมันไม่ได้ขนาดเล็กกว่า มันเป็นที่การแสดงผลของ Windows ต่างหาก เช่น Drive ขนาด 500 GB ถ้าดูใน Properties ค่า Capacity ในหน่วย byte มีค่า 499,427,872,768 bytes ซึ่งอันนี้ถูกต้อง จากนั้นเราก็คาดหวังมาว่ามันจะโชว์ 500 GB ใน This PC ของ Windows แต่มันกลับโชว์ 465 GB ซะงั้น!!!

เพราะว่า Windows ไม่ได้เอาค่า byte มาหารด้วย 1,000,000,000 เพื่อคำนวณเป็นหน่วย GB แบบตรงไปตรงมา มันจะเอาค่า byte มาหารด้วย 1,024 จะได้ 500,000,000,000 bytes / 1,024 = 488,281,250 KB ค่า 1,024 นี้คือ 2 ยกกำลัง 10 เพราะคอมพิวเตอร์ทำงานด้วยระบบเลขฐานสอง

จากนั้นจะเอา 488,281,250 KB / 1,024 = 476,837 MB แล้วก็เอา 476,837 MB / 1,024 = 465 GB ก็จะได้ค่า Capacity ที่ Windows แสดงผลออกมานั่นเอง

ทดสอบความเร็วในการอ่าน/เขียน SSD ด้วยซอฟต์แวร์ CrystalDiskMark 8 ภาค #2

หลังจากได้ WD Blue SN580 M.2 SSD มาใหม่ จึงทำการทดสอบเทียบกัน

ผลการทดสอบมีดังต่อไปนี้

1) WD SATA SSD 2 TB (NTFS)


2) Toshiba M.2 NVMe PCIe 3.0 SSD 512 GB (NTFS)


3) WD SN580 M.2 NVMe PCIe 4.0 SSD 500 GB (NTFS)


จะเห็นได้ว่า WD Blue SN580 ซึ่งเป็น PCIe 4.0 มี Speed ทั้ง Read และ Write สูงกว่า Toshiba ซึ่งเป็น PCIe 3.0 อย่างเห็นได้ชัดทั้ง Sequential และ Random R/W อีกจุดสังเกตหนึ่งคือ WD SSD จะมี Speed R/W ที่สมดุลกันทั้ง SSD ที่เป็นแบบ SATA และแบบ NVMe ซึ่งต่างจาก Toshiba SSD ที่มี Writing Speed ต่ำกว่า Reading Speed อยู่หลายเท่า

วันศุกร์ที่ 12 เมษายน พ.ศ. 2567

แข่งหมากรุกไทยครั้งแรก

    ในกระดานที่ 7 กระดานสุดท้ายของการแข่งขัน หมากฝ่ายขาวกำลังได้เปรียบ แต่ในแต้มนี้หมากขาวเดินม้า C3 ไป B5 ทำให้จากรูปเกมที่ได้เปรียบ กลายเป็นเสียเปรียบ เพราะหมากดำสามารถกินเบี้ยข้างขุนฟรีเพราะกินสอง แล้วม้าก็ไปชิดขุนฝ่ายดำ แถมบังตาเรืออีก ตาที่ควรเดินจริงๆ คือเดินม้า E5 มา D3


วันอังคารที่ 10 ตุลาคม พ.ศ. 2566

เชื่อมต่อ Web Application ผ่าน Websocket กับ MQTT Broker ด้วย Paho MQTT

  • เพิ่ม Script ใน tag <header> จาก CDNJS
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.1.0/paho-mqtt.min.js"></script>
  • สร้าง Client Instance ของ Paho MQTT ด้วยคำสั่ง
let client = new Paho.Client("<broker-url>", Number(<port>), "<client-id>");
  • สร้างฟังก์ชั่น onConnect ทำการเชื่อมต่อและ subscribe ไปยัง topic ด้วยคำสั่ง
                       const onConnect = () => {
                               console.log("Connected");
                               console.log("Subscribing to topic: <topic-name>");
                               client.subscribe("<topic-name>");
                       }
  • สร้างฟังก์ชั่น onConnectionLost เพื่อแสดงสถานะหากถูกตัดการเชื่อมต่อ
                       const onConnectionLost = responseObject => {
                              if(responseObject !== 0){
                                      console.log("ConnectionLost:"+responseObject.errorMessage);
                              }
                       }
  • สร้างฟังก์ชั่น onMessageArrived เพื่อแสดงข้อความที่ได้รับ
                        const onMessageArrived = message => {
                                console.log("MessageArrived: " + message.payloadString);
                               }
                        }
  • เรียกใช้ฟังก์ชัน connect, onConnect, onConnectionLost และ onMessageArrived
                        client.connect({
                                onSuccess: onConnect
                        }
                        client.onConnectionLost = onConnectionLost;
                        client.onMessageArrived = onMessageArrived;


วันเสาร์ที่ 30 กันยายน พ.ศ. 2566

Git Command

  • เริ่มต้นสร้าง Git repository หรือสร้างโฟลเดอร์ .git (hidden folder) ด้วยคำสั่ง
  • git init

  • เพิ่มไฟล์เข้าไปใน staging area ด้วยคำสั่ง
git add <file name> หรือ git add . เพื่อ add ไฟล์ทั้งหมด
  • Commit ไฟล์ไปยัง local repository ด้วยคำสั่ง
git commit -m "<commit-message>"
  • ตรวจสอบ remote repositoty ด้วยคำสั่ง
git remote -v
  • Add remote repositoty ด้วยคำสั่ง
git remote add <remote-name> <remote-url>
  • เปลี่ยน remote url ด้วยคำสั่ง
git remote set-url <remote-name> <new-remote-url>
  • ลบ remote reposity ด้วยคำสั่ง
git remote rm <remote-name>
  • ตรวจสอบ branch ปัจจุบันด้วยคำสั่ง
git branch
  • ตรวจสอบ branch ทั้งหมดด้วยคำสั่ง
git branch -a
  • เปลี่ยนชื่อ branch ปัจจุบันด้วยคำสั่ง
git branch -M <new-branch-name>
  • สร้าง branch ใหม่ด้วยคำสั่ง
git branch <new-branch-name>
  • เปลี่ยน branch ปัจจุบันด้วยคำสั่ง
git checkout <branch-name>
  • ลบ local branch ด้วยคำสั่ง
git branch -d <branch-name>
  • ลบ remote branch ด้วยคำสั่ง
git push <remote-name> --delete <branch-name>
  • Push local reposity ไปยัง remote reposity ด้วยคำสั่ง
git push -u <remote-name> <branch-name>
  • Clone remote repository ไปยัง local reposity ด้วยคำสั่ง
git clone <remote-url>
  • ดึงการอัพเดทล่าสุดจาก remote repository ด้วยคำสั่ง 
git pull

วันอังคารที่ 22 สิงหาคม พ.ศ. 2566

Deploy React App บน GitHub Page

 


  • ติดตั้ง gh-pages npm package ด้วยคำสั่ง
npm install gh-pages

  • เพิ่ม homepage property ในไฟล์ package.json
"homepage": "https://<username>.github.io/<repository-name>"
  • เพิ่ม predeploy และ deploy ใน script ของไฟล์ package.json
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
  • Add remote repository ด้วยคำสั่ง
git remote add origin https://github.com/<username>/<repository-name>.git
  • Push React app ด้วยคำสั่ง
npm run deploy
หรือ
npm run deploy -- -m "<commit-message>"

npm จะทำการ build ไฟล์เก็บไว้ในโฟลเดอร์ build
แล้ว deploy ขึ้นไปที่ gh-pages branch
  • หากต้องการเก็บ React app source code ไว้บน GitHub สามารถใช้คำสั่ง
git add .
git commit -m "<commit-message>"
git push origin main

React app source code จะถูกเก็บใน main branch
build file จะถูกเก็บใน gh-pages branch