<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by jason19970210 on Medium]]></title>
        <description><![CDATA[Stories by jason19970210 on Medium]]></description>
        <link>https://medium.com/@jason19970210?source=rss-ec1fbc9d25f9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*muXS5wwqnEaM231S46hExA.png</url>
            <title>Stories by jason19970210 on Medium</title>
            <link>https://medium.com/@jason19970210?source=rss-ec1fbc9d25f9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 22:09:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jason19970210/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Step-by-Step Guide How to Deal With Expired GPG Keys]]></title>
            <link>https://jason19970210.medium.com/a-step-by-step-guide-how-to-deal-with-expired-gpg-keys-72277e227e75?source=rss-ec1fbc9d25f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/72277e227e75</guid>
            <category><![CDATA[apt]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[gpg]]></category>
            <dc:creator><![CDATA[jason19970210]]></dc:creator>
            <pubDate>Thu, 25 Jan 2024 01:43:01 GMT</pubDate>
            <atom:updated>2024-01-25T01:48:01.641Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*INnchsqYcIAFh727" /><figcaption>Photo by <a href="https://unsplash.com/@aronvisuals?utm_source=medium&amp;utm_medium=referral">Aron Visuals</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Tags: apt gpg <br>Created At: 2024/01/24<br>Updated At: 2024/01/24</blockquote><p>A quick note for GPG key warning message from apt update :</p><pre>W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://deb.anydesk.com all InRelease: The following signatures were invalid: EXPKEYSIG 18DF3741CDFFDE29 philandro Software GmbH &lt;info@philandro.com&gt;<br>W: Failed to fetch http://deb.anydesk.com/dists/all/InRelease  The following signatures were invalid: EXPKEYSIG 18DF3741CDFFDE29 philandro Software GmbH &lt;info@philandro.com&gt;<br>W: Some index files failed to download. They have been ignored, or old ones used instead.</pre><p><a href="https://manpages.debian.org/testing/gpg/gpg.1.en.html"><strong>GPG</strong></a> is the OpenPGP (Pretty Good Privacy) part of the GNU Privacy Guard (GnuPG).<br>It is used to <strong>authorize </strong>the target source.<br>For my case, the expired GPG key ID belongs to Anydesk.</p><p>After searching through the Internet, there are many different ways to renew the key, but some of them are outdated, deprecated or insecure.</p><h3>Warning from <strong><em>apt-key(8)</em></strong></h3><p>ref: <a href="https://manpages.debian.org/testing/apt/apt-key.8.en.html">https://manpages.debian.org/testing/apt/apt-key.8.en.html</a></p><pre>apt-key(8) will last be available in Debian 11 and Ubuntu 22.04.</pre><pre>Use of apt-key is deprecated, except for the use of apt-key del in maintainer scripts to remove existing keys from the main keyring.</pre><p>The recommended way is just using tee command with wget to maintain the keys with the default directory /etc/apt/trusted.gpg.d/ or suggest directory /etc/apt/keyrings. <em>(see more detail with ref above)</em></p><pre>wget -qO- https://myrepo.example/myrepo.asc | sudo tee /etc/apt/trusted.gpg.d/myrepo.asc</pre><p>Make sure to use:</p><ul><li>asc extension for <strong>ASCII</strong> armored keys, works with apt version 1.4+</li><li>gpg extension for <strong>binary</strong> OpenPGP format (also known as “GPG key public ring”), works with all apt versions</li></ul><h3>Transfer between asc &amp; gpg format</h3><ul><li>GPG Binary to OpenPGP ASCII armor</li></ul><pre>$ gpg --dearmor file.gpg file.asc</pre><ul><li>OpenPGP ASCII armor to GPG Binary</li></ul><pre>$ gpg --enarmor file.asc file.gpg</pre><blockquote><em>The </em><strong>filename</strong> <em>for the keys can be </em>customized<em>, which should be specific in the </em><em>source.list with the </em><em>signed-by argument (</em><em>Signed-By as deb822 multi-line format). <br><br>If no keyring files are specified the default is the </em><em>trusted.gpg keyring and </em><strong>all</strong> <em>keyrings in the </em><em>trusted.gpg.d/ directory.<br><br>Ref: </em><a href="https://manpages.ubuntu.com/manpages/noble/en/man5/sources.list.5.html">https://manpages.ubuntu.com/manpages/noble/en/man5/sources.list.5.html</a></blockquote><h3>If missing GPG key</h3><p>NO_PUBKEY error will occur if apt doesn’t find proper GPG key file in .</p><pre>Err:21 http://deb.anydesk.com all InRelease<br>  The following signatures couldn&#39;t be verified because the public key is not available: NO_PUBKEY 18DF3741CDFFDE29</pre><h3>Solution (Option 1 with apt-key)</h3><p>The key to pass into --recv-keys argument can be found in error message, for example with the above message, the key will be 18DF3741CDFFDE29 .</p><pre>$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 18DF3741CDFFDE29</pre><h3>Solution (Option 2 with tee)</h3><p>The target URL should be found in the documentation somewhere from the packet official website, ex.<br>- <a href="http://deb.anydesk.com/howto.html">http://deb.anydesk.com/howto.html</a><br>- <a href="https://ngrok.com/docs/getting-started/">https://ngrok.com/docs/getting-started/</a></p><pre>$ wget -qO - https://keys.anydesk.com/repos/DEB-GPG-KEY | sudo tee /etc/apt/trusted.gpg.d/anydesk.asc</pre><h3>Solution (Option 3 with tee &amp; gpg dearmor)</h3><pre>$ wget -qO - https://keys.anydesk.com/repos/DEB-GPG-KEY | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/anydesk.gpg</pre><p>Hope this article could save you day ! There might have more details around apt, gpg, source.list. I will keep organize and publish !</p><h3>Ref</h3><ol><li><a href="https://www.digitalocean.com/community/tutorials/how-to-handle-apt-key-and-add-apt-repository-deprecation-using-gpg-to-add-external-repositories-on-ubuntu-22-04">https://www.digitalocean.com/community/tutorials/how-to-handle-apt-key-and-add-apt-repository-deprecation-using-gpg-to-add-external-repositories-on-ubuntu-22-04</a></li><li><a href="https://askubuntu.com/questions/1259803/what-does-the-apt-key-adv-command-mean">https://askubuntu.com/questions/1259803/what-does-the-apt-key-adv-command-mean</a></li><li><a href="https://www.linuxuprising.com/2021/01/apt-key-is-deprecated-how-to-add.html">https://www.linuxuprising.com/2021/01/apt-key-is-deprecated-how-to-add.htm</a>l</li><li><a href="https://code.yidas.com/pgp-gpg-commands/">https://code.yidas.com/pgp-gpg-commands/</a></li><li><a href="https://opensource.com/article/22/9/deprecated-linux-apt-key">https://opensource.com/article/22/9/deprecated-linux-apt-key</a></li><li><a href="https://www.gnupg.org/documentation/manuals/gnupg/GPG-Configuration-Options.html">https://www.gnupg.org/documentation/manuals/gnupg/GPG-Configuration-Options.html</a></li><li><a href="https://askubuntu.com/questions/29889/how-do-i-check-if-my-openpgp-key-is-in-the-ubuntu-keyserver">https://askubuntu.com/questions/29889/how-do-i-check-if-my-openpgp-key-is-in-the-ubuntu-keyserver</a></li><li><a href="https://manpages.ubuntu.com/manpages/xenial/man5/sources.list.5.html">https://manpages.ubuntu.com/manpages/xenial/man5/sources.list.5.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72277e227e75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Minimum L3 IP Packet with Scapy in Python & Wireshark]]></title>
            <link>https://jason19970210.medium.com/minimum-tcp-packet-with-scapy-in-python-wireshark-5ee93198a522?source=rss-ec1fbc9d25f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ee93198a522</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[tcp]]></category>
            <category><![CDATA[wireshark]]></category>
            <category><![CDATA[scapy]]></category>
            <dc:creator><![CDATA[jason19970210]]></dc:creator>
            <pubDate>Fri, 19 Jan 2024 06:23:43 GMT</pubDate>
            <atom:updated>2024-01-22T04:16:57.152Z</atom:updated>
            <content:encoded><![CDATA[<p>Tags: scapy tcp/ip wireshark python ipv4</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eTEfExne3SY73eQm" /><figcaption>Photo by <a href="https://unsplash.com/@erwanhesry?utm_source=medium&amp;utm_medium=referral">Erwan Hesry</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>IP (Internet Protocol) is the network layer protocol that is responsible for routing packets across the internet. The IP header contains information about the source and destination addresses, the version, the length, the identification, the flags, the fragment offset, the time to live, the protocol, the checksum, and the options.</p><p>The IP header is usually 20 bytes long, but it can be up to 60 bytes if options are used. The IP header is also different from the TCP header in that it does not have any port numbers, sequence or acknowledgment numbers, window size, or flags. The IP header also has a different checksum algorithm and a different set of options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/0*jdyNL9kRZRbAvL4r.png" /><figcaption>IP Packet Header (<a href="https://www.geeksforgeeks.org/introduction-and-ipv4-datagram-header/">src</a>)</figcaption></figure><p>According to Section 3 in document Security Assessment of the Transmission Control Protocol (TCP) draft-ietf-tcpm-tcp-security-02.txt from IETF (Internet Engineering Task Force) <a href="https://datatracker.ietf.org/doc/html/draft-ietf-tcpm-tcp-security-02#section-3">[2]</a>, the minimum TCP header size is <em>20</em> bytes, and corresponds to a TCP segment with no options and no data. We can treat the IP packets which header length is less than 20 bytes as malicious traffic, aim to trigger a DoS attack, thus the device should <strong><em>drop</em></strong> the packet.</p><p>This article will deep dive with sending IP packets with less than minimum TCP header length as DoS attack by using Scapy package <a href="https://scapy.net/">[4]</a>.</p><h3>Experiences</h3><p>Build a simple IP packet with basic usage from Scapy</p><pre>from scapy.data import ETHER_BROADCAST<br>from scapy.layers.l2 import Ether<br>from scapy.layers.inet import IP<br>from scapy.arch import get_if_hwaddr<br>from scapy.sendrecv import sendp<br><br>## setup interface<br>src_mac_addr = get_if_hwaddr(&quot;&lt;interface&gt;&quot;)<br><br>packet = Ether(src=src_mac_addr, dst=ETHER_BROADCAST) / IP()<br><br>packet.show2()<br><br>print(f&quot;packet length (bytes): {len(packet)}\n&quot;)<br><br>sendp(packet)<br><br>## Output<br><br>###[ Ethernet ]### <br>  dst       = ff:ff:ff:ff:ff:ff<br>  src       = &lt;interface_MAC_addr&gt;<br>  type      = IPv4                   &lt;- EtherType: 0x0800<br>###[ IP ]### <br>     version   = 4<br>     ihl       = 5<br>     tos       = 0x0<br>     len       = 20<br>     id        = 1<br>     flags     = <br>     frag      = 0<br>     ttl       = 64<br>     proto     = hopopt<br>     chksum    = 0x7ce7<br>     src       = 127.0.0.1<br>     dst       = 127.0.0.1<br>     \options   \<br><br>packet length (bytes): 34</pre><p>As the result, the basic TCP packet comes with 34 bytes, including 14 bytes as Ether packet and 20 bytes as TCP packet header.</p><p>The above code snippet also shows the EtherType <a href="https://en.wikipedia.org/wiki/EtherType">[wiki]</a> <a href="https://en.wikipedia.org/wiki/EtherType#Values">[Value Table]</a> for a L2 packet is 0x0800 which indicates as IPv4 type in Wireshark.</p><p>If there is no IP packet section right after the Ether packet, the EtherType will be filled with default value: 0x0900 which indicates loopback in Wireshark.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*QhQ8VXosl0e09i855WFjlw.png" /><figcaption>Basic TCP packet with 34 bytes</figcaption></figure><p>Try building the IP packet with 4 bytes header by using Raw without IP packet section</p><pre>from scapy.data import ETHER_BROADCAST<br>from scapy.packet import Raw<br>from scapy.arch import get_if_hwaddr<br>from scapy.sendrecv import sendp<br><br>## setup interface<br>src_mac_addr = get_if_hwaddr(&quot;&lt;interface&gt;&quot;)<br><br>packet = Ether(src=src_mac_addr, dst=ETHER_BROADCAST, type=0x0800) / Raw(b&#39;\x45\x00\x00\x04&#39;)<br><br>packet.show2()<br><br>print(f&quot;packet length (bytes): {len(packet)}\n&quot;)<br><br>sendp(packet)<br><br>## Output<br><br>###[ Ethernet ]### <br>  dst       = ff:ff:ff:ff:ff:ff<br>  src       = &lt;interface_MAC_addr&gt;<br>  type      = IPv4<br>###[ IP ]### <br>     version   = 4<br>     ihl       = 5<br>     tos       = 0x0<br>     len       = 4<br>     id        = 1<br>     flags     = <br>     frag      = 0<br>     ttl       = 64<br>     proto     = hopopt<br>     chksum    = None<br>     src       = 127.0.0.1<br>     dst       = 127.0.0.1<br>     \options   \<br><br>packet length (bytes): 18</pre><p>According to the previous test, the minimum IP packet which Wireshark can recognize must contain 4 bytes as IP packet header right after Ether frame (14 Bytes), so the packet length is 18 bytes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*cFUzVUWg4-hVz80V31NGUg.png" /><figcaption>TCP packet with less than 20 bytes header</figcaption></figure><p>Another test for sending full 20 bytes IP packet header with \x00 , please modify the Total Length value to 0x14 which is integer 20 as decimal notation.</p><pre>from scapy.data import ETHER_BROADCAST<br>from scapy.packet import Raw<br><br>## setup interface<br>src_mac_addr = get_if_hwaddr(&quot;&lt;interface&gt;&quot;)<br><br>packet = Ether(src=src_mac_addr, dst=ETHER_BROADCAST, type=0x0800) / Raw(b&#39;\x45\x00\x00\x14&#39;) / Raw(b&#39;\x00&#39; * 16)<br>                                                                                       ^<br>                                                                                       Total Length Value    <br>packet.show2()<br><br>print(f&quot;packet length (bytes): {len(packet)}\n&quot;)<br><br>## Output<br><br>###[ Ethernet ]### <br>  dst       = ff:ff:ff:ff:ff:ff<br>  src       = &lt;interface_MAC_addr&gt;<br>  type      = IPv4<br>###[ IP ]### <br>     version   = 4<br>     ihl       = 5<br>     tos       = 0x0<br>     len       = 4<br>     id        = 1<br>     flags     = <br>     frag      = 0<br>     ttl       = 64<br>     proto     = hopopt<br>     chksum    = None<br>     src       = 127.0.0.1<br>     dst       = 127.0.0.1<br>     \options   \<br><br>packet length (bytes): 34</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*t9gnIQ23NgnxC7uwFUoPvg.png" /></figure><p>What if we remove the Raw(b&#39;\x00&#39; * 16) ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*pUqU-0x1SXJ1e2dzVULRWA.png" /></figure><p>Wireshark will mark this packet as malformed IPv4 packet.</p><h3>Conclusion</h3><p>Based on the tests above, for sending out a malformed IP packet which <em>header length</em> is less than <em>20</em> bytes should be at least 14 bytes as Ether frame and 4 bytes if we desired to mark it as IPv4 packet section.</p><p>The DoS protection mechanism / policy should be set its filter which the IP packet length less than 20 bytes to avoid processing meaningless packet.</p><h3>Reference</h3><p>[1]: <a href="https://www.networkurge.com/2017/10/tcp-header-details.html">https://www.networkurge.com/2017/10/tcp-header-details.html</a><br>[2]: <a href="https://www.paloaltonetworks.com/cyberpedia/what-is-a-denial-of-service-attack-dos">https://www.paloaltonetworks.com/cyberpedia/what-is-a-denial-of-service-attack-do</a>s<br>[3]: <a href="https://datatracker.ietf.org/doc/html/draft-ietf-tcpm-tcp-security-02#section-3">https://datatracker.ietf.org/doc/html/draft-ietf-tcpm-tcp-security-02#section-3</a><br>[4]: <a href="https://scapy.net/">https://scapy.net/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ee93198a522" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firefox 火狐瀏覽器 更改中文字體 with Windows]]></title>
            <link>https://jason19970210.medium.com/firefox-%E7%81%AB%E7%8B%90%E7%80%8F%E8%A6%BD%E5%99%A8-%E6%9B%B4%E6%94%B9%E4%B8%AD%E6%96%87%E5%AD%97%E9%AB%94-with-windows-82206955f2c5?source=rss-ec1fbc9d25f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/82206955f2c5</guid>
            <category><![CDATA[firefox]]></category>
            <category><![CDATA[chinese-fonts]]></category>
            <category><![CDATA[fonts]]></category>
            <dc:creator><![CDATA[jason19970210]]></dc:creator>
            <pubDate>Tue, 31 Oct 2023 13:29:26 GMT</pubDate>
            <atom:updated>2023-10-31T13:32:17.669Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZ2ke_wHNN7NS333TCZ-7Q.jpeg" /></figure><p>在 Windows 系統上，有許多應用程式搭配其預設中文字體，hmmmm，就很新細明體。為了能讓 Firefox on Windows 能跟 Firefox on macOS 擁有類似的字體，因此這篇文章誕生了。</p><p>方法一：手動更改</p><p>其實方法一是相對直觀的，要修正的筆數也沒有到太多 (9筆)，可能用方法二的時間也差不多改完了</p><p>Step1. 在 Firefox 的網址輸入框中輸入: about:config ，按下 [接受風險並繼續 (Accept the Risk and Continue)]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*EVESBBYQWoeVDBA6IGfH4g.png" /><figcaption>Accept the Risk and Continue</figcaption></figure><p>Step2. 在 about:config 頁面中 搜尋: font.name-list.*.zh<br>(搜尋跟 zh 有關的字體)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xTLSaH-cJVyBZnUYamQSmQ.png" /><figcaption>about:config -&gt; font.name-list.*.zh</figcaption></figure><p>Step3. 將對應的項目替換掉<br>(記得修改後要再按最右方的確認，不然不會儲存)</p><pre>font.name-list.cursive.zh-CN : Microsoft YaHei, KaiTi, KaiTi_GB2312<br>font.name-list.cursive.zh-HK : Microsoft JhengHei, DFKai-SB<br>font.name-list.cursive.zh-TW : Microsoft JhengHei, DFKai-SB<br><br>(這三個維持預設值 / As Default)<br>font.name-list.monospace.zh-CN : SimSun, MS Song, SimSun-ExtB<br>font.name-list.monospace.zh-HK : MingLiU_HKSCS, Ming(for ISO10646), MingLiU, MingLiU_HKSCS-ExtB, Microsoft JhengHei<br>font.name-list.monospace.zh-TW : MingLiU, MingLiU-ExtB<br><br>font.name-list.sans-serif.zh-CN : Microsoft YaHei, 新細明體,PMingLiU,細明體,MingLiU<br>font.name-list.sans-serif.zh-HK : Microsoft JhengHei, Arial, MingLiU_HKSCS, Ming(for ISO10646), MingLiU, MingLiU_HKSCS-ExtB<br>font.name-list.sans-serif.zh-TW : Microsoft JhengHei, Arial, PMingLiU, MingLiU, MingLiU-ExtB<br>font.name-list.serif.zh-CN : Microsoft YaHei, 新細明體,PMingLiu,細明體,MingLiU<br>font.name-list.serif.zh-HK : Microsoft JhengHei, Times New Roman, MingLiu_HKSCS, Ming(for ISO10646), MingLiU, MingLiU_HKSCS-ExtB<br>font.name-list.serif.zh-TW : Microsoft JhengHei, Times New Roman, PMingLiu, MingLiU, MingLiU-ExtB<br></pre><p>修正完之後長這樣:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UN4g7V52HGCHRjund86E2A.png" /></figure><p>方法二：直接修改 Config File</p><p>Step1. [ Win + R ] 執行 %APPDATA%\Mozilla\Firefox\Profiles</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*a33Zj_vqnzPkLRkn9Sb-VQ.png" /><figcaption>Win + R</figcaption></figure><p>Step2. 找到檔名為prefs.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*pwcElFSgMMNN6oSQYqa13A.png" /><figcaption>Find prefs.js in Profile folder</figcaption></figure><p>Step3. 用 Visual Studio Code 或是其他文字編輯器打開 prefs.js 並搜尋 font 字串，用下方的區塊取代</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xvnQMHimveCEIxDvftHYcg.png" /><figcaption>Replace the font.name-list.*.zh config</figcaption></figure><pre>user_pref(&quot;font.language.group&quot;, &quot;zh-TW&quot;);<br>user_pref(&quot;font.name-list.cursive.zh-CN&quot;, &quot;Microsoft YaHei, KaiTi, KaiTi_GB2312&quot;);<br>user_pref(&quot;font.name-list.cursive.zh-HK&quot;, &quot;Microsoft JhengHei, DFKai-SB&quot;);<br>user_pref(&quot;font.name-list.cursive.zh-TW&quot;, &quot;Microsoft JhengHei, DFKai-SB&quot;);<br>user_pref(&quot;font.name-list.sans-serif.zh-CN&quot;, &quot;Microsoft YaHei, 新細明體,PMingLiU,細明體,MingLiU&quot;);<br>user_pref(&quot;font.name-list.sans-serif.zh-HK&quot;, &quot;Microsoft JhengHei, Arial, MingLiU_HKSCS, Ming(for ISO10646), MingLiU, MingLiU_HKSCS-ExtB&quot;);<br>user_pref(&quot;font.name-list.sans-serif.zh-TW&quot;, &quot;Microsoft JhengHei, Arial, PMingLiU, MingLiU, MingLiU-ExtB&quot;);<br>user_pref(&quot;font.name-list.serif.zh-CN&quot;, &quot;Microsoft YaHei, 新細明體,PMingLiu,細明體,MingLiU&quot;);<br>user_pref(&quot;font.name-list.serif.zh-HK&quot;, &quot;Microsoft JhengHei, Times New Roman, MingLiu_HKSCS, Ming(for ISO10646), MingLiU, MingLiU_HKSCS-ExtB&quot;);<br>user_pref(&quot;font.name-list.serif.zh-TW&quot;, &quot;Microsoft JhengHei, Times New Roman, PMingLiu, MingLiU, MingLiU-ExtB&quot;);<br>user_pref(&quot;font.name.monospace.zh-TW&quot;, &quot;Microsoft Sans Serif&quot;);<br>user_pref(&quot;font.name.serif.x-western&quot;, &quot;Arial&quot;);<br>user_pref(&quot;font.name.serif.zh-TW&quot;, &quot;Arial&quot;);</pre><p>Done !</p><p>重新整理網頁之後就會有好看一些的字體了！</p><p>Ref: <a href="https://www.everybbs.com/show1.php?o=t&amp;f=233&amp;t=35">https://www.everybbs.com/show1.php?o=t&amp;f=233&amp;t=35</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82206955f2c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mojo Installation on Ubuntu 23.04 [Not Stable]]]></title>
            <link>https://jason19970210.medium.com/mojo-installation-on-ubuntu-23-04-8f381c377d2a?source=rss-ec1fbc9d25f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f381c377d2a</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[installation]]></category>
            <category><![CDATA[mojo]]></category>
            <category><![CDATA[ubuntu-23]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[jason19970210]]></dc:creator>
            <pubDate>Thu, 14 Sep 2023 06:14:59 GMT</pubDate>
            <atom:updated>2023-09-14T13:13:07.289Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Warning: Not Stable, please DO NOT try it on production environment</blockquote><blockquote>The default Python3 version for Ubuntu 23.04 is 3.11, thus we must install version from 3.8 to 3.10 for Mojo🔥 requirement.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Sld7PVXhJ1_Y6_0V" /><figcaption>Photo by <a href="https://unsplash.com/@wrongtog?utm_source=medium&amp;utm_medium=referral">WrongTog</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Installation Guide</h3><p>Sign in to <a href="https://developer.modular.com/signup?redirect=%2Fdownload">https://developer.modular.com/signup?redirect=%2Fdownload</a> to get the MODULAR_AUTH_TOKEN</p><p>Install modular CLI</p><pre>$ curl https://get.modular.com | \<br>  MODULAR_AUTH=&lt;MODULAR_AUTH_TOKEN&gt; \<br>  sh -</pre><p>Install mojo SDK via modular command</p><pre>$ modular install mojo</pre><p>Output from Ubuntu 23.04 with Python3.11</p><pre>$ modular install mojo<br># Found release for https://packages.modular.com/mojo @ 0.2.1, installing to /home/user/.modular/pkg/packages.modular.com_mojo<br># Downloads complete, setting configs...<br># Configs complete, running post-install hooks...<br>error: externally-managed-environment<br><br>× This environment is externally managed<br>╰─&gt; To install Python packages system-wide, try apt install<br>    python3-xyz, where xyz is the package you are trying to<br>    install.<br>    <br>    If you wish to install a non-Debian-packaged Python package,<br>    create a virtual environment using python3 -m venv path/to/venv.<br>    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make<br>    sure you have python3-full installed.<br>    <br>    If you wish to install a non-Debian packaged Python application,<br>    it may be easiest to use pipx install xyz, which will manage a<br>    virtual environment for you. Make sure you have pipx installed.<br>    <br>    See /usr/share/doc/python3.11/README.venv for more information.<br><br>note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.<br>hint: See PEP 668 for the detailed specification.<br>modular: error: failed to run python:</pre><p>Build Python3.10 from Source Code <a href="https://ubuntuhandbook.org/index.php/2021/10/compile-install-python-3-10-ubuntu/"><em>[ref1]</em></a><em> </em><a href="https://stackoverflow.com/questions/7880454/python-executable-not-finding-libpython-shared-library"><em>[ref2]</em></a></p><pre>$ sudo apt install -y wget build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev</pre><pre>$ wget -c https://www.python.org/ftp/python/3.10.13/Python-3.10.13.tar.xz<br>$ tar -Jxf Python-3.10.13.tar.xz<br><br>$ cd Python-3.10.13/<br>$ ./configure --enable-optimizations --enable-shared<br>$ sudo make -j4 &amp;&amp; sudo make altinstall</pre><p>The python3.10 will be installed in /usr/local/bin/</p><pre>$ which python3.10<br>/usr/local/bin/python3.10<br><br>$ which python3<br>/usr/bin/python3<br><br><br>$ python3 --version<br>Python 3.11.4</pre><p>Config Python3 version with update-alternatives command to make python3.10 as system python3 temporary. <a href="https://stackoverflow.com/questions/43062608/how-to-update-alternatives-to-python-3-without-breaking-apt"><em>[ref]</em></a></p><pre>$ sudo update-alternatives --list python3<br>update-alternatives: error: no alternatives for python3<br><br>$ sudo update-alternatives --list python<br>update-alternatives: error: no alternatives for python<br><br>$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 1<br>$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1<br><br>$ sudo update-alternatives --config python3<br>There are 2 choices for the alternative python3 (providing /usr/bin/python3).<br><br>  Selection    Path                       Priority   Status<br>------------------------------------------------------------<br>* 0            /usr/local/bin/python3.10   2         auto mode<br>  1            /usr/bin/python3.11         1         manual mode<br>  2            /usr/local/bin/python3.10   2         manual mode<br><br>Press &lt;enter&gt; to keep the current choice[*], or type selection number:<br></pre><p>After config the python3 version for the system, please aware to check again.</p><pre>$ python3 --version<br>Python 3.10.13</pre><p>Finally, time to install mojo again.</p><pre>$ modular install mojo</pre><p>After Installed, add modular path for system environment</p><pre>## Bash<br>echo &#39;export MODULAR_HOME=&quot;$HOME/.modular&quot;&#39; &gt;&gt; ~/.bashrc<br>echo &#39;export PATH=&quot;$HOME/.modular/pkg/packages.modular.com_mojo/bin:$PATH&quot;&#39; &gt;&gt; ~/.bashrc<br>source ~/.bashrc<br><br>## ZSH<br>echo &#39;export MODULAR_HOME=&quot;$HOME/.modular&quot;&#39; &gt;&gt; ~/.zshrc<br>echo &#39;export PATH=&quot;$HOME/.modular/pkg/packages.modular.com_mojo/bin:$PATH&quot;&#39; &gt;&gt; ~/.zshrc<br>source ~/.zshrc</pre><p>Ready to go</p><pre>$ mojo</pre><h3>Error &amp; Fix</h3><h4>modular: error: failure detected</h4><pre>modular: error: failure detected - please run `modular clean` and try again<br>==========================<br>Failure Information:<br> - Creating symlink for /home/user/.modular/pkg/packages.modular.com_mojo/lib/liblldb.so.18.0.0git -&gt; /home/user/.modular/pkg/packages.modular.com_mojo/lib/liblldb.so failed: File exists<br> - Creating symlink for /home/user/.modular/pkg/packages.modular.com_mojo/lib/libMojoJupyter.so.18git -&gt; /home/user/.modular/pkg/packages.modular.com_mojo/lib/libMojoJupyter.so failed: File exists<br> - Creating symlink for /home/user/.modular/pkg/packages.modular.com_mojo/lib/liblldb.so.18.0.0git -&gt; /home/user/.modular/pkg/packages.modular.com_mojo/lib/liblldb.so.18git failed: File exists<br> - Creating symlink for /home/user/.modular/pkg/packages.modular.com_mojo/lib/libKGENCompilerRTShared.so.18git -&gt; /home/user/.modular/pkg/packages.modular.com_mojo/lib/libKGENCompilerRTShared.so failed: File exists<br> - Creating symlink for /home/user/.modular/pkg/packages.modular.com_mojo/lib/libMojoLLDB.so.18git -&gt; /home/user/.modular/pkg/packages.modular.com_mojo/lib/libMojoLLDB.so failed: File exists<br> - Creating symlink for /home/user/.modular/pkg/packages.modular.com_mojo/lib/libLLCLRuntimeGlobals.so.18git -&gt; /home/user/.modular/pkg/packages.modular.com_mojo/lib/libLLCLRuntimeGlobals.so failed: File exists<br> - Creating symlink for /home/user/.modular/pkg/packages.modular.com_mojo/lib/libMSupportGlobals.so.18git -&gt; /home/user/.modular/pkg/packages.modular.com_mojo/lib/libMSupportGlobals.so failed: File exists<br>==========================</pre><pre>$ module clean &amp;&amp; modular install mojo</pre><h4>python3: error while loading shared libraries: libpython3.10.so.1.0: cannot open shared object file: No such file or directory</h4><pre>$ find /usr/local/lib/ -name &quot;libpython*.so*&quot;<br>/usr/local/lib/libpython3.10.so.1.0<br>/usr/local/lib/libpython3.so<br>/usr/local/lib/libpython3.10.so<br><br>$ export LD_LIBRARY_PATH=&quot;/usr/local/lib/:$LD_LIBRARY_PATH&quot;<br>$ module clean &amp;&amp; modular install mojo</pre><p>Thanks for your time, hope this article can help you install mojo in Ubuntu 23.04.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f381c377d2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golang Works with Shared Object Through cgo (.so Not Found Issue)]]></title>
            <link>https://jason19970210.medium.com/golang-works-with-shared-object-through-cgo-so-not-found-issue-46a8ce423f8b?source=rss-ec1fbc9d25f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/46a8ce423f8b</guid>
            <category><![CDATA[gcc]]></category>
            <category><![CDATA[cgo]]></category>
            <category><![CDATA[linker]]></category>
            <category><![CDATA[shared-objects]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[jason19970210]]></dc:creator>
            <pubDate>Sun, 10 Sep 2023 03:17:46 GMT</pubDate>
            <atom:updated>2024-01-24T01:20:41.276Z</atom:updated>
            <content:encoded><![CDATA[<p>Faced the problem with Golang and cgo for a couple days, so just take a quick note to record what had happened.</p><p><strong>Shortcut</strong>: Jump to <a href="#d1a3"><em>[Key Point]</em></a>, <a href="#3b04"><em>[Solution]</em></a> section<br>A quick look in <a href="https://gist.github.com/jason19970210/4b6c4f34bbe90dd366de608f3e9e8f17"><em>[Gist]</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hj89Vh7GqMhWnP7w" /><figcaption>Photo by <a href="https://unsplash.com/@kar111?utm_source=medium&amp;utm_medium=referral">Karine Avetisyan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>From the beginning, my goal was aim to make Golang works with a shared object file (.so) built from a C code.<br>Just like others in 2023, I went to ChatGPT for an answer which can help me have a quick look for the solution how to achieve the goal.</p><h3>Key Point</h3><p>Noticed from <a href="https://segmentfault.com/q/1010000022621510">Ref[2]</a>: (the reference is written in Chinese)</p><pre>1. The `.so` file built from gcc should has the `lib` prefix<br>example: `libsum.so`, `libcalc.so`<br><br>2. The value after `LDFLAGS` should goes with name without `lib`<br>example:<br>a) `libsum.so` -&gt; LDFLAGS=sum<br>a) `libcalc.so` -&gt; LDFLAGS=calc</pre><p>ChatGPT shows me a sum.c &amp; main.go</p><pre>// sum.c<br>#include &quot;sum.h&quot;<br><br>int sum(int a, int b) {<br>    return a + b;<br>}</pre><pre>package main<br><br>/*<br>#cgo LDFLAGS: -L. -lsum<br>#include &quot;sum.h&quot;<br>*/<br>import &quot;C&quot;<br>import &quot;fmt&quot;<br><br>func main() {<br> // Call the sum function from the shared library<br> result := C.sum(5, 7)<br><br> // Print the result<br> fmt.Printf(&quot;Sum: %d\n&quot;, result)<br>}</pre><p>I had put the files into following struct:</p><pre>$ tree &lt;project_folder&gt;<br>.<br>├── libs<br>│   ├── sum.c<br>│   └── sum.h<br>└── main.go</pre><p>With the build script:</p><pre>$ cd &lt;project_folder&gt;/libs<br>$ gcc -shared -o libsum.so sum.c<br><br>$ cd &lt;project_folder&gt;<br>$ go build -o go_sum main.go</pre><p>And here comes the first error:</p><pre>$ go build -o go_sum main.go<br><br># command-line-arguments<br>./main.go:5:10: fatal error: sum.h: No such file or directory<br>    5 | #include &quot;sum.h&quot;<br>      |          ^~~~~~~<br>compilation terminated.</pre><p>It’s not a big deal to us to create a sum.h header file.</p><pre>// sum.h<br><br>#include &lt;stdio.h&gt;<br><br>int sum(int a, int b);</pre><p>There should also put another compile flag: CFLAGS for cgo in main.go , then rebuild the Golang executable file</p><pre>package main<br><br>/*<br>#cgo CFLAGS: -Ilibs<br>#cgo LDFLAGS: -Llibs -lsum<br>#include &quot;sum.h&quot;<br>*/<br>import &quot;C&quot;<br>import &quot;fmt&quot;<br>...</pre><p>Once build successfully, just run the executable file with name go_sum</p><p>Unfortunately, another error pops !</p><pre>$ ./go_sum<br>./go_sum: error while loading shared libraries: libsum.so: cannot open shared object file: No such file or directory</pre><p>By searching and try-error for hours, I had found the solution which I should make the .so file been found by linker.</p><p>Here is the command where we can track the .so file information linked to a executable file:</p><pre>$ ldd &lt;executable file&gt;<br><br>## Results for go_sum<br>$ ldd go_sum<br>    linux-vdso.so.1 (0x00007ffde1aab000)<br>    libsum.so =&gt; not found<br>    libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6a85b55000)<br>    /lib64/ld-linux-x86-64.so.2 (0x00007f6a85d86000)</pre><p>As the result, the libsum.so has not been recognized, here is nothing consider with the .so itself, but the linker.</p><h3>Solution</h3><p>Updated: 2023/09/20</p><ul><li>By config correctly with LDFLAGS <br>Thanks to the answer from <a href="https://medium.com/@ark76r?source=post_page-----19cad9550246--------------------------------"><strong>Arkadiusz Rychliński</strong></a></li></ul><pre>#cgo LDFLAGS: -L./lib -Wl, -rpath, $ORIGIN/libs -lsum</pre><ul><li>By adding the LD_LIBRARY_PATH</li></ul><pre>$ export LD_LIBRARY_PATH=&lt;project_folder&gt;/lib/</pre><p>After the line execute, rebuild the Golang executable file, then check again the lib has been recognized with ldd command.</p><pre>$ go build -o go_sum main.go<br><br>$ ldd go_sum<br>    linux-vdso.so.1 (0x00007ffde1aab000)<br>    libsum.so =&gt; &lt;project_folder&gt;/libs/libsum.so (0x00007ff959dbb000)<br>    libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6a85b55000)<br>    /lib64/ld-linux-x86-64.so.2 (0x00007f6a85d86000)</pre><pre>$ ./go_sum<br>Sum: 12</pre><p>Hope the article can help to save times.</p><p>Ref:<br>[1]: <a href="https://segmentfault.com/q/1010000022621510">https://segmentfault.com/q/1010000022621510</a><br>[2]: <a href="https://serverfault.com/a/201711">https://serverfault.com/a/201711</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46a8ce423f8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Great News from ngrok with Static Domains]]></title>
            <link>https://jason19970210.medium.com/great-news-from-ngrok-with-static-domains-efd0c158cdde?source=rss-ec1fbc9d25f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/efd0c158cdde</guid>
            <category><![CDATA[ngrok]]></category>
            <category><![CDATA[static-url]]></category>
            <dc:creator><![CDATA[jason19970210]]></dc:creator>
            <pubDate>Sat, 09 Sep 2023 02:34:24 GMT</pubDate>
            <atom:updated>2023-09-09T02:38:29.104Z</atom:updated>
            <content:encoded><![CDATA[<p>Publish Date: 2023/09/09<br>Update Date: 2023/09/09</p><p>Just wake up as a normal day, took up my phone, checked notifications &amp; mails, there is a mail catch my eyes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k3H3DtZrzOWagNZ-" /><figcaption>Photo by <a href="https://unsplash.com/@cadop?utm_source=medium&amp;utm_medium=referral">Mathew Schwartz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Static domains and cloud edges for all ngrok users !</h3><p>What a great news for us. We don’t need to remember the random URL anymore. (but as my experience, the URL doesn&#39;t change that frequently). <br>Not only for test or dev use, also it can be used on production as well.</p><p>So let’s dive into the static domain for free users.</p><p>Step 1: <a href="https://dashboard.ngrok.com/login"><em>Login</em></a> to the ngrok dashboard<br>Step 2: Navigate to <a href="https://dashboard.ngrok.com/cloud-edge/domains"><em>Cloud Edge &gt; Domains</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*znOqdDNeXUAIgJbuxVp40g.png" /><figcaption>Cloud Edge &gt; Domain in Dashboard</figcaption></figure><p>Step 3: Just click on the button: <strong>Create Domain</strong> , then you’ll get a custom domain for yourself. As the value after --domain flag, example.ngrok-free.app for example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fDfSHWLmT9zUkG6fDnD4xA.png" /><figcaption>Start a tunnel via CLI</figcaption></figure><p>Step 4: Start the ngrok agent ! <br>- <a href="https://ngrok.com/download"><em>[Installation Guide]</em></a><em><br></em>Don’t forget create the Authtokens from Tunnels <a href="https://dashboard.ngrok.com/tunnels/authtokens"><em>[link]</em></a>, please keep it safe.</p><pre># Add AUTHTOKEN into config file<br>$ ngrok config add-authtoken &lt;YOUR-AUTHTOKEN&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mhyayKGp_2AtafC51BmFUA.png" /><figcaption>Tunnels &gt; Authtokens in Dashboard</figcaption></figure><p>Via Command Line Interface:</p><pre>$ ngrok http --domain=example.ngrok-free.app 80</pre><p>Via Config:</p><pre># Linux / macOS<br># Path: $HOME/.config/ngrok/ngrok.yml<br><br>version: 2<br>authtoken: &lt;YOUR-AUTHTOKEN&gt;<br><br>tunnels:<br>  NAME-OF-TUNNEL: # Change the name to your own<br>    proto: http<br>    addr: 80<br>    domain: example.ngrok-free.app</pre><pre># Start ngrok with config<br>$ ngrok start NAME-OF-TUNNEL<br><br># Specify the config file<br>$ ngrok start NAME-OF-TUNNEL --config &lt;FILE-PATH&gt;<br><br># Start all tunnels defined in yml<br>$ ngrok start --all</pre><p>For more information about ngrok agent, please refer:<br><a href="https://ngrok.com/docs/secure-tunnels/ngrok-agent/reference/config/">https://ngrok.com/docs/secure-tunnels/ngrok-agent/reference/config/</a></p><p>It’s quite convenience that we can observe the result via CLI output, it also shows in <a href="https://dashboard.ngrok.com/tunnels/agents"><strong><em>Tunnels &gt; Agents</em></strong></a><em> </em>with the dashboard.</p><p>Be aware of the limitation of the domain, it just goes with protocol http &amp; tls at all, not suit for tcp , so if there is other tcp tunnel defined in config yaml file, it won’t be connect via the static URL for free users.</p><p>Hope this article can help !</p><p>Ref:<br>1. <a href="https://ngrok.com/blog-post/free-static-domains-ngrok-users?utm_campaign=Monthly%20Newsletter&amp;utm_medium=email&amp;_hsmi=273371496&amp;utm_content=273371496&amp;utm_source=hs_email">https://ngrok.com/blog-post/free-static-domains-ngrok-users</a><br>2. <a href="https://ngrok.com/docs/secure-tunnels/ngrok-agent/reference/config/">https://ngrok.com/docs/secure-tunnels/ngrok-agent/reference/config/</a><br>3. <a href="https://dashboard.ngrok.com/">https://dashboard.ngrok.com</a>/</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efd0c158cdde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[致初學者：Python環境設置起手式]]></title>
            <link>https://jason19970210.medium.com/%E8%87%B4%E5%88%9D%E5%AD%B8%E8%80%85-python%E7%92%B0%E5%A2%83%E8%A8%AD%E7%BD%AE%E8%B5%B7%E6%89%8B%E5%BC%8F-79ae260520e7?source=rss-ec1fbc9d25f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/79ae260520e7</guid>
            <category><![CDATA[virtual-environment]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[projects]]></category>
            <dc:creator><![CDATA[jason19970210]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 07:49:50 GMT</pubDate>
            <atom:updated>2023-08-08T07:52:13.719Z</atom:updated>
            <content:encoded><![CDATA[<p>tags: Python, Virtual Environment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jm-Cx7yzZzM0w0Ez" /><figcaption>Photo by <a href="https://unsplash.com/@sajadnori?utm_source=medium&amp;utm_medium=referral">Sajad Nori</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>English Version:<br><a href="https://jason19970210.medium.com/to-beginners-learning-with-minimum-python-environment-setup-d37a6cdc6d3d">https://jason19970210.medium.com/to-beginners-learning-with-minimum-python-environment-setup-d37a6cdc6d3d</a></blockquote><p>目前在開發實務上有著不同的編輯器 (Editor) (e.g. Visual Studio Code (VSCode), Sublime, Atom, Notepad++)、集成開發環境 (IDE, Integrated Development Environments) (e.g. PyCharm, Visual Studio)、網頁型態環境 (Web-Based) (e.g. Colab)，讓大家更方便的使用 Python，但因為種類、方法繁多，也讓許多人產生疑惑</p><p>那麼最快上手的環境是哪一個？我自己覺得是 Colab，僅僅只需要打開一個分頁；但如果還是希望在自己的設備上，又該怎麼設置呢？</p><p>我們會先分類作業系統，進行不同的操作，以下是較為推薦的方式：<br>- Windows: 下載 Python 安裝程序<br>( link: <a href="https://www.python.org/downloads/">https://www.python.org/downloads/</a> )</p><p>- macOS: 已內建包含 Python3 的執行環境<br>- Linux: 可以使用 apt 或 yum 套件管理器下載</p><p>example:</p><pre>## Linux (with sudo privilege)<br>$ sudo apt install python3 python3-venv</pre><p>在 Windows 安裝精靈中，請勾選 “Add python.exe to PATH (將 python.exe 加入環境變數)” 選項，在安裝完成後的頁面中，點擊 “Disable path length restrictions (禁用路徑長度限制)” 選項</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/0*RjxeNncb5EzOuYzf.png" /><figcaption>Check: &quot;Add python.exe to PATH&quot;</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/0*j-NH7DNbBHxsa4TF.png" /><figcaption>Click: &quot;Disable path length limit&quot;</figcaption></figure><p>接下來我們要確認安裝是否完成，Python 能否正常運作：</p><blockquote>注意事項：<br>在 Windows 環境中，通常是用 python 這個指令來執行 python v3 版本；而在 macOS、Linux 系統中，使用 python3 指令來對應 python v3 版本，python 指令則是對應 python v2 版本</blockquote><pre>## [Windows] Command Prompt (CMD) / PowerShell (PS)<br>C:\Users\user&gt; python --version<br>Python 3.11.3<br><br>## macOS / Linux<br>user@localhost $ python3 --version<br>Python 3.11.3</pre><p>確認安裝、執行沒有問題後，就要來開始建立工作目錄，在國外的文章、論壇中通常稱作 Directory，也就是我們熟知的 Folder 資料夾</p><p>在這邊我們用「桌面 (Desktop)」舉例，並建立一個專案名稱為「hello_world」的資料夾</p><pre>## [Windows] Command Prompt (CMD) / Powershell (PS)<br>C:\Users\user&gt; cd Desktop<br>C:\Users\user\Desktop&gt; mkdir hello_world<br><br>## macOS / Linux<br>user@localhost:~ $ cd Desktop<br>user@localhost:~/Desktop $ mkdir hello_world</pre><p>對於每個專案所需要的套件 (dependency) 都會有所不同，因此我們需要建立 venv（虛擬環境, Virtual Environment）來達到區隔的效果</p><blockquote>註：<br>在指令 $ python3 -m venv venv 中，代表的事情是：讓電腦用 python3 去執行，執行的內容是指定執行的模組 (module) 為 venv，並將參數帶入，而這邊的參數係指我們要建立的虛擬環境名稱</blockquote><pre>## [Windows] Command Prompt (CMD) / PowerShell (PS)<br>C:\Users\user\Desktop&gt; cd hello_world<br>C:\Users\user\Desktop\hello_world&gt; python -m venv venv<br><br>## macOS / Linux<br>user@localhost:~/Desktop $ cd hello_world<br>user@localhost:~/Desktop/hello_world $ python -m venv venv</pre><p>此時系統就會在 hello_world 工作目錄中建立一個名為 venv 的新文件夾，裡面存放著跟虛擬環境相關的檔案，下一步就是啟動我們的虛擬環境</p><pre>## [Windows] Command Prompt (CMD)<br>C:\Users\user\Desktop\hello_world&gt; .\venv\Scripts\activate.bat<br><br>## [Windows] PowerShell (PS)<br>PS C:\Users\user\Desktop\hello_world&gt; .\venv\Scripts\Activate.ps1<br><br>## macOS / Linux /* NOTICE: Check &amp; set the exec permission */<br>user@localhost:~/Desktop/hello_world $ sudo chmod +x ./venv/bin/activate<br>user@localhost:~/Desktop/hello_world $ source ./venv/bin/activate</pre><blockquote>註：<br>在 Windows 環境中的 PowerShell 環境中，必須先設定 ExecutionPolicy 執行權限，才能執行 ps1 檔案<br>ref: <a href="https://superuser.com/a/106362">https://superuser.com/a/106362</a></blockquote><p>當我們成功啟動 venv 環境後，終端介面 (CLI, Command Line Interface) 的前綴會加上 venv 的名稱</p><pre>## [Windows] Command Prompt (CMD)<br>(venv) C:\Users\user\Desktop\hello_world&gt; <br><br>## [Windows] PowerShell (PS)<br>(venv) PS C:\Users\user\Desktop\hello_world&gt;<br><br>## macOS / Linux<br>(venv) user@localhost:~/Desktop/hello_world $<br><br><br>### To deactivate ###<br>## [Windows] Command Prompt (CMD) / PowerShell (PS)<br>(venv) &gt; deactivate<br>&gt;<br>## macOS / Linux<br>(venv) $ deactivate<br>$</pre><p>接著我們要檢查是否有確實用虛擬環境的 Python 執行檔來做執行</p><pre>## [Windows] PowerShell (PS)<br>(venv) PS C:\Users\user\Desktop\hello_world&gt; Get-Command python<br>(venv) PS C:\Users\user\Desktop\hello_world&gt; gcm python<br><br>CommandType  Name        Version    Source<br>-----------  ----        -------    ------<br>Application  python.exe  3.11.31... C:\Users\user\Desktop\hello_world\venv\Scripts\python.exe<br><br>(venv) PS C:\Users\user\Desktop\hello_world&gt; Get-Command pip<br>(venv) PS C:\Users\user\Desktop\hello_world&gt; gcm pip<br><br>CommandType  Name     Version    Source<br>-----------  ----     -------    ------<br>Application  pip.exe  0.0.0.0    C:\Users\user\Desktop\hello_world\venv\Scripts\pip.exe<br><br>## macOS / Linux<br>(venv) $ which python3<br>/home/user/Desktop/hello_world/venv/bin/python3<br>(venv) $ which pip3<br>/home/user/Desktop/hello_world/venv/bin/pip3</pre><p>下一步，在工作目錄中建立一個 main.py 來測試，Linux &amp; macOS 環境下可以用 touch 指令新增檔案，再透過 vim 指令編輯檔案</p><blockquote>Linux 安裝 vim 指令：<br>$ sudo apt install vim -y<br>$ sudo yum install vim -y</blockquote><pre># filename: main.py<br><br>print(&quot;hello world&quot;)</pre><pre>## [Windows] Command Prompt (CMD) / PowerShell (PS)<br>(venv) &gt; python main.py<br><br>## macOS / Linux<br>(venv) $ python3 main.py<br><br>### Output ###<br>hello world</pre><p>若要幫我們的專案安裝其他套件，通常是透過指令 $ pip install &lt;package&gt;</p><p>如果有很多套件 (也包含不同版本) 的需求，在習慣上會新增一個稱作 requirements.txt 的檔案，儲存會用到的套件資訊，並安裝在虛擬環境中</p><pre>## filename: requirememts.txt<br><br>pandas<br>numpy&gt;=1.24.3</pre><pre>## [Windows] Command Prompt (CMD) / PowerShell (PS)<br>(venv) &gt; pip install -r requirements.txt<br><br>## macOS / Linux<br>(venv) $ pip3 install -r requirements.txt</pre><p>到這邊我們已經完成了一個基本的專案建置，是時候加入自已的程式，讓 Python 幫我們實現要完成的目標。<br>對於編輯器的使用，我個人推薦 Visual Studio Code ( short for: VS Code / VSC)，而 IDE 的話，則是推薦 JetBrains 的 PyCharm</p><p>Visual Studio Code 在大多數情況下都能很好地勝任，同時也支援許多 Extensions，針對 ipynb 格式的 IPython Notebook 也是如此，僅需選擇正確的 Interpreter 直譯器即可執行</p><p>Keep enjoy coding with Python ! 希望這篇文章對讀者有所幫助</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79ae260520e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[To Beginners Learning with Minimum Python Environment Setup]]></title>
            <link>https://jason19970210.medium.com/to-beginners-learning-with-minimum-python-environment-setup-d37a6cdc6d3d?source=rss-ec1fbc9d25f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d37a6cdc6d3d</guid>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[virtual-environment]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[jason19970210]]></dc:creator>
            <pubDate>Tue, 23 May 2023 03:39:18 GMT</pubDate>
            <atom:updated>2023-09-05T02:20:27.420Z</atom:updated>
            <content:encoded><![CDATA[<p>tags: Python, Virtual Environment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fko-EJu9NXKvEwgj" /><figcaption>Photo by <a href="https://unsplash.com/@alishahlakhani?utm_source=medium&amp;utm_medium=referral">Ali Shah Lakhani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>中文版本:<br><a href="https://jason19970210.medium.com/%E8%87%B4%E5%88%9D%E5%AD%B8%E8%80%85-python%E7%92%B0%E5%A2%83%E8%A8%AD%E7%BD%AE%E8%B5%B7%E6%89%8B%E5%BC%8F-79ae260520e7">https://jason19970210.medium.com/%E8%87%B4%E5%88%9D%E5%AD%B8%E8%80%85-python%E7%92%B0%E5%A2%83%E8%A8%AD%E7%BD%AE%E8%B5%B7%E6%89%8B%E5%BC%8F-79ae260520e7</a></blockquote><p>Since there are lots of editors (e.g. Visual Studio Code (<em>VSCode</em>), Sublime, Atom, Notepad++), IDEs (Integrated Development Environment) (e.g. PyCharm, Visual Studio), web-based applications (e.g. Colab) support people to work with Python, but that always make those who don’t familiar with basic computer or programming knowledge really confusing.</p><p>What is the better setup for leaning Python ? Of course Colab is one of the simplest environment working with Python, just open a notebook. But what if working on your own PC or laptop ?</p><p>Download the Python execution from: <a href="https://www.python.org/downloads/">https://www.python.org/downloads/</a> , then follow the instructions to complete the installation.<br>[Recommended]<br>- Windows Installer (64-bit)<br>- macOS <strong>default</strong> comes with Python (version 3) execution already<br>- Linux can be downloaded with apt or yum package manager</p><p>example:</p><pre>## Linux (with sudo privilege)<br>$ sudo apt install python3 python3-venv</pre><p>For Windows installation wizard, please check the option Add python.exe to PATH at the beginning, and Disable path length limit at the end of wizard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*0i559GdakW1u9eZgC5EkAw.png" /><figcaption>Check: &quot;Add python.exe to PATH&quot;</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*bAL6PlvAzB2rhhJxtpOApw.png" /><figcaption>Click: “Disable path length limit”</figcaption></figure><p>Next, check the execution works fine along with:</p><blockquote>Beware that <em>Windows</em> points python to indicate Python version 3<br>Linux separates python as Python version 2, python3 as Python version 3</blockquote><pre>## [Windows] Command Prompt (CMD) / PowerShell (PS)<br>C:\Users\user&gt; python --version<br>Python 3.11.3<br><br>## macOS / Linux<br>user@localhost $ python3 --version<br>Python 3.11.3</pre><p>Now we are going to setup a project / working directory (aka. folder) on the Desktop, take folder name hello_world for example:</p><pre>## [Windows] Command Prompt (CMD) / Powershell (PS)<br>C:\Users\user&gt; cd Desktop<br>C:\Users\user\Desktop&gt; mkdir hello_world<br><br>## macOS / Linux<br>user@localhost:~ $ cd Desktop<br>user@localhost:~/Desktop $ mkdir hello_world</pre><p>For different purposes &amp; dependencies for each project, we need venv (aka. Virtual Environment) to separate &amp; isolate the packages.<br>P.S. $ python3 -m venv venv means calling for Python execution with the -m flag which using the module venv then make the virtual environment name as venv as the last parameter from the above command, choose your own venv name if you want.</p><pre>## [Windows] Command Prompt (CMD) / PowerShell (PS)<br>C:\Users\user\Desktop&gt; cd hello_world<br>C:\Users\user\Desktop\hello_world&gt; python -m venv venv<br><br>## macOS / Linux<br>user@localhost:~/Desktop $ cd hello_world<br>user@localhost:~/Desktop/hello_world $ python3 -m venv venv</pre><p>Then there will have a new folder called venv inside the working directory hello_world , next we are going to activate the virtual environment.</p><pre>## [Windows] Command Prompt (CMD)<br>C:\Users\user\Desktop\hello_world&gt; .\venv\Scripts\activate.bat<br><br>## [Windows] PowerShell (PS)<br>PS C:\Users\user\Desktop\hello_world&gt; .\venv\Scripts\Activate.ps1<br><br>## macOS / Linux /* NOTICE: Check &amp; set the exec permission */<br>user@localhost:~/Desktop/hello_world $ sudo chmod +x ./venv/bin/activate<br>user@localhost:~/Desktop/hello_world $ source ./venv/bin/activate</pre><p>PowerShell must have ExecutionPolicy set before activate ps1 file.<br>ref: <a href="https://superuser.com/a/106362">https://superuser.com/a/106362</a></p><p>Once we activate venv successfully, the console of the terminal will have the prefix indicated that we are inside the venv:</p><pre>## [Windows] Command Prompt (CMD)<br>(venv) C:\Users\user\Desktop\hello_world&gt; <br><br>## [Windows] PowerShell (PS)<br>(venv) PS C:\Users\user\Desktop\hello_world&gt;<br><br>## macOS / Linux<br>(venv) user@localhost:~/Desktop/hello_world $<br><br><br>### To deactivate ###<br>## [Windows] Command Prompt (CMD) / PowerShell (PS)<br>(venv) &gt; deactivate<br>&gt;<br>## macOS / Linux<br>(venv) $ deactivate<br>$</pre><p>Then how to check we are using the correct Python execution ?</p><pre>## [Windows] PowerShell (PS)<br>(venv) PS C:\Users\user\Desktop\hello_world&gt; Get-Command python<br>(venv) PS C:\Users\user\Desktop\hello_world&gt; gcm python<br><br>CommandType  Name        Version    Source<br>-----------  ----        -------    ------<br>Application  python.exe  3.11.31... C:\Users\user\Desktop\hello_world\venv\Scripts\python.exe<br><br>(venv) PS C:\Users\user\Desktop\hello_world&gt; Get-Command pip<br>(venv) PS C:\Users\user\Desktop\hello_world&gt; gcm pip<br><br>CommandType  Name     Version    Source<br>-----------  ----     -------    ------<br>Application  pip.exe  0.0.0.0    C:\Users\user\Desktop\hello_world\venv\Scripts\pip.exe<br><br>## macOS / Linux<br>(venv) $ which python3<br>/home/user/Desktop/hello_world/venv/bin/python3<br>(venv) $ which pip3<br>/home/user/Desktop/hello_world/venv/bin/pip3</pre><p>Then create a main.py for testing, with <em>Linux</em> you can try $ touch main.py for create or short command for create + edit by vim: $ vim main.py</p><blockquote>Install vim in Linux by : <br>$ sudo apt install vim -y<br><em>$ sudo yum install vim -y</em></blockquote><pre># filename: main.py<br><br>print(&quot;hello world&quot;)</pre><pre>## [Windows] Command Prompt (CMD) / PowerShell (PS)<br>(venv) &gt; python main.py<br><br>## macOS / Linux<br>(venv) $ python3 main.py<br><br>### Output ###<br>hello world</pre><p>Mostly we want to add dependencies for the project, just with the command $ pip install .</p><p>If there are lots of dependencies, comes with the purpose to management about package and versions, create a requirements.txt to store more information about them, and remember to install them inside the virtual environment, example:</p><pre>## filename: requirememts.txt<br><br>pandas<br>numpy&gt;=1.24.3</pre><pre>## [Windows] Command Prompt (CMD) / PowerShell (PS)<br>(venv) &gt; pip install -r requirements.txt<br><br>## macOS / Linux<br>(venv) $ pip3 install -r requirements.txt</pre><p>We had just setup the basic for the Python working directory !<br>Now it’s time to add your own codes and idea to make it happened.</p><p>For the editor I recommend Visual Studio Code (<a href="https://code.visualstudio.com/">link</a>) made by Microsoft, and the IDE goes to PyCharm (<a href="https://www.jetbrains.com/pycharm/">link</a>) from JetBrains.</p><p>VSCode works great for most of the cases, and has been nicely supported for basic Python script with extensions, so does ipynb format as IPython Notebook. Just select the correct interpreter then run the script, that’s all.</p><p>Keep enjoy coding with Python! Hope this article helps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d37a6cdc6d3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proper Setup for Netplan YAML File Permission]]></title>
            <link>https://jason19970210.medium.com/proper-way-to-setup-netplan-yaml-file-permission-867da8eb026a?source=rss-ec1fbc9d25f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/867da8eb026a</guid>
            <category><![CDATA[chmod]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[permission]]></category>
            <category><![CDATA[netplan]]></category>
            <dc:creator><![CDATA[jason19970210]]></dc:creator>
            <pubDate>Wed, 17 May 2023 01:51:33 GMT</pubDate>
            <atom:updated>2024-03-30T00:44:28.350Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pcF6ko5gt6luU0AH" /><figcaption>Photo by <a href="https://unsplash.com/@markuswinkler?utm_source=medium&amp;utm_medium=referral">Markus Winkler</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Begin</h3><p>Just during configuring the YAML file for the <a href="https://netplan.readthedocs.io/en/stable/">netplan</a> to modify my own IP route settings, I had met the warning messages below when applying:</p><pre>** (generate:40134): WARNING **: 09:28:29.011: Permissions for /etc/netplan/00-installer-config.yaml are too open. Netplan configuration should NOT be accessible by others.<br>** (generate:40134): WARNING **: 09:28:29.011: Permissions for /etc/netplan/01-network-manager-all.yaml are too open. Netplan configuration should NOT be accessible by others.</pre><p>Let’s dive in and check how to fix these warnings !<br>According to the message, it means that we have given too much permission which can allow non-root user to get the file content.</p><p>By checking the official documentation <a href="https://netplan.readthedocs.io/en/stable/reference/">(ref)</a> , they suggest only given read-write to root user only, which comes with <strong><em>600</em></strong> for the command option of chmod .</p><blockquote>Netplan’s configuration files use the <a href="http://yaml.org/spec/1.1/current.html">YAML (v1.1)</a> format. All files in /{lib,etc,run}/netplan/*.yaml are considered and are supposed to use restrictive file permissions (600 / rw-------), i.e. owner (root) read-write only.</blockquote><h3>Before</h3><p>As the following console output, we found that the YAML files are along with permission 644 which give read operation for user, that’s the cause for the warnings.</p><pre>$ cd /etc/netplan<br>$ ls -l<br><br>-rw-r--r--   1 root root    90 May  8 15:41 00-installer-config.yaml<br>-rw-r--r--   1 root root  1066 May 16 16:26 01-network-manager-all.yaml</pre><h3>Operation</h3><pre>$ cd /etc/netplan<br>$ sudo chmod 600 *.yaml<br>$<br> <br>$ ls -l<br>-rw------- 1 root root   90 May  8 15:41 00-installer-config.yaml<br>-rw------- 1 root root 1066 May 16 16:26 01-network-manager-all.yaml</pre><p>For now we have permission 600 for all YAML files inside directory /etc/netplan/ , just double check.</p><h3>Check</h3><pre>$ cd /etc/netplan/<br>$ cat 01-network-manager-all.yaml<br><br>cat: 01-network-manager-all.yaml: Permission denied<br><br>$ sudo cat 01-network-manager-all.yaml<br><br>network:<br>    version: 2<br>    renderer: NetworkManager<br>......</pre><p>Here we have done with the correct permission !<br>It’ s time to make it try / apply.</p><pre><br>$ sudo netplan try<br>$ sudo netplan apply</pre><p>Thanks for your time.<br>If you have any further questions, please feel free to leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=867da8eb026a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Back to Root View — Pure SwiftUI for iOS 16 with NavigationStack & NavigationDestination]]></title>
            <link>https://jason19970210.medium.com/back-to-root-view-pure-swiftui-for-ios-16-with-navigationstack-navigationdestination-a054a3550851?source=rss-ec1fbc9d25f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a054a3550851</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[jason19970210]]></dc:creator>
            <pubDate>Thu, 16 Mar 2023 06:19:40 GMT</pubDate>
            <atom:updated>2024-01-24T01:25:13.686Z</atom:updated>
            <content:encoded><![CDATA[<h3>Back to Root View — Pure SwiftUI for iOS 16 With NavigationStack &amp; NavigationDestination</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UWroa5WwluIfj_-W" /><figcaption>Photo by <a href="https://unsplash.com/@theshubhamdhage?utm_source=medium&amp;utm_medium=referral">Shubham Dhage</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Since the NavigationView has been soft deprecated for iOS 16 (<a href="https://developer.apple.com/documentation/swiftui/navigationview"><em>detail</em></a>), there comes 2 new instances: <a href="https://developer.apple.com/documentation/swiftui/navigationstack"><em>NavigationStack</em></a> &amp; <a href="https://developer.apple.com/documentation/swiftui/navigationsplitview"><em>NavigationSplitView</em></a> . This also brings the new navigationDestination function for changing views.</p><p>The isActive argument for NavigationLink method is also deprecated (<a href="https://developer.apple.com/documentation/swiftui/navigationlink/init(isactive:destination:label:)"><em>detail</em></a>), so how can we changing the views by using NavigationStack &amp; navigationDestination for the simplest way ?</p><p>Here is the migration document from apple: <a href="https://developer.apple.com/documentation/swiftui/migrating-to-new-navigation-types">https://developer.apple.com/documentation/swiftui/migrating-to-new-navigation-types</a></p><p>For my case, there are 3 views: HomeView, FormView, PreviewView. The user will go through one another then pop back to HomeView by pressing a button.</p><p>Expectation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*pnd1q83tXoAChH8hyZVqCw.gif" /><figcaption>Expectation Flow</figcaption></figure><p>By searching days and nights from anywhere I can reach, I cannot find any tutor or example which suit for my case. At the first time I am using navigationDestination , I tried using <a href="https://developer.apple.com/documentation/swiftui/navigationstack/navigationdestination(ispresented:destination:)"><em>isPresented</em></a> argument for controlling when the application should change view, such as button action, or some conditions. Along the method, the application didn’t pop back at the end of the flow.</p><p>So here is my solution, let’s dive into the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f31b8362b94338c51a6f99af99f56129/href">https://medium.com/media/f31b8362b94338c51a6f99af99f56129/href</a></iframe><p>First we create and initialize a global observed environment object goes with class Router, then share the router state for all views.</p><p>By using the new NavigationStack, here I called a .navigationDestination <em>instance method</em> with <a href="https://developer.apple.com/documentation/swiftui/navigationstack/navigationdestination(for:destination:)"><em>for</em></a> parameter which make program control which destination as the ViewFactory class does.</p><p>Update ( 2023/03/16 ): modify the ViewFactory from class to enum without return AvyView().</p><p>But even the for parameter can solve the case, I am still wondering how to make this happened by using the isPresented parameter, here is the stackoverflow <a href="https://stackoverflow.com/questions/74525690/navigationdestinationispresented-with-a-path-in-swiftui-4"><em>post</em></a> discuss about this topic.</p><p>&lt; Update 2023/04/12 &gt;<br>Since the Xcode has been updated to Version 14.3 which supporting iOS 16.4 &amp; iPadOS 16.4, I have encountered a new error message but the functions works great.<br>( ref: <a href="https://stackoverflow.com/a/75713254">https://stackoverflow.com/a/75713254</a> )</p><pre>Update NavigationAuthority bound path tried to update multiple times per frame.</pre><p>Hope this article can help !</p><p>ref: <br>1. <a href="https://developer.apple.com/documentation/swiftui/list/navigationdestination(for:destination:)">https://developer.apple.com/documentation/swiftui/list/navigationdestination(for:destination:</a>)<br>2. <a href="https://developer.apple.com/documentation/swiftui/navigationstack">https://developer.apple.com/documentation/swiftui/navigationstack</a><br>3. <a href="https://developer.apple.com/documentation/swiftui/navigationpath">https://developer.apple.com/documentation/swiftui/navigationpath</a><br>4. <a href="https://dev.to/gualtierofr/introducing-navigationpath-in-swiftui-3424">https://dev.to/gualtierofr/introducing-navigationpath-in-swiftui-3424</a><br>5. <a href="https://morioh.com/p/fe963ede1bdc">https://morioh.com/p/fe963ede1bdc</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a054a3550851" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>