<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Clay on Ken Huang</title>
    <link>https://blog.kenhuang.io/tags/clay/</link>
    <description>Recent content in Clay on Ken Huang</description>
    <generator>Hugo</generator>
    <language>en</language>
    <managingEditor>kenhuang512@gmail.com (Ken Huang)</managingEditor>
    <webMaster>kenhuang512@gmail.com (Ken Huang)</webMaster>
    <lastBuildDate>Sun, 09 Mar 2025 17:25:04 +0800</lastBuildDate>
    <atom:link href="https://blog.kenhuang.io/tags/clay/rss.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>A Few Quick Notes About babashka/fs</title>
      <link>https://blog.kenhuang.io/blog/2024-12-07-babashka-fs-notes/</link>
      <pubDate>Sat, 07 Dec 2024 22:24:41 +0800</pubDate><author>kenhuang512@gmail.com (Ken Huang)</author>
      <guid>https://blog.kenhuang.io/blog/2024-12-07-babashka-fs-notes/</guid>
      <description>&lt;p&gt;&#xA;Recently I&amp;#39;ve used &lt;a href=&#34;https://github.com/babashka/fs/blob/master/API.md&#34;&gt;babashka/fs&lt;/a&gt; a little bit, here are some quick notes for it:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Path vs File.&#xA;&#xA;Use Path whenever possible, according to &lt;a href=&#34;https://stackoverflow.com/a/26658436&#34;&gt;this SO answer to &amp;#34;Java: Path vs File&amp;#34;&lt;/a&gt;.&#xA;&#xA;This is actually Java related.&lt;/li&gt;&#xA;&lt;li&gt;It&amp;#39;s ok to use a &lt;code class=&#34;verbatim&#34;&gt;path&lt;/code&gt; as a key for a clojure map.&#xA;&#xA;At my first try, I somehow came to the conclusion that it&amp;#39;s not ok, while I was refactoring the &lt;a href=&#34;https://github.com/scicloj/clay/blob/main/src/scicloj/clay/v2/live_reload.clj&#34;&gt;live reload&lt;/a&gt; for clay. And later I found that it&amp;#39;s totally fine to use it as a key. 😞&lt;/li&gt;&#xA;&lt;li&gt;Use &lt;a href=&#34;https://github.com/babashka/fs/blob/master/API.md#babashka.fs/path&#34;&gt;fs/path&lt;/a&gt; to construct file/directory paths, for example, &lt;code class=&#34;verbatim&#34;&gt;(fs/path &amp;#34;/tmp&amp;#34; &amp;#34;foo&amp;#34; &amp;#34;bar&amp;#34; &amp;#34;baz.clj&amp;#34;)&lt;/code&gt; will result in a path object for &lt;code class=&#34;verbatim&#34;&gt;/tmp/foo/bar/baz.clj&lt;/code&gt; on linux.&#xA;&#xA;If you&amp;#39;re coming from Python, it might remind you of &lt;a href=&#34;https://docs.python.org/3/library/os.path.html&#34;&gt;os.path.join(path, *paths)&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Use &lt;code class=&#34;verbatim&#34;&gt;fs/createdirs&lt;/code&gt; for &lt;code class=&#34;verbatim&#34;&gt;mkdir -p&lt;/code&gt;, though its name is a bit misleading, I first thought it&amp;#39;s for creating a few dirs.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code class=&#34;verbatim&#34;&gt;fs/with-temp-dir&lt;/code&gt; is convenient for &lt;a href=&#34;https://github.com/scicloj/clay/blob/main/test/scicloj/clay/v2/live_reload_test.clj&#34;&gt;creating tests&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
    <item>
      <title>Doing Unit test in Clojure Is Easy</title>
      <link>https://blog.kenhuang.io/blog/2024-11-27-clojure-unit-test/</link>
      <pubDate>Thu, 28 Nov 2024 23:10:56 +0800</pubDate><author>kenhuang512@gmail.com (Ken Huang)</author>
      <guid>https://blog.kenhuang.io/blog/2024-11-27-clojure-unit-test/</guid>
      <description>&lt;p&gt;&#xA;While refactoring the &lt;a href=&#34;https://github.com/scicloj/clay/blob/main/src/scicloj/clay/v2/live_reload.clj&#34;&gt;live reload&lt;/a&gt; feature of &lt;a href=&#34;https://github.com/scicloj/clay&#34;&gt;Clay&lt;/a&gt;, I realized I&amp;#39;d better break long functions into smaller and functional ones (as many as I can), which is also a &lt;a href=&#34;https://guide.clojure.style/#be-functional&#34;&gt;common practice&lt;/a&gt; in the clojure community.&lt;/p&gt;&#xA;&lt;p&gt;&#xA;Small pure functions not only are easy to verify on the development process (using a REPL), but also are easy to test. And unit tests are easy to write in clojure, just use &lt;code class=&#34;verbatim&#34;&gt;deftest&lt;/code&gt; from &lt;code class=&#34;verbatim&#34;&gt;clojure.test&lt;/code&gt;, a very basic one looks like this:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Clj-async-profiler Rocks</title>
      <link>https://blog.kenhuang.io/blog/2024-11-28-beholder-clj-async-profiler/</link>
      <pubDate>Thu, 28 Nov 2024 22:23:32 +0800</pubDate><author>kenhuang512@gmail.com (Ken Huang)</author>
      <guid>https://blog.kenhuang.io/blog/2024-11-28-beholder-clj-async-profiler/</guid>
      <description>&lt;p&gt;&#xA;While developing the live reload feature for &lt;a href=&#34;https://scicloj.github.io/clay/&#34;&gt;Clay&lt;/a&gt;, a minimalistic Clojure tool for data visualization and literate programming, I found that it constantly takes ~1 minute for &lt;a href=&#34;https://github.com/nextjournal/beholder&#34;&gt;beholder&lt;/a&gt; to watch a directory. After some code inspect, I was still having no idea why it happened.&lt;/p&gt;&#xA;&lt;p&gt;&#xA;So I decided to use a profiler to find out what&amp;#39;s going one under the hood, and Google immediately took me to &lt;a href=&#34;https://clojure-goes-fast.com/kb/profiling/clj-async-profiler/&#34;&gt;clj-async-profiler&lt;/a&gt;. It&amp;#39;s easy to set up following its &lt;a href=&#34;https://clojure-goes-fast.com/kb/profiling/clj-async-profiler/basic-usage/&#34;&gt;basic usage docs&lt;/a&gt;:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
