23 March 2025
I've been told to avoid linked lists because their elements are scattered everywhere, which can be true in some cases. However, I wonder what happens in loops, which I use frequently. I tried to inspect memory addresses of list elements of these two programs run on SBCL.
CL-USER> (setq *a-list* (let ((a nil)) (push 10 a) (push 20 a) (push 30 a) a))
(30 20 10)
CL-USER> (sb-kernel:get-lisp-obj-address *a-list*)
69517814583 (37 bits, #x102F95AB37)
CL-USER> (sb-kernel:get-lisp-obj-address (cdr *a-list*))
69517814567 (37 bits, #x102F95AB27)
CL-USER> (sb-kernel:get-lisp-obj-address (cddr *a-list*))
69517814551 (37 bits, #x102F95AB17)
CL-USER> (sb-kernel:get-lisp-obj-address (cddr *a-list*))
69517814551 (37 bits, #x102F95AB17)
CL-USER> (setq *a-list* (let ((a nil))
(push 10 a)
(push 20 a)
(push 30 a)
a))
(30 20 10)
CL-USER> (sb-kernel:get-lisp-obj-address *a-list*)
69518319943 (37 bits, #x102F9D6147)
CL-USER> (sb-kernel:get-lisp-obj-address (cdr *a-list*))
69518319927 (37 bits, #x102F9D6137)
CL-USER> (sb-kernel:get-lisp-obj-address (cddr *a-list*))
69518319911 (37 bits, #x102F9D6127)
In both programs, the list elements are not scattered. So, if scattered list elements were an issue for these simple cases, you probably used the wrong compiler or memory allocator.
โดย Vee Satayamas ณ 23 March 2025 08:18 +0000
18 March 2025
The wait is over. Here we go .. https://www.gimp.org/news/2025/03/16/gimp-3-0-released/ We may need to update the scripts, though.
โดย kitty ณ 18 March 2025 01:56 +0000
1 February 2025
เรื่องสมมติที่เกิดขึ้นจริง ในฝั่ง cybersecurity เราเริ่มใช้ AI ในการป้องกันมาพักนึงแล้ว และพบการโจมตีมากขึ้นเรื่อย ๆ รวมถึงเห็นภัยคุกคามใหม่ ๆ ที่เชื่อมโยงกับ AI ด้วยเหมือนกันในทางบวก ฝั่งป้องกัน เราใช้ AI ช่วยในการ summarize logs เชื่อมโยง security events เพื่อ discovery การโจมตี discover สิ่งที่ rule-based ทำไม่ได้ หรือ overload มนุษย์มาก ๆ ในทางลบ เราเห็น web crawlers / spiders ฝั่ง AI วิ่งเก็บข้อมูลหน้าเว็บหนักกว่าเดิม 5 – 10 เท่าจากปกติ ซึ่งมันกิน resources เด้อจ้า .. ทั้ง CPU, mem, egress ที่ต้องประมวลผลตอบสนอบขึ้นหมดเลย … Continue reading LLM Safety →
โดย kitty ณ 1 February 2025 08:48 +0000
29 January 2025
ลองเอา deepseek-r1:1.5b ตัวเล็กสุด มารันใน notebook ตัวเอง มันเก่งจริงอย่างที่หลายคนอวยยศแฮะ response เร็ว กิน resource น้อย (อจก. ตามไปอ่าน architecture ของ deepseek แล้ว ในทางวิศวกรรม #ของแทร่ อยู่เด้อ) ประเด็นคือออ .. model ขนาด 1-2b parameters หลาย ๆ models นี่ คอมพิวเตอร์ทั่ว ๆ ไป มี memory เหลือสัก 1.5-2 GB ก็รันได้แล้วนะครับ ไม่ต้องมี GPU/NPU ช่วย accelerate ก็รันได้ (เครื่อง อจก. ก็ไม่มี GPU/NPU) ยิ่งถ้ามี AI-accelerated (e.g., CPU+NPU, Copilot+ PC) ที่กำลังทยอยออกมาวางขายผู้ใช้งานทั่วไป การรัน … Continue reading DeepSeek-R1 →
โดย kitty ณ 29 January 2025 01:39 +0000
26 January 2025
“NO leap second will be introduced at the end of June 2025. The difference between Coordinated Universal Time UTC and the International Atomic Time TAI is : from 2017 January 1, 0h UTC, until further notice : UTC-TAI = -37 s” — IERS EOP Bulletin C#69
โดย kitty ณ 26 January 2025 14:12 +0000
มาแล้วก็ใช้สิครับ AWS Asia Pacific (Thailand) Region .. \(^^)/ ref. https://aws.amazon.com/local/thailand/
โดย kitty ณ 26 January 2025 14:07 +0000
หัวทีม debian mirror แจ้งข่าวเข้า mailling list แต่เช้าว่า “สูเจ้าจงอัปเกรด rsync ASAP” ต้นเรื่องคือ 3.3 >= rsync >= 3.2.7 มี heap overflow และอื่น ๆ lot นี้ พบ และ fix ไปแล้ว ~ 6 CVEs ครับ main distros release fixes แล้วเมื่อไม่กี่ชั่วโมงที่ผ่านมา
โดย kitty ณ 26 January 2025 14:05 +0000
ออกจากดาวหมา มาอยู่บ้านนี้สิบหกปี..วันนี้ลุงหมูแฮมได้กลับดาวละน้าาาาา
โดย kitty ณ 26 January 2025 14:03 +0000
10:00 31 ธ.ค. 2024 หลังจากที่ได้ instant ใหม่ OS เดิม (Ubuntu 16.04) เป็นเครื่องเปล่า ๆ ที่ไม่มีข้อมูล สิ่งแรกที่พยายามทำคือกู้จาก snapshot เดียวที่มีอยู่ ทำให้ได้ kitty.in.th ที่มีข้อมูลถึงประมาณต้นเดือนมีนาคม 2017 manually install All-in-One WP migration ทำ site backup ได้ไฟล์ขนาด 2 GB ซึ่งใหญ่เกิน จะ recovery ได้ฟรี แต่ก็ยังดีกว่าไม่มีอะไรเลย หลังจาก มี backup .wpress แล้ว dump mysql, tar gz web root เก็บ ย้ายมาเก็บที่ notebook อีกหนึ่งสำเนา พร้อมล้างเครื่องแล้ว .. กด … Continue reading คืนชีพ skuld.kitty.in.th →
โดย kitty ณ 26 January 2025 14:00 +0000
รหัสผ่านไม่จำเป็นต้องมีสัญลักษณ์ผสมก็ได้ มันทำให้จำยาก พิมพ์ผิดง่าย และไม่ได้ช่วยให้ปลอดภัยอย่างที่เคยคิด แต่จะต้องตั้งรหัสผ่านให้ยาว ๆ (ต่ำสุด ๆ คือ 12 ตัวอักษร แนะนำว่า 15 ขึ้นไป) รหัสผ่านตั้งยาว ๆ ได้ ก็จะใช้ยาว ๆ ได้เลย ไม่จำเป็นต้องเปลี่ยนทุก 90 วันเหมือนที่เคยแนะนำกันอีกแล้ว จะใช้นานเท่าไหร่ก็ไม่ว่า จะบังคับเปลี่ยนก็ต่อเมื่อมีหลักฐานเพียงพอว่ารหัสผ่านรั่วไหล อย่าใช้รหัสผ่านเดียวกันหลายเว็บ/แอป มันมีความเสี่ยงที่เว็บ/แอป ทำรหัสผ่านเรารั่วไหล แล้วเอารหัสผ่านนั้นไป login เว็บอื่น ๆ ต่อ สำหรับคนที่กลัวจำรหัสผ่านยาว ๆ ไม่ได้ เรามีเทคโนโลยี password manager ช่วยตั้งและจำรหัสผ่านแทนได้นะครับ จะใช้ Google Chrome, Apple Password ไปเลยก็ได้ หรือจะใช้ LastPass, Dashlane, Bitwarden, 1Password ก็ได้ เดี๋ยวนี้ รหัสผ่านอย่างเดียวไม่พอจริง ๆ … Continue reading 2024 Password Guidelines →
โดย kitty ณ 26 January 2025 13:59 +0000
เรื่องสมมติที่เกิดขึ้นจริง สิบสองปีก่อนโน้น Google Docs ยังใช้ภาษาไทยไม่ได้ดีเท่าทุกวันนี้ อจก. กับ FOSS dev หยิบมือนึง อยากเอาฟอนต์ TH Sarabun New เข้าไปอยู่ใน Google Docs จะได้สร้างเอกสารภาษาไทยได้สมบูรณ์ขึ้น โดยเฉพาะเอกสารราชการซึ่งมีมติฯ ให้ใช้ TH Sarabun PSK (อ่านต่อไปเรื่อย ๆ จะเข้าใจ PSK กับ New) และบังเอิญหยิบมือนั้นได้คุยกับ Dave Crossland คนที่ทำโครงการ Google Fonts .. เวลานั้น Dave บอก อจก. ว่ากำลังจะมาเมืองไทยพอดี ถ้าจะให้ workshop เรื่องฟอนต์ สัญญาอนุญาต การออกแบบ โปรแกรม Dave ยินดีมาก ๆ สำหรับหยิบมือนั้น การคุยกันกับ Dave เป็นการปักหมุด เรื่องฟอนต์ไทยไป … Continue reading About TH Sarabun →
โดย kitty ณ 26 January 2025 13:28 +0000
19 January 2025
There are many ways to manipulate JSON. I reviewed a few rapid ways today, which are using a command line tool called jq
and libraries that support JSONPath query language.
jq
Awk
is a powerful domain-specific language for text processing, but it lacks built-in support for manipulating hierarchical data structures like trees. jq
fills this gap by providing a tool for transforming JSON data. However, one potential drawback is that jq
requires a separate installation, which may add complexity to my workflow.
So I write a shell script using jq
to extract user's names and user's urls from a cURL response, and then output it in TSV format.
curl -s 'https://mstdn.in.th/api/v1/timelines/public?limit=10' | jq '.[].account | [.username, .url] | @tsv' -r
The result looks like this:
kuketzblog https://social.tchncs.de/@kuketzblog
cats https://social.goose.rodeo/@cats
AlJazeera https://flipboard.com/@AlJazeera
TheHindu https://flipboard.com/@TheHindu
GossiTheDog https://cyberplace.social/@GossiTheDog
kuketzblog https://social.tchncs.de/@kuketzblog
weeklyOSM https://en.osm.town/@weeklyOSM
juanbellas https://masto.es/@juanbellas
noborusudou https://misskey.io/@noborusudou
jerryd https://mastodon.social/@jerryd
With a TSV file, we can use Awk, sed, etc. to manipulate them as usual.
JSONPath
JSONPath, which was explained in RFC 9535, is supported by many libraries and applications, e.g. PostgreSQL. Still, I try to it in Python by the jsonpath_nq
library.
from jsonpath_ng import parse
import requests
res = requests.get("https://mstdn.in.th/api/v1/timelines/public?limit=10")
compiled_path = parse("$[*].account")
for matched_node in compiled_path.find(res.json()):
print(matched_node.value["username"] + "\t" + matched_node.value["url"])
It gave the same result to the shell script above. The code is a bit longer than the shell script. However, it can be integrated with many Python libraries.
โดย Vee Satayamas ณ 19 January 2025 11:55 +0000
1 January 2025
ต้นเดือน กพ. คุณพ่อ อจก. ป่วย หมอพบลำไส้อุดตัน และภายหลังพบว่าสาเหตุมาจากมะเร็งลำไส้ใหญ่ระยะ 3 หมอ รพ.ขก. ผ่าตัดฉุกเฉินรักษาได้ทัน แต่พ่อติดเชื้อหลังผ่าตัด อจก. ย้ายพ่อมารักษาที่ รพ.ศรีฯ เชื้อดื้อยามาก ๆ ลากยาวมาจนถึงสงกรานต์ ร่างกายพ่ออ่อนแอจนมีการติดเชื้อราเพิ่ม หมอให้ยาฆ่าเชื้อ 5 ตัว ยาตัวสุดท้ายที่เหลือให้หมอใช้ได้ เป็นตัวที่แรงมาก ๆ และมีผลข้างเคียงแรงมาก ๆ แต่ก็ไม่สามารถลดการติดเชื้อได้ เราหมดทางรักษาการติดเชื้อของพ่อ พ่ออดทนกับการรับยาฆ่าเชื้อมาจนถึงเมื่อวาน เวลา 11:30 เป็นเวลาที่เราได้พบกับทีมรักษาประคับประคอง (palliative care) ครอบครัวเราตัดสินใจรับ palliative care ในช่วงท้าย ทำให้ครอบครัวเรามีเวลาอยู่กับท่าน และเลือกการประคับประคองที่ทำได้ สำหรับบางกรณี อาจจะประคองกันได้เป็นเดือน ๆ ทำให้ครอบครัวมีเวลาได้อยู่ด้วยกัน ใช้ชีวิตได้เกือบจะปกติ สำหรับกรณีของเรา ทางเลือกที่พ่อทรมานที่สุดอาจจะประคองได้ไม่กี่ชั่วโมง และทางเลือกที่ทรมานน้อยที่สุดประคองได้ไม่กี่นาที ครอบครัวเราเลือกที่พ่อทรมานน้อยที่สุด หยุดรับการให้ยาฆ่าเชื้อ จนเมื่อวานเย็น เราให้ถอด life support … Continue reading ป๊า →
โดย kitty ณ 1 January 2025 05:30 +0000
ฉลองด้วยการทำงานตั้งแต่ UTC+11 ยัน UTC+4 ตื่นสาย ๆ ก็นึกขึ้นได้ว่า .. “เรามี archive.org นี่หว่า!!!” เช็ค archive.org ว่ามี snapshot หน้าเว็บนี้ไหม ปรากฎว่ามีเยอะเลย! “รอดแล้วโว้ยยย” สรุปว่า .. โพสหลังมีนาคม 2017 จนถึง 30 ธันวาคม 2024 เอากลับมาโดย copy & paste มาจาก archive.org ล่ะจ้า
โดย kitty ณ 1 January 2025 05:28 +0000
/me มีติ่งเนื้อที่ข้อพับหลังเข่าซ้าย เป็นอยู่หลายเดือนแล้ว ขนาดก็ไม่ได้โตขึ้นอะไร เมื่อวานไปผ่าตัดเอาออก ผ่าเล็กห้อง ER ฉีดยาชา ไม่มีราก ขั้วไม่ใหญ่ เฉือนออกไม่มาก แต่กรีดแผลกว้างหน่อย 15 นาทีเสร็จ หมอเห็นติ่งเนื้อเองก็ไม่แน่ใจว่าคืออะไร เลยส่งตรวจ ส่วนตอนนี้พันแผลไว้ ห้ามแกะ ห้ามโดนน้ำ นัดตัดไหมอีกสองสัปดาห์ค่อยแกะทีเดียว
โดย kitty ณ 1 January 2025 04:30 +0000
Well, two weeks after the operation, I got stitches removed. The excision wound is somewhere between 4-5 cm long, it’s pretty intact. Still need to put a gauze pad for 4-5 more days though. So, what is it exactly ? Based on diagnostic surgical pathology, it’s an irritated seborrheic keratosis. Safe ? Yes.
โดย kitty ณ 1 January 2025 04:29 +0000
5-minute smart contract on ETH-compat blockchain network ? .. Yes, it is very possible .. if you already have some knowledge about it.
โดย kitty ณ 1 January 2025 04:28 +0000
สงกรานต์ปี 2563 เป็นปี จ.ศ. (2563 – 1181) = 1382 วันเถลิงศก ตรงกับ (1382 * 0.25875)+ floor(1382 / 100 + 0.38)– floor(1382/ 4 + 0.5)– floor(1382 / 400 + 0.595)– 5.53375= 357.5925 + 14 – 346 – 4 – 5.53375= 16.05875 = วันที่ 16 เมษายน 2563 เวลา 01:24:36 วันสงกรานต์ ตรงกับ 16.05875 – 2.165 = 13.89375 = วันที่ … Continue reading คำนวณวันสงกรานต์ปี 2563 →
โดย kitty ณ 1 January 2025 04:26 +0000
สงกรานต์ปี 2564 เป็นปี จ.ศ. (2564 – 1181) = 1383 วันเถลิงศก ตรงกับ (1383 * 0.25875)+ floor(1383 / 100 + 0.38)– floor(1383/ 4 + 0.5)– floor(1383 / 400 + 0.595)– 5.53375= 357.85125 + 14 – 346 – 4 – 5.53375= 16.3175 = วันที่ 16 เมษายน 2564 เวลา 07:37:12 วันสงกรานต์ ตรงกับ 16.3175 – 2.165 = 14.1525 = วันที่ … Continue reading คำนวณวันสงกรานต์ปี 2564 →
โดย kitty ณ 1 January 2025 04:25 +0000
I knew I’m in a dream. It was a bad dream. I wanted to get out I knew I’m in a dream. I decided to commit a suicide so it would wake me up. I jumped out of a window, closed my eyes. It was pitch black. Eyes opened, I woke up .. .. in … Continue reading Inception ? →
โดย kitty ณ 1 January 2025 04:25 +0000
สงกรานต์ปี 2565 เป็นปี จ.ศ. (2565 – 1181) = 1384 วันเถลิงศก ตรงกับ(1384 * 0.25875)+ floor(1384 / 100 + 0.38)– floor(1384 / 4 + 0.5)– floor(1384 / 400 + 0.595)– 5.53375= 358.11 + 14 – 346 – 4 – 5.53375= 16.57625= วันที่ 16 เมษายน 2565 เวลา 13:49:48 วันสงกรานต์ ตรงกับ16.57625 – 2.165 = 14.41125= วันที่ 14 เมษายน 2565 … Continue reading วันสงกรานต์ปี 2565 →
โดย kitty ณ 1 January 2025 04:24 +0000
เป็นปี จ.ศ. (2566 – 1181) = 1385 วันเถลิงศก ตรงกับ(1385 * 0.25875)+ floor(1385 / 100 + 0.38)– floor(1385 / 4 + 0.5)– floor(1385 / 400 + 0.595)– 5.53375= 358.36875 + 14 – 346 – 4 – 5.53375= 16.835= วันที่ 16 เมษายน 2566 เวลา 20:02:24 วันสงกรานต์ ตรงกับ16.835 – 2.165 = 14.67= วันที่ 14 เมษายน 2566 เวลา 16:04:48
โดย kitty ณ 1 January 2025 04:23 +0000
วันสงกรานต์ปี 2567 เป็นปี จ.ศ. (2567 – 1181) = 1386 วันเถลิงศก ตรงกับ(1386 * 0.25875)+ floor(1386 / 100 + 0.38)– floor(1386 / 4 + 0.5)– floor(1386 / 400 + 0.595)– 5.53375= 358.6275 + 14 – 347 – 4 – 5.53375= 16.09375= วันที่ 16 เมษายน 2567 เวลา 02:15:00 วันสงกรานต์ ตรงกับ16.09375 – 2.165 = 13.92875= วันที่ 13 เมษายน 2567 … Continue reading วันสงกรานต์ปี 2567 →
โดย kitty ณ 1 January 2025 04:22 +0000
31 December 2024
Python is a fantastic language, but in specific situations, Awk can offer significant advantages, particularly in terms of portability, longevity, conciseness, and interoperability.
While Python scripts are generally portable, they may not always run seamlessly on popular Docker base images like Debian and Alpine. In contrast, Awk scripts are often readily available and executable within these environments.
Although Python syntax is relatively stable, its lifespan is shorter compared to Awk. For example, the print 10
syntax from the early 2000s is no longer valid in modern Python. However, Awk scripts from the 1980s can still be executed in current environments.
Python is known for its conciseness, especially when compared to languages like Java. However, when it comes to text processing and working within shell pipelines, Awk often provides more concise solutions. For instance, extracting text blocks between "REPORT" and "END" can be achieved with a single line in Awk: /REPORT/,/END/ { print }
. Achieving the same result in Python typically involves more lines of code, including handling file input and pattern matching.
While Python can be embedded within shell scripts like Bash, aligning the indentation of multiline Python code with the surrounding shell script can often break the Python syntax. Awk, on the other hand, is less sensitive to indentation, making it easier to integrate into shell scripts.
Although different Awk implementations (such as Busybox Awk and GNU Awk) may have minor variations, Awk generally offers advantages over Python in the situations mentioned above.
โดย Vee Satayamas ณ 31 December 2024 17:44 +0000
เมื่อคืน .. 22:00 Vultr ส่งเมลแจ้ง unplanned hardware maintenance .. ส่งผลให้ VPS instance อจก ตายไป 1 ตัว 02:00 Vultr update ว่า พยายามกู้ (manually) แล้ว แต่ไม่สำเร็จ เท่ากับ ข้อมูลใน instance นั้นหายถาวร ทีม Vultr จะสร้าง instance ให้ใหม่ size เดิม OS เดิม IP เดิม ให้เครดิตชดเชย 2 เดือน หลังจากได้ instance ใหม่แล้ว จะ recovery จาก snapshot หรือ backup ได้ 04:00 new instance … Continue reading ส่งท้ายปี 2024 →
โดย kitty ณ 31 December 2024 16:58 +0000
29 December 2024
ต้นเดือน กพ. คุณพ่อ อจก. ป่วย หมอพบลำไส้อุดตัน และภายหลังพบว่าสาเหตุมาจากมะเร็งลำไส้ใหญ่ระยะ 3 หมอ รพ.ขก. ผ่าตัดฉุกเฉินรักษาได้ทัน แต่พ่อติดเชื้อหลังผ่าตัด อจก. ย้ายพ่อมารักษาที่ รพ.ศรีฯ เชื้อดื้อยามาก ๆ ลากยาวมาจนถึงสงกรานต์ ร่างกายพ่ออ่อนแอจนมีการติดเชื้อราเพิ่ม หมอให้ยาฆ่าเชื้อ 5 ตัว ยาตัวสุดท้ายที่เหลือให้หมอใช้ได้ เป็นตัวที่แรงมาก ๆ และมีผลข้างเคียงแรงมาก ๆ แต่ก็ไม่สามารถลดการติดเชื้อได้ เราหมดทางรักษาการติดเชื้อของพ่อ พ่ออดทนกับการรับยาฆ่าเชื้อมาจนถึงเมื่อวาน เวลา 11:30 เป็นเวลาที่เราได้พบกับทีมรักษาประคับประคอง (palliative care) ครอบครัวเราตัดสินใจรับ palliative care ในช่วงท้าย ทำให้ครอบครัวเรามีเวลาอยู่กับท่าน และเลือกการประคับประคองที่ทำได้ สำหรับบางกรณี อาจจะประคองกันได้เป็นเดือน ๆ ทำให้ครอบครัวมีเวลาได้อยู่ด้วยกัน ใช้ชีวิตได้เกือบจะปกติ สำหรับกรณีของเรา ทางเลือกที่พ่อทรมานที่สุดอาจจะประคองได้ไม่กี่ชั่วโมง และทางเลือกที่ทรมานน้อยที่สุดประคองได้ไม่กี่นาที ครอบครัวเราเลือกที่พ่อทรมานน้อยที่สุด หยุดรับการให้ยาฆ่าเชื้อ จนเมื่อวานเย็น เราให้ถอด life support … Continue reading ป๊า →
โดย kitty ณ 29 December 2024 07:57 +0000
21 July 2024
I usually run this shell script after installing SBCL because to develop a program in Common Lisp practically, I usually need libraries. Thus, this script install Quicklisp and Ultralisp as a package manager and a package repository, respectively. Moreover, I set working directory for my Common Lisp projects to Develop in my home directory because when I put them in quicklisp/local-projects, I usually forget to backup or even forget where that the projects exist.
#!/bin/bash
# My working directory is $HOME/Develop. You probably want to change it.
rm -rf ~/quicklisp
rm quicklisp.lisp
wget https://beta.quicklisp.org/quicklisp.lisp
sbcl --load quicklisp.lisp \
--eval '(quicklisp-quickstart:install)' \
--eval '(ql-util:without-prompting (ql:add-to-init-file))' \
--quit
rm quicklisp.lisp
sbcl --eval '(ql-dist:install-dist "http://dist.ultralisp.org/" :prompt nil)' --quit
if [ -e ~/.config/common-lisp ]; then
cp -rp ~/.config/common-lisp ~/.config/common-lisp.bak-$(date -I)-$$
fi
mkdir -p ~/.config/common-lisp
cat <<EOF > ~/.config/common-lisp/source-registry.conf
(:source-registry
(:tree (:home "Develop"))
:inherit-configuration)
EOF
โดย Vee Satayamas ณ 21 July 2024 14:58 +0000
14 July 2024
I wonder if I can use pyenv and pipenv on Fedora Workstation 40 although I don't use these utilities in my personal projects. And the answer is yes.
The steps are as follow:
Install dependencies
sudo dnf builddep python3
Install pyenv
curl https://pyenv.run | bash
I know that you don't like running Bash script immediately from cURL.
Modify .bashrc
Pyenv normally told you to append these lines to .bashrc, and the restart your terminal.
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# Restart your shell for the changes to take effect.
# Load pyenv-virtualenv automatically by adding
# the following to ~/.bashrc:
eval "$(pyenv virtualenv-init -)"
Install Python via Pyenv
pyenv install 3.10 # You can choose other versions
I know that we can install Python using configure and make like many other packages, but you can use pyenv as well.
Set default python
pyenv global 3.10 # or other version
And then restart your terminal.
And finally, install pipenv
โดย Vee Satayamas ณ 14 July 2024 08:32 +0000
10 June 2024
My frequent mistake in Go is overusing pointers, like this unrealistic example below:
type BBox struct {
X1 float64
Y1 float64
X2 float64
Y2 float64
}
func ShowWidth(b *BBox) {
w := math.Abs(b.X2 - b.X1)
fmt.Println(w)
}
func main() {
b1 := BBox{X1: 10.1, Y1: 100.2, X2: 1024.4, Y2: 4096.188888}
b2 := BBox{X1: 10.1, Y1: 100.2, X2: 2024.4, Y2: 4096.188888}
b3 := BBox{X1: 10.1, Y1: 100.2, X2: 3024.4, Y2: 4096.188888}
ShowWidth(&b1)
ShowWidth(&b2)
ShowWidth(&b3)
}
I pass a pointer of BBox to ShowWidth, which according to @meeusdylan's post, it slows down my program because the garbage collector has to determine if a BBox must be in stack or heap.
In the alternative code below, I don't use pointer.
func ShowWidth(b BBox) {
w := math.Abs(b.X2 - b.X1)
fmt.Println(w)
}
func main() {
b1 := BBox{X1: 10.1, Y1: 100.2, X2: 1024.4, Y2: 4096.188888}
b2 := BBox{X1: 10.1, Y1: 100.2, X2: 2024.4, Y2: 4096.188888}
b3 := BBox{X1: 10.1, Y1: 100.2, X2: 3024.4, Y2: 4096.188888}
ShowWidth(b1)
ShowWidth(b2)
ShowWidth(b3)
}
I worried that my program will copy the entire BBox every time ShowWidth is called. So, I checked the generated asssembly code. It looks like this:
ShowWidth(b1)
0x48098e f20f10059ab60300 MOVSD_XMM $f64.4024333333333333(SB), X0
0x480996 f20f100d9ab60300 MOVSD_XMM $f64.40590ccccccccccd(SB), X1
0x48099e f20f10159ab60300 MOVSD_XMM $f64.409001999999999a(SB), X2
0x4809a6 f20f101daab60300 MOVSD_XMM $f64.40b000305af6c69b(SB), X3
0x4809ae e82dffffff CALL main.ShowWidth(SB)
So, what I worried was true. MOVSD_XMM is for copying value from a member of a BBox in memory to a register one-by-one. You may see MOVSD_XMM was called 4 times per each ShowWidth call.
I didn't measure which one is faster or slower. I've heard that Skymont support loads per cycle. And, I wish they meant loading float64 using MOVSD_XMM as well. So, copying entire BBox is hopefully fast. And, at least, as far as I have been told, a BBox will definitely remain in stack without a need of checking by the GC.
Moreover, passing by value seems to comply to Go community better than pointer. So it will look familiar, and everyone will be happy to see passing by value.
My plan is avoiding pointer by default, and I will use it only when I have to. About performance, I think I may have to benchmark before using a pointer. Or if the speed is acceptable, I won't optimize.
โดย Vee Satayamas ณ 10 June 2024 09:36 +0000