<?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 Reorx Xiao on Medium]]></title>
        <description><![CDATA[Stories by Reorx Xiao on Medium]]></description>
        <link>https://medium.com/@reorx?source=rss-31cf00c8e47b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dwo82HC7KceFILgyWTV5qA.png</url>
            <title>Stories by Reorx Xiao on Medium</title>
            <link>https://medium.com/@reorx?source=rss-31cf00c8e47b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:40:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@reorx/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[Tips that may save you from the hell of PyYAML]]></title>
            <link>https://medium.com/@reorx/tips-that-may-save-you-from-the-hell-of-pyyaml-572cde7e1d6f?source=rss-31cf00c8e47b------2</link>
            <guid isPermaLink="false">https://medium.com/p/572cde7e1d6f</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[snippet]]></category>
            <category><![CDATA[yaml]]></category>
            <dc:creator><![CDATA[Reorx Xiao]]></dc:creator>
            <pubDate>Sun, 15 May 2022 09:55:53 GMT</pubDate>
            <atom:updated>2022-05-15T09:55:53.808Z</atom:updated>
            <content:encoded><![CDATA[<p>YAML is a data-serialization language that is widely used. As a developer, I’m always dealing with YAML from time to time. But processing YAML, especially using PyYAML in Python is painful and full of traps. Here I want to share some tips and snippets that can make your life with PyYAML easier.</p><blockquote><em>Code in this article is only guaranteed to work in Python 3</em></blockquote><h3>Always use safe_load/safe_dump</h3><p>YAML’s ability to construct an arbitrary Python object makes it dangerous to use blindly. It might be harmful to your application to simply yaml.load a document from an untrusted source such as the Internet and user input.</p><p>See from <a href="https://pyyaml.org/wiki/PyYAMLDocumentation#loading-yaml">PyYAML official documentation</a>:</p><blockquote><strong><em>Warning: It is not safe to call </em></strong><strong><em>yaml.load with any data received from an untrusted source! </em></strong><strong><em>yaml.load is as powerful as </em></strong><strong><em>pickle.load and so may call any Python function.</em></strong></blockquote><p>In short, you should always use yaml.safe_load and yaml.safe_dump as the standard I/O methods for YAML.</p><h3>Keep keys in order (load/dump)</h3><p>In Python 3.7+, the order of dict keys is naturally preserved [<a href="https://docs.python.org/3/whatsnew/3.7.html#:~:text=the%20insertion%2Dorder%20preservation%20nature%20of%20dict%20objects%20has%20been%20declared%20to%20be%20an%20official%20part%20of%20the%20Python%20language%20spec.">ref</a>], thus the dict you get from yaml.safe_load has the same order of keys as the original file.</p><pre><strong>&gt;&gt;&gt;</strong> <strong>import</strong> yaml<br><strong>&gt;&gt;&gt;</strong> text <strong>=</strong> &quot;&quot;&quot;---<br>... c: 1<br>... b: 1<br>... d: 1<br>... a: 1<br>... &quot;&quot;&quot;<br><strong>&gt;&gt;&gt;</strong> d <strong>=</strong> yaml<strong>.</strong>safe_load(text)<br><strong>&gt;&gt;&gt;</strong> d<br>{&#39;c&#39;: 1, &#39;b&#39;: 1, &#39;d&#39;: 1, &#39;a&#39;: 1}<br><strong>&gt;&gt;&gt;</strong> list(d)<br>[&#39;c&#39;, &#39;b&#39;, &#39;d&#39;, &#39;a&#39;]</pre><p>When dumping dict into a YAML string, make sure to add keyword argument sort_keys=False to preserve the order of keys.</p><pre><strong>&gt;&gt;&gt;</strong> print(yaml<strong>.</strong>safe_dump(d))<br>a: 1<br>b: 1<br>c: 1<br>d: 1<br><strong>&gt;&gt;&gt;</strong> d[&#39;e&#39;] <strong>=</strong> 1<br><strong>&gt;&gt;&gt;</strong> print(yaml<strong>.</strong>safe_dump(d, sort_keys<strong>=False</strong>))<br>c: 1<br>b: 1<br>d: 1<br>a: 1<br>e: 1</pre><p>If your Python version is lower, or you want to make sure the keys order preserving always works, you can use this library called <a href="https://github.com/wimglenn/oyaml">oyaml</a> as a drop-in replacement for pyyaml.</p><pre><strong>&gt;&gt;&gt;</strong> <strong>import</strong> oyaml <strong>as</strong> yaml<br><strong>&gt;&gt;&gt;</strong> d <strong>=</strong> yaml<strong>.</strong>safe_load(text)<br><strong>&gt;&gt;&gt;</strong> d<br>OrderedDict([(&#39;c&#39;, 1), (&#39;b&#39;, 1), (&#39;d&#39;, 1), (&#39;a&#39;, 1)])<br><strong>&gt;&gt;&gt;</strong> d[&#39;e&#39;] <strong>=</strong> 1<br><strong>&gt;&gt;&gt;</strong> print(yaml<strong>.</strong>safe_dump(d, sort_keys<strong>=False</strong>))<br>c: 1<br>b: 1<br>d: 1<br>a: 1<br>e: 1</pre><h3>Enhance list indentation (dump)</h3><p>By default, PyYAML indent list items on the same level as their parent.</p><pre><strong>&gt;&gt;&gt;</strong> d <strong>=</strong> {&#39;a&#39;: [1, 2, 3]}<br><strong>&gt;&gt;&gt;</strong> print(yaml<strong>.</strong>safe_dump(d))<br>a:<br><strong>-</strong> 1<br><strong>-</strong> 2<br><strong>-</strong> 3</pre><p>This is not a good format according to style guides like <a href="https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html">Ansible</a> and <a href="https://developers.home-assistant.io/docs/documenting/yaml-style-guide/#block-style-sequences">HomeAssistant</a>. It is also not recognized by code editors like VSCode, making the list items unfoldable in the editor.</p><p>To solve this problem, you can use the snippet below to define an IndentDumper class:</p><pre><strong>class</strong> <strong>IndentDumper</strong>(yaml<strong>.</strong>Dumper):<br>    <strong>def</strong> <strong>increase_indent</strong>(self, flow<strong>=False</strong>, indentless<strong>=False</strong>):<br>        <strong>return</strong> super(IndentDumper, self)<strong>.</strong>increase_indent(flow, <strong>False</strong>)</pre><p>Then pass it to the Dumper keyword argument in yaml.dump function.</p><pre><strong>&gt;&gt;&gt;</strong> print(yaml<strong>.</strong>dump(d, Dumper<strong>=</strong>IndentDumper))<br>a:<br>  <strong>-</strong> 1<br>  <strong>-</strong> 2<br>  <strong>-</strong> 3</pre><blockquote><em>Note that </em><em>Dumper cannot be passed to </em><em>yaml.safe_dump which has its owner dumper class defined.</em></blockquote><h3>Output readable UTF-8 (dump)</h3><p>By default, PyYAML assumes the user only wants ASCII code in the output, so it converts UTF-8 characters to Python’s Unicode representation.</p><pre><strong>&gt;&gt;&gt;</strong> d <strong>=</strong> {&#39;a&#39;: &#39;你好&#39;}<br><strong>&gt;&gt;&gt;</strong> print(yaml<strong>.</strong>safe_dump(d))<br>a: &quot;\u4F60\u597D&quot;</pre><p>This makes the output hard to read for humans.</p><p>In the modern world, UTF-8 is widely supported, it’s safe to write UTF-8 in the output. Pass allow_unicode=True to yaml.safe_dump to enable that.</p><pre><strong>&gt;&gt;&gt;</strong> print(yaml<strong>.</strong>safe_dump(d, allow_unicode<strong>=True</strong>))<br>a: 你好</pre><h3>No default_flow_style needed (dump)</h3><p>Most of the time we don’t want <a href="https://yaml.org/spec/1.2.2/#chapter-7-flow-style-productions">flow style productions</a> in the output (i.e. no JSON in YAML). According to <a href="https://pyyaml.org/wiki/PyYAMLDocumentation#dictionaries-without-nested-collections-are-not-dumped-correctly">PyYAML documentation</a>, default_flow_style=False should be passed to yaml.safe_dump to achieve that.</p><p>After digging into the source code of the latest PyYaml (6.0), I find it is not needed anymore. You should remove this keyword argument to keep the code cleaner and less confusing.</p><h3>Libraries</h3><h3>oyaml</h3><p>Link: <a href="https://github.com/wimglenn/oyaml">https://github.com/wimglenn/oyaml</a></p><p>As mentioned above, oyaml is a drop-in replacement for PyYAML which preserves dict ordering.</p><p>I suggest using oyaml if you already use PyYAML in your code.</p><p>It’s worth mentioning that oyaml is a single-file library with only <a href="https://github.com/wimglenn/oyaml/blob/d0195070d26bd982f1e4e604bded5510dd035cd7/oyaml.py">53 lines of code</a>. This makes it very flexible to use, you can just copy the code to your library and customize it according to your need.</p><h3>strictyaml</h3><p>Link: <a href="https://github.com/crdoconnor/strictyaml">https://github.com/crdoconnor/strictyaml</a></p><p>Some people say YAML is too complex and flexible to be a good configuration language, but I think this is not the problem of YAML, but the problem of how we use it. If we restrict our usage to only a subset of its features, it will be as good as it should be.</p><p>This is where StrictYAML came up. It is a type-safe YAML parser that parses and validates a <a href="https://hitchdev.com/strictyaml/features-removed">restricted subset</a> of the YAML specification.</p><p>I suggest using StrictYAML if you have strong security concerns for your application.</p><p>There are tons of great articles on the <a href="https://hitchdev.com/strictyaml/">documentation site</a> of strictyaml, definitely worth having a look at if you have thought about YAML and other configuration languages.</p><h3>ruamel. yaml</h3><p>Link: <a href="https://yaml.readthedocs.io/en/latest/overview.html">https://yaml.readthedocs.io/en/latest/overview.html</a></p><p>ruamel.yaml is a fork of PyYAML, it was released in 2009 and continuously maintained in the past decade.</p><p>The differences with PyYAML are listed <a href="https://yaml.readthedocs.io/en/latest/pyyaml.html#yaml-1-2-support">here</a>. Generally, ruamel.yaml focuses on <a href="https://yaml.org/spec/1.2.2/">YAML 1.2</a> with some opinionated enhancements for the syntax.</p><p>What interests me most is the ability to round-trip in the loading/dumping process. It works like black magic. Here’s the explanation from ruamel.yaml documentation:</p><blockquote><em>A round-trip is a YAML load-modify-save sequence and ruamel.yaml tries to preserve, among others:</em></blockquote><blockquote>- comments</blockquote><blockquote>- block style and key ordering are kept, so you can diff the round-tripped source</blockquote><blockquote>- flow style sequences ( ‘a: b, c, d’) (based on request and test by Anthony Sottile)</blockquote><blockquote>- anchor names that are hand-crafted (i.e. not of the formidNNN)</blockquote><blockquote>- merges in dictionaries are preserved</blockquote><p>I suggest using ruamel.yaml if you have the requirement to preserve the original content as much as possible.</p><blockquote><em>One thing I notice is that ruamel.yaml’s </em><em>safe_load method (</em><em>YAML(typ=&#39;safe&#39;).load) cannot parse flow style collection (</em><em>a: {&quot;foo&quot;: &quot;bar&quot;}), this is a undocumented difference with PyYAML.</em></blockquote><h3>Summary</h3><p>YAML has its good and bad. It’s easy to read, the learning curve is mild at the beginning, but the specification is complex, which not only causes chaos in practice, but also makes implementations in different languages inconsistent with each other in many trivial aspects.</p><p>Despite these quirks, YAML is still the best configuration language for me, and as long as we can use it properly, problems will be avoided and the experience will be much better.</p><p><em>This article is also published on my blog: </em><a href="https://reorx.com/blog/python-yaml-tips/"><em>https://reorx.com/blog/python-yaml-tips/</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=572cde7e1d6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A look into Heptabase’s split writing experience]]></title>
            <link>https://medium.com/@reorx/a-look-into-heptabases-split-writing-experience-87f9c2bfb257?source=rss-31cf00c8e47b------2</link>
            <guid isPermaLink="false">https://medium.com/p/87f9c2bfb257</guid>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[heptabase]]></category>
            <category><![CDATA[note-taking-app]]></category>
            <dc:creator><![CDATA[Reorx Xiao]]></dc:creator>
            <pubDate>Wed, 20 Apr 2022 16:28:56 GMT</pubDate>
            <atom:updated>2022-04-20T16:33:36.533Z</atom:updated>
            <content:encoded><![CDATA[<p>Yesterday I found <a href="https://heptabase.com/">Heptabase</a>’s new introduction video by <a href="https://medium.com/u/7f54ec92397a">詹雨安 Alan Chan</a>: <a href="https://www.youtube.com/watch?v=oVXQx9sz_Wk">The 3-step knowledge workflow in Heptabase</a>.</p><p>Heptabase is the most promising note-taking app for me in recent years. The idea of combining bi-directional links, cards, and whiteboards together is mind-blowing. The word note-taking or knowledge base is not accurate to define it, in fact, it’s more like a tool that aims for boosting the process of thinking.</p><p>Traditional note-taking tools are keen on providing more than enough ways for dumping your thoughts into notes, but lack methodologies on how to retrieve and use notes. The way Heptabase organizes and interacts with the data is what really empowers the user to think and write more efficiently.</p><p>Back to the video at the beginning, after watching it I noticed a very interesting feature. I can’t stop thinking of it and really wish to have something similar in other note-taking or PMK tools like Obsidian (yeah, I’m an Obsidian fan).</p><h3>The feature</h3><p>Here’s the walk though of that amazing feature:</p><ul><li>On a whiteboard, select several cards you would like to refer to</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZlZNZpJJdLwzJVhn.png" /></figure><ul><li>Right-click on them and choose “Open in new tab”, a new page with a left-right split layout appears. The first card selected shows on the left; others show on the right as a folded list.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C0wJDEDb0JbiPZxW.png" /></figure><ul><li>Click on the + sign button on the top menu bar; a new card is created on the left side, and the card that previously shows on the left is automatically moved to the card list on the right.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XSMB0ZBEBLko11Z4.png" /></figure><ul><li>You can fold/unfold notes while browsing the right side, and drag’n drop blocks to copy them to the left side.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F8XKwJRkY-TaoxbY.png" /></figure><p>This is the best way I’ve ever seen to think and write a note while referring to many other notes. In other note-taking tools, take Obsidian for example, I can split the panes, but it is not convenient to organize the workspace well for more than 3 notes. As new panes are growing, it will become more and more interruptive to switch back and forth.</p><p>Even if I managed to build up a tidy workspace, it’s still very frustrating to switch to another context. Obsidian has the functionality to manage workspaces, but you have to manually save before switching, otherwise, the context will be missing. In Heptabase, all the workspaces are clearly shown in the sidebar, switching around is fast and easy as a breath.</p><h3>Conclusion</h3><p>It’s a shock to me how easy and intuitive it could be in Heptabase to create a workspace and focus on writing. I believe anybody with note-taking experience could learn something from Heptabase’s design.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87f9c2bfb257" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Thunderbird UI Customization: Migrate from 60 to 68]]></title>
            <link>https://medium.com/@reorx/thunderbird-ui-customization-migrate-from-60-to-68-da5f107b01f8?source=rss-31cf00c8e47b------2</link>
            <guid isPermaLink="false">https://medium.com/p/da5f107b01f8</guid>
            <category><![CDATA[customization]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[thunderbird]]></category>
            <dc:creator><![CDATA[Reorx Xiao]]></dc:creator>
            <pubDate>Sun, 10 Nov 2019 08:30:10 GMT</pubDate>
            <atom:updated>2019-11-10T08:39:00.189Z</atom:updated>
            <content:encoded><![CDATA[<p>In Thunderbird (abbr as TB) 60, there are generally two ways to customize the UI:</p><ol><li>Use <a href="https://github.com/Aris-t2/CustomizeMyBird">CustomizeMyBird</a> addon.</li><li>Write code in chrome/userChrome.css under profile directory.</li></ol><p>The first way is essentially the second way, only easier to use, and has live preview which means you don’t need to restart TB again and again to view what’s changed.</p><p>Since TB 68 was released recently, many people who upgraded to that version have found CustomizeMyBird stoped working due to incompatibility. Here I will introduce the migration steps to take for some typical scenarios you may encounter.</p><h4>You placed all your customization code in userChrome.css</h4><p>Congrats, your TB should look just as expected. If not, you only need to set the option toolkit.legacyUserProfileCustomizations.stylesheets as true in ConfigEditor, which can be opened from Preferences → Advanced → General → ConfigEditor .</p><h4>You used CustomizeMyBird and tweaked without code</h4><p>Currently CustomizeMyBird does not support TB 68+, and the author has no plan to do that. Fortunately the author created another repo called <a href="https://github.com/Aris-t2/CustomCSSforTb">CustomCSSForTb</a>, it’s a bunch of css files rather than a plugin, but most of CustomizeMyBird’s functionality should be involved. Check the <a href="https://github.com/Aris-t2/CustomCSSforTb#how-to-use-custom-user-styles">project</a> to see how to get it work.</p><h4>You placed your customization code in CustomizedMyBird</h4><p>The solution is simple: get the code and put them into chrome/userChrome.css . What may bother is how to get the code in the disabled CustomizeMyBird.</p><p>First you need to open the profile directory: click the three-line menu and follow Help → Troubleshooting Information , on the new page, click Show in Finder button besides “Profile Folder” line.</p><p>Then open prefs.js file and search for extensions.customizemybirdextension.customcsstb, you should find something like below:</p><pre>user_pref(&quot;extensions.customizemybirdextension.customcsstb&quot;, &quot;#threadTree treechildren {\n    font-size: 13px !important;\n    font-family: \&quot;Helvetica Neue\&quot;;\n}\n#threadTree treechildren::-moz-tree-row {\n    height: 32px !important;\n}\n#threadTree treechildren::-moz-tree-cell-text(unread) {\n    color: #222 !important;\n}\n\n#folderTree treechildren {\n    font-size: 13px !important;\n}\n\n#folderTree treechildren::-moz-tree-row {\n    height: 25px !important;\n}\n&quot;);</pre><p>Copy the second parameter of user_pref, print it in a console like Python or Node:</p><pre>Python 3.7.1 (default, Aug 31 2019, 17:32:38)<br>[Clang 10.0.1 (clang-1001.0.46.4)] on darwin<br>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>&gt;&gt;&gt; print(&quot;#threadTree treechildren {\n    font-size: 13px !important;\n    font-family: \&quot;Helvetica Neue\&quot;;\n}\n#threadTree treechildren::-moz-tree-row {\n    height: 32px !important;\n}\n#threadTree treechildren::-moz-tree-cell-text(unread) {\n    color: #222 !important;\n}\n\n#folderTree treechildren {\n    font-size: 13px !important;\n}\n\n#folderTree treechildren::-moz-tree-row {\n    height: 25px !important;\n}\n&quot;)<br>#threadTree treechildren {<br>    font-size: 13px !important;<br>    font-family: &quot;Helvetica Neue&quot;;<br>}<br>#threadTree treechildren::-moz-tree-row {<br>    height: 32px !important;<br>}<br>#threadTree treechildren::-moz-tree-cell-text(unread) {<br>    color: #222 !important;<br>}</pre><pre>#folderTree treechildren {<br>    font-size: 13px !important;<br>}</pre><pre>#folderTree treechildren::-moz-tree-row {<br>    height: 25px !important;<br>}</pre><p>Voilà! The printed result is what we should put into chrome/userChrome.css to recover the customization.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da5f107b01f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>