<?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"><channel><title><![CDATA[aprksy's blog]]></title><description><![CDATA[just an average to mediocre coder]]></description><link>https://blog.aprksy.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 03:40:11 GMT</lastBuildDate><atom:link href="https://blog.aprksy.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How I Stopped Drowning in Incus Containers (and Started Loving My Homelab Again)]]></title><description><![CDATA[A few months ago, I had a problem:
I couldn’t remember what half my containers were for. Seriously.
I’d run incus list and see:
+-----------------+---------+----------------------+-----------+-----------+
|      NAME       |  STATE  |       IPV4     ...]]></description><link>https://blog.aprksy.dev/how-i-stopped-drowning-in-incus-containers-and-started-loving-my-homelab-again</link><guid isPermaLink="true">https://blog.aprksy.dev/how-i-stopped-drowning-in-incus-containers-and-started-loving-my-homelab-again</guid><category><![CDATA[incus ]]></category><category><![CDATA[Homelab]]></category><category><![CDATA[containers]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[Agung Prakasya]]></dc:creator><pubDate>Sun, 05 Oct 2025 07:31:24 GMT</pubDate><content:encoded><![CDATA[<p>A few months ago, I had a problem:</p>
<p>I couldn’t remember what half my containers were for. Seriously.</p>
<p>I’d run <code>incus list</code> and see:</p>
<pre><code class="lang-bash">+-----------------+---------+----------------------+-----------+-----------+
|      NAME       |  STATE  |       IPV4           |   TYPE    | SNAPSHOTS |
+-----------------+---------+----------------------+-----------+-----------+
| web01           | RUNNING | 10.209.83.196 (eth0) | CONTAINER | 0         |
| api-dev         | RUNNING | 10.209.83.177 (eth0) | CONTAINER | 0         |
| tile-cache      | RUNNING | 10.209.83.201 (eth0) | CONTAINER | 0         |
| db-geo          | RUNNING | 10.209.83.155 (eth0) | CONTAINER | 0         |
| temp-test       | STOPPED |                      | CONTAINER | 0         |
| legacy-app      | STOPPED |                      | CONTAINER | 0         |
        ...           ...             ...               ... 
+-----------------+---------+----------------------+-----------+-----------+
</code></pre>
<p>And I’d stare at it like…<br />- <em>“Wait — does</em> <code>api-dev</code> use <code>db-geo</code>? Or was that <code>web01</code>?”<br />- <em>“Is</em> <code>tile-cache</code> still needed? Who uses it?”<br />- <em>“Why is there a</em> <code>temp-test</code> from six weeks ago??”</p>
<p>My lab had become a <strong>container graveyard</strong> — full of forgotten services, scattered docs, and tribal knowledge only I (barely) remembered.</p>
<h3 id="heading-the-breaking-point">The Breaking Point</h3>
<p>One day, I cloned a container for a new project, started it up… and got this SSH warning:</p>
<pre><code class="lang-bash">WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
</code></pre>
<p>Because — duh — it inherited the same SSH host keys as the original. And that was it. I’d had enough.</p>
<p>I wanted:</p>
<ul>
<li><p>To know what each container was for</p>
</li>
<li><p>To not break things by accident</p>
</li>
<li><p>To spin up full environments with one command</p>
</li>
<li><p>To stop guessing</p>
</li>
</ul>
<p>So I built <strong>LabKit</strong>.</p>
<h3 id="heading-what-is-labkit">What Is labkit?</h3>
<p><code>labkit</code> is not another orchestration tool. It’s not Kubernetes. It’s not even trying to be.</p>
<p>It’s a <strong>lightweight, Git-powered wrapper around Incus</strong> that helps you treat your containers like actual projects — not just random Linux boxes.</p>
<p>Think of it like <code>create-react-app</code>, but for full development environments.</p>
<p>With <code>labkit</code>, I now do this:</p>
<pre><code class="lang-bash">labkit new backend-api
<span class="hljs-built_in">cd</span> backend-api
labkit node add postgres
labkit node add api-server
labkit requires add tile-server
labkit up
</code></pre>
<p>And boom — my whole stack is up, documented, and connected.</p>
<h3 id="heading-how-it-works-without-the-boring-parts">How It Works (Without the Boring Parts)</h3>
<p>Every lab is just a folder with:</p>
<pre><code class="lang-bash">backend-api/
├── lab.yaml               <span class="hljs-comment"># config: template, deps</span>
├── nodes/
│   ├── postgres/          <span class="hljs-comment"># auto-created</span>
│   │   ├── manifest.yaml  <span class="hljs-comment"># "This is a PostGIS DB"</span>
│   │   └── README.md      <span class="hljs-comment"># Usage notes, queries, tips</span>
│   └── api-server/
│       ├── manifest.yaml
│       └── README.md
└── shared/                <span class="hljs-comment"># scripts, configs, certs</span>
</code></pre>
<p>When I run <code>labkit up</code>:</p>
<ul>
<li><p>It starts <code>postgres</code> and <code>api-server</code></p>
</li>
<li><p>But also checks if <code>tile-server</code> (a shared map tile server) is running — and starts it if needed</p>
</li>
<li><p>All docs are mounted into the containers at <code>/lab/node</code> so anyone can read them</p>
</li>
<li><p>And if I ever forget what <code>api-server</code> does? I just <code>cat /lab/node/</code><a target="_blank" href="http://README.md"><code>README.md</code></a></p>
</li>
</ul>
<p>No more Slack pings. No more digging through notes.</p>
<h3 id="heading-the-magic-shared-infrastructure-that-doesnt-get-killed">The Magic: Shared Infrastructure That Doesn’t Get Killed</h3>
<p>Here’s my favorite part:</p>
<p>I have a <strong>shared OSM tile server</strong> used by three different labs.</p>
<p>Before <code>labkit</code>, if I ran <code>incus delete --all</code>, I’d accidentally kill it.</p>
<p>Now, I tag it:</p>
<pre><code class="lang-bash">incus config <span class="hljs-built_in">set</span> tile-server user.pinned=<span class="hljs-literal">true</span>
incus config <span class="hljs-built_in">set</span> tile-server user.required_by=backend-api,frontend-map,analytics-dashboard
</code></pre>
<p>And when I run <code>labkit down</code> in any lab?</p>
<ul>
<li><p>It stops local containers</p>
</li>
<li><p>Leaves <code>tile-server</code> alone</p>
</li>
<li><p>Even if it’s not “in” that lab</p>
</li>
</ul>
<p>It just knows: <em>“Someone else needs this.”</em></p>
<h3 id="heading-bonus-start-only-what-you-need">Bonus: Start Only What You Need</h3>
<p>Sometimes I don’t want the whole stack.</p>
<p>So I added:</p>
<pre><code class="lang-bash">labkit up --only api-server
</code></pre>
<p>Perfect for testing one service without bringing up five others.</p>
<p>And yes — <code>--dry-run</code> works everywhere:</p>
<pre><code class="lang-bash">labkit down --only postgres --dry-run
</code></pre>
<p>Output:</p>
<pre><code class="lang-bash">Planned actions:
  Stop <span class="hljs-built_in">local</span> node: postgres
DRY RUN: No changes applied
</code></pre>
<p>Peace of mind before pressing “go”.</p>
<h3 id="heading-why-this-matters">Why This Matters</h3>
<p><code>labkit</code> didn’t just organize my containers. It changed how I work.</p>
<p>Now:</p>
<ul>
<li><p>New projects take minutes, not hours</p>
</li>
<li><p>I never lose context</p>
</li>
<li><p>I can safely clean up old stuff because I know what depends on what</p>
</li>
<li><p>Documentation lives where it’s used — inside the environment</p>
</li>
<li><p>And yes, no more SSH host key warnings 😌</p>
</li>
</ul>
<p>It’s not fancy. It doesn’t scale to 1000 nodes.</p>
<p>But for <strong>real developers managing real homelabs</strong>, it’s exactly what we need.</p>
<h3 id="heading-want-to-try-it">Want to Try It?</h3>
<p>Check out <a target="_blank" href="https://github.com/aprksy/labkit">github.com/aprksy/labkit</a> or the project page https://labkit.aprksy.dev</p>
<p>Then:</p>
<pre><code class="lang-bash">labkit new myproject
labkit node add web
labkit up
</code></pre>
<p>That’s it.</p>
<p>No YAML sprawl. No complex CRDs. Just containers that make sense.</p>
<hr />
<h3 id="heading-final-thought">Final Thought</h3>
<p>We spend so much time building apps that we forget to build good environments for building them.</p>
<p><code>labkit</code> is my way of fixing that. And honestly? I finally enjoy using my homelab again.</p>
<p>No more chaos. Just clarity.</p>
<p>I guess I will write another post on how I setup my homelabs in more detailed.</p>
]]></content:encoded></item><item><title><![CDATA[The C++ `main` function]]></title><description><![CDATA[When we write program using C, C++, Go, Java and many others, we mostly will interact with this function. Some libraries or frameworks minimize the interaction though, to let programmers to focus to the business layer. However, they do not replace th...]]></description><link>https://blog.aprksy.dev/the-c-main-function</link><guid isPermaLink="true">https://blog.aprksy.dev/the-c-main-function</guid><category><![CDATA[C++]]></category><category><![CDATA[learning]]></category><category><![CDATA[main-function]]></category><dc:creator><![CDATA[Agung Prakasya]]></dc:creator><pubDate>Sun, 11 Aug 2024 17:30:02 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1723403544281/718a7e38-dc12-4562-ba91-d4be6b3c4c10.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we write program using C, C++, Go, Java and many others, we mostly will interact with this function. Some libraries or frameworks minimize the interaction though, to let programmers to focus to the business layer. However, they do not replace the <code>main</code> function. In this article I'm trying to document my learning process about the <code>main</code> function, which I used to just use it without any deeper concern.</p>
<blockquote>
<p>I'm no expert in this field. This writing is an effort to document my learning process from multiple sources and will be updated when I get more comprehension on the topic. Feel free to correct me, or comment.</p>
</blockquote>
<h2 id="heading-what-is-it">What is it?</h2>
<p>The <code>main</code> function is the entry-point of a program, where the instructions to be executed. However this is not the case with libraries, they don't have one. What if a program doesn't have one? It simply won't compile.</p>
<h2 id="heading-how-is-it-declared">How is it declared?</h2>
<p>Generally the <code>main</code> function is declared like the following:</p>
<pre><code class="lang-c++"><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{ ... }

<span class="hljs-comment">// or</span>

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">(<span class="hljs-keyword">int</span> argc, <span class="hljs-keyword">char</span>* argv[])</span> </span>{ ... }

<span class="hljs-comment">// or, with common POSIX extension</span>

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">(<span class="hljs-keyword">int</span> argc, <span class="hljs-keyword">char</span>* argv[], <span class="hljs-keyword">char</span>* envp[])</span> </span>{ ... }
</code></pre>
<h3 id="heading-the-name-main">The name <code>main</code></h3>
<p>The name <code>main</code> was inherited from C, and it escapes from all the revision and changes between standards, except got a little bit annoyance in MSVC++ which they introduce <code>wmain</code> for arguments that supports wide chars.</p>
<h3 id="heading-the-signature">The signature</h3>
<p>The signature was also inherited, this time from the old days of <em>C++98</em>, and the third version also accomodating POSIX extension. The following would be the explanation of the signature elements.</p>
<h4 id="heading-int-return-value"><code>int</code> return value</h4>
<blockquote>
<p>In the early days, we've seen something like <code>void main(...)</code>. However, using it in modern C++ will raise an error.</p>
</blockquote>
<p>This is the return value that C++98 and above expects. The <code>int</code> return type, as I've read somewhere, while it does not direct mapping with the OS process exit statuses, it's for easy conversion and more intuitively interpretable. But I think it's more of a guess of mine, if you know the reason behind it, please let me know.</p>
<h4 id="heading-int-argc-argument"><code>int argc</code> argument</h4>
<p>This is the count of entire argument including the executable name itself. Thus,</p>
<pre><code class="lang-bash">./cut -d<span class="hljs-string">' '</span> -f2,3,4 data.csv
</code></pre>
<p>will have <code>argc</code> equals to 4.</p>
<h4 id="heading-char-argv-argument"><code>char* argv[]</code> argument</h4>
<p>This is the argument values, packed in array. The first element of the array will always be the program name. Hence, from the previous example it will be equal to <code>./cut</code>, and the next in sequence will be <code>-d' '</code>, <code>-f2,3,4</code> and the last one will be <code>data.csv</code>. What about the next element, <code>argv[argc]</code>? It is guaranteed to be <code>null</code>.</p>
<h4 id="heading-char-envp-argument"><code>char* envp[]</code> argument</h4>
<p>This argument does not come from the C++ standard, but commonly used and as part of the POSIX extension. This parameter will be the storage of the frozen version on user's environment variables, including those provided when executing a program like this:</p>
<pre><code class="lang-bash">EDITOR=/bin/vim visudo
</code></pre>
<p>The <code>envp</code> array has the possibility to be empty. Also, because of the absence of the count parameter (like <code>argc</code> to <code>argv</code>), programmer shall loop through the array until finds <code>null</code> which is the indicator that there's no more value to collect. </p>
<p>However based on many discussion on the internet, many of them discourage to use this as it's not portable between systems. Some also pointed out about overflowing possibilities. I'd like to hear from you too if you have something in mind about this.</p>
<h2 id="heading-how-does-it-flow">How does it flow?</h2>
<h3 id="heading-what-happened-before-main-begins">What happened before <code>main</code> begins?</h3>
<p>There are some activities happens when we executed a program. The following are the activities that is performed before it entering the <code>main</code> function.</p>
<ul>
<li>Linker takes the object files and libraries the program linked against, and combined them into an executable program. After that, loader will load the program into the memory.</li>
<li>Memory is allocated both for the code, data and stack.</li>
<li>Global variables are initialized with their corresponding initializers, and for the uninitialized, they will be set to zeros. On MSVC++, all static members of classes will also be initialized here similar to global variables. However, other compilers decide to perform this at compile time.</li>
<li>Function pointers are set up, and virtual tables are constructed for <em>dynamic dispatch</em>. </li>
<li>Entering the executable entry point as OS expects it, that is the <code>_start</code> section in the assembly code version of our program. In this section, it will initialize C++ runtime library required for running the program, and also prepare the arguments for our actual <code>main</code> function and finally invoke it.</li>
</ul>
<h3 id="heading-what-happened-after-main-ends">What happened after <code>main</code> ends?</h3>
<ul>
<li>The destructor of all globals and static objects will be called in reversed order as they were created to clean up the resources they may allocated.</li>
<li>After that the C++ runtime library will make system call to OS to indicate that the program is terminating, typically will take the <code>main</code> return value as its parameter.</li>
<li>OS will then update the process status to terminated and marks it with the <code>main</code> function return value.</li>
</ul>
<h2 id="heading-what-can-we-do-with-it">What can we do with it?</h2>
<ul>
<li>Declare the function body as <code>try/catch</code> block:</li>
</ul>
<pre><code class="lang-c++"><span class="hljs-comment">// this example is borrowed from reference 1</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdexcept&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;iostream&gt;</span></span>

<span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">Q</span> {</span>
    ~Q() <span class="hljs-keyword">noexcept</span>(<span class="hljs-literal">false</span>) {
        <span class="hljs-keyword">throw</span> <span class="hljs-built_in">std</span>::runtime_error(<span class="hljs-string">"will escape"</span>);
    };
} q;

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> <span class="hljs-keyword">try</span> </span>{
    <span class="hljs-keyword">throw</span> <span class="hljs-built_in">std</span>::runtime_error(<span class="hljs-string">"will be caught"</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::exception&amp; e) {
    <span class="hljs-comment">// will caught the runtime error from main, but not from ~Q</span>
    <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cerr</span> &lt;&lt; <span class="hljs-string">"caught: "</span> &lt;&lt; e.what() &lt;&lt; <span class="hljs-built_in">std</span>::<span class="hljs-built_in">endl</span>;
}
</code></pre>
<p>here's the output of the above program:</p>
<pre><code>caught: will be caught
terminate called after throwing an instance <span class="hljs-keyword">of</span> <span class="hljs-string">'std::runtime_error'</span>
  what():  will <span class="hljs-built_in">escape</span>
<span class="hljs-attr">make</span>: *** [Makefile:<span class="hljs-number">14</span>: <span class="hljs-keyword">try</span>-main.x] Aborted (core dumped)
</code></pre><p>A little explanation of the above code:</p>
<ul>
<li>entering <code>main</code></li>
<li>throw exception, hopefully be caught</li>
<li>catching exception: yes, it is caught</li>
<li>is there user code remaing to execute? no</li>
<li><code>main</code> exiting...</li>
<li>program do some house keeping, found <code>q</code> of type <code>Q</code>, which throws exception in its d'tor</li>
<li>destroy <code>q</code>, hence, throws exception <code>"will escape"</code></li>
<li>is there anymore to clean up? no</li>
<li>call terminate</li>
</ul>
<h2 id="heading-what-can-not-we-do-with-it">What can NOT we do with it?</h2>
<h3 id="heading-naming">Naming</h3>
<ul>
<li>Cannot be named, thus can't take its address, can't also be called recursively, or get the type of it.</li>
<li>Cannot use the name main for other function in global namespace or anything with C-linkage</li>
</ul>
<h3 id="heading-construction">Construction</h3>
<p><code>main</code> can't be declared as <code>inline</code>, <code>static</code>, <code>constexpr</code>, <code>consteval</code> or with <code>auto</code> or as a coroutine. </p>
<h2 id="heading-reference">Reference</h2>
<ol>
<li><a target="_blank" href="https://simontoth.substack.com/p/daily-bite-of-c-main?utm_source=post-email-title&amp;publication_id=1177271&amp;post_id=143546210&amp;utm_campaign=email-post-title&amp;isFreemail=true&amp;r=2a3bae&amp;triedRedirect=true">Daily bit(e) of C++ | <code>main</code></a></li>
<li><a target="_blank" href="https://learn.microsoft.com/en-us/cpp/cpp/main-function-command-line-args?view=msvc-170"><code>main</code> function and command-line arguments</a></li>
<li><a target="_blank" href="https://en.cppreference.com/w/c/language/main_function">Main function</a></li>
</ol>
]]></content:encoded></item><item><title><![CDATA[C++ Uniform Initialization]]></title><description><![CDATA[Initialization is the act of providing a starting value to a variable or object during its creation. This value determines the initial state of the variable or object in memory and ensures it's in a usable condition before any operations are performe...]]></description><link>https://blog.aprksy.dev/c-uniform-initialization</link><guid isPermaLink="true">https://blog.aprksy.dev/c-uniform-initialization</guid><category><![CDATA[C++]]></category><category><![CDATA[uniform-initialization ]]></category><category><![CDATA[learning]]></category><dc:creator><![CDATA[Agung Prakasya]]></dc:creator><pubDate>Mon, 22 Jul 2024 19:42:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1723436262683/e75af6d6-25e5-48d8-905a-d1b65911134e.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Initialization is the act of providing a starting value to a variable or object during its creation. This value determines the initial state of the variable or object in memory and ensures it's in a usable condition before any operations are performed on it.</p>
<blockquote>
<p>I'm no expert in this field. This writing is an effort to document my learning process from multiple sources and will be updated as I gain more understanding of the topic. Feel free to correct me or comment.</p>
</blockquote>
<p>There are two type of initialization mechanisms, <code>direct initialization</code> and <code>copy initialization</code>.</p>
<ol>
<li><p><strong>Direct initialization</strong> is a mechanism that explicitly use the constructor to construct the value of the variable or object.</p>
</li>
<li><p><strong>Copy initialization</strong>, on the other hand, is a mechanism that use other value or object to construct the value or object.</p>
</li>
</ol>
<p>Now, <em>what's the uniform term refer to?</em> It's uniform by mean of there's no difference between initializing variables of regular types, or custom types (classes, arrays, maps etc.).</p>
<h2 id="heading-how">How?</h2>
<p>By using the <em>brace initialization</em> <code>{}</code> (introduced in <code>C++11</code>, improved in <code>C++20</code>).</p>
<pre><code class="lang-cpp"><span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> direct {<span class="hljs-string">"this is direct initialization"</span>};
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> copy = {<span class="hljs-string">"this is copy initialization"</span>};

<span class="hljs-keyword">int</span> i {<span class="hljs-number">10</span>};
<span class="hljs-keyword">int</span> n = {<span class="hljs-number">1</span>};

<span class="hljs-keyword">float</span> f {<span class="hljs-number">22.7</span>};
<span class="hljs-keyword">float</span> c = {<span class="hljs-number">299792458</span>};

<span class="hljs-keyword">int</span> array1[<span class="hljs-number">5</span>] {<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>};
<span class="hljs-keyword">int</span>* array2[<span class="hljs-number">3</span>] = <span class="hljs-keyword">new</span> <span class="hljs-keyword">int</span>[<span class="hljs-number">3</span>]{<span class="hljs-number">10</span>, <span class="hljs-number">20</span>, <span class="hljs-number">30</span>};

<span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span>&lt;<span class="hljs-keyword">int</span>&gt; vector1 {<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>};
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">map</span>&lt;<span class="hljs-keyword">int</span>, <span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span>&gt; map1 {{<span class="hljs-number">1</span>, <span class="hljs-string">"one"</span>}, {<span class="hljs-number">2</span>, <span class="hljs-string">"two"</span>}};

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">foo</span> {</span>
    <span class="hljs-keyword">public</span>:
        foo(): _i(<span class="hljs-number">0</span>), _f(<span class="hljs-number">0.0</span>) {};
        foo(<span class="hljs-keyword">int</span> i, <span class="hljs-keyword">float</span> f): _i(i), _f(f) {};

    <span class="hljs-keyword">private</span>:
        <span class="hljs-keyword">int</span> _i;
        <span class="hljs-keyword">float</span> _f;
}

foo {};
foo {<span class="hljs-number">4</span>, <span class="hljs-number">29.3</span>};
</code></pre>
<h2 id="heading-why">Why?</h2>
<p>The following are the reasons why you would use it most of the time.</p>
<h4 id="heading-consistent-syntax">Consistent syntax</h4>
<p>It provides same or at least intuitive syntax for variables initialization of various data types.</p>
<pre><code class="lang-cpp"><span class="hljs-comment">// integer</span>
<span class="hljs-keyword">int</span> i {<span class="hljs-number">1</span>};
<span class="hljs-keyword">int</span>* iref {<span class="hljs-number">12</span>};

<span class="hljs-comment">// floating points</span>
<span class="hljs-keyword">float</span> f {<span class="hljs-number">22.01</span>};
<span class="hljs-keyword">double</span> f {<span class="hljs-number">3.1416</span>};

<span class="hljs-comment">// string</span>
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> name {<span class="hljs-string">"Agung Prakasya"</span>};
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> email {<span class="hljs-string">"agung@example.com"</span>};

<span class="hljs-comment">// array</span>
<span class="hljs-keyword">int</span>* heights[<span class="hljs-number">5</span>] {<span class="hljs-number">14</span>, <span class="hljs-number">22</span>, <span class="hljs-number">21</span>, <span class="hljs-number">15</span>, <span class="hljs-number">17</span>};

<span class="hljs-comment">// map</span>
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">map</span>&lt;<span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span>, <span class="hljs-keyword">float</span>&gt; dict {{<span class="hljs-string">"earth"</span>, <span class="hljs-number">67.5</span>}, {<span class="hljs-string">"mars"</span>, <span class="hljs-number">21.7</span>}, {<span class="hljs-string">"venus"</span>, <span class="hljs-number">33.8</span>}};

<span class="hljs-comment">// vector</span>
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span>&lt;<span class="hljs-keyword">double</span>&gt; distances {<span class="hljs-number">12.6</span>, <span class="hljs-number">44.2</span>, <span class="hljs-number">15.7</span>};

<span class="hljs-comment">// object (from previous section)</span>
foo {};
foo {<span class="hljs-number">4</span>, <span class="hljs-number">29.3</span>};

<span class="hljs-comment">// and so on...</span>
</code></pre>
<h4 id="heading-doesnt-allow-narrowing-type-conversion">Doesn't allow narrowing type conversion</h4>
<p>In C++, narrowing conversion is a <em>potentially unsafe numeric conversion where the destination type may not be able to hold all the values of the source type</em>. The following code won't compile, that is to prevent unintentional typecast which can produce error in further flow of the program.</p>
<pre><code class="lang-cpp"><span class="hljs-comment">// initialize variable d as double with value 10.71 </span>
<span class="hljs-keyword">double</span> d {<span class="hljs-number">10.71</span>};

<span class="hljs-comment">// create variable i as int, with intention to initialize</span>
<span class="hljs-comment">// with value 10 (integer).</span>
<span class="hljs-comment">// this won't compile.</span>
<span class="hljs-keyword">int</span> i {d};
</code></pre>
<p>However, if it's intentionally to cast the value, we can achieve that with the following:</p>
<pre><code class="lang-cpp"><span class="hljs-comment">// initialize variable d as double with value 10.71 </span>
<span class="hljs-keyword">double</span> d {<span class="hljs-number">10.71</span>};

<span class="hljs-comment">// double to int implicit conversion</span>
<span class="hljs-keyword">int</span> i = d;

<span class="hljs-comment">// modern C++ typecasting - this is the best practice</span>
<span class="hljs-keyword">int</span> i {<span class="hljs-keyword">static_cast</span>&lt;<span class="hljs-keyword">int</span>&gt;(d)};

<span class="hljs-comment">// C style typecast</span>
<span class="hljs-keyword">int</span> i {(<span class="hljs-keyword">int</span>)d};

<span class="hljs-comment">// old C++ style typecast</span>
<span class="hljs-keyword">int</span> i {<span class="hljs-keyword">int</span>(d)};
</code></pre>
<h4 id="heading-fixes-most-vexing-parse">Fixes most vexing parse</h4>
<p>There's a rule in C++ parser that, every time it finds something considered as function declaration, then treat it as function declaration.</p>
<p>Now consider the following example:</p>
<pre><code class="lang-cpp"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">foo</span> {</span>
    <span class="hljs-keyword">public</span>:
        foo() {...};
    <span class="hljs-keyword">private</span>:
        <span class="hljs-function"><span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span>&lt;<span class="hljs-keyword">int</span>&gt; <span class="hljs-title">v</span><span class="hljs-params">(<span class="hljs-number">3</span>, <span class="hljs-number">0</span>)</span></span>;
}
</code></pre>
<p>The code ablve won't compile. The vector <code>v</code> initialization will be treated as function declaration, while it's not.</p>
<p>To achieve the vector v initialization we can use some other approach. First, move the initialization into the constructor:</p>
<pre><code class="lang-cpp"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">foo</span> {</span>
    <span class="hljs-keyword">public</span>:
        foo(): v(<span class="hljs-number">3</span>, <span class="hljs-number">0</span>) {};
    <span class="hljs-keyword">private</span>:
        <span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span>&lt;<span class="hljs-keyword">int</span>&gt; v;
}
</code></pre>
<p>second, use the copy initialization:</p>
<pre><code class="lang-cpp"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">foo</span> {</span>
    <span class="hljs-keyword">public</span>:
        foo() {};
    <span class="hljs-keyword">private</span>:
        <span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span>&lt;<span class="hljs-keyword">int</span>&gt; v = <span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span>&lt;<span class="hljs-keyword">int</span>&gt;(<span class="hljs-number">3</span>, <span class="hljs-number">0</span>);
}
</code></pre>
<p>third, use the uniform initialization:</p>
<pre><code class="lang-cpp"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">foo</span> {</span>
    <span class="hljs-keyword">public</span>:
        foo() {};
    <span class="hljs-keyword">private</span>:
        <span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span>&lt;<span class="hljs-keyword">int</span>&gt; v {<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>};
}
</code></pre>
<h3 id="heading-why-not">Why not?</h3>
<p>With all the pros above, still, we need to be aware that there are some cases that we need to not just used it along with other conveniences. Actually the following are just special cases where if all the condition occur, we might need to use another approach.</p>
<h4 id="heading-auto-type">Auto type</h4>
<p>While using <code>auto</code> in variable declaration is convenience, we might need to sacrifice it when using uniform initialization. Otherwise, we might get the variable type not as intended, or the code doesn't even compile.</p>
<pre><code class="lang-cpp"><span class="hljs-comment">// var_name is of type int</span>
<span class="hljs-keyword">auto</span> var_name {<span class="hljs-number">1</span>};

<span class="hljs-comment">// var_name is of type std::initializer_list&lt;int&gt;</span>
<span class="hljs-keyword">auto</span> var_name = {<span class="hljs-number">2</span>};

<span class="hljs-comment">// doesn't compile, error variable contains multiple expressions</span>
<span class="hljs-keyword">auto</span> var_name {<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>};

<span class="hljs-comment">// var_name is of type std::initializer_list&lt;int&gt;</span>
<span class="hljs-keyword">auto</span> var_name = {<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>};
</code></pre>
<p>However, with simply replacing <code>auto</code> with actual data type should have solved the problem.</p>
<h4 id="heading-vector-type">Vector type</h4>
<p>It's actually more like warning to not mixed up with the old initialization approach like the following code:</p>
<pre><code class="lang-cpp"><span class="hljs-comment">// initialize myvector with {0, 0, 0} elements</span>
<span class="hljs-function"><span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span>&lt;<span class="hljs-keyword">int</span>&gt; <span class="hljs-title">myvector</span> <span class="hljs-params">(<span class="hljs-number">3</span>, <span class="hljs-number">0</span>)</span></span>;

<span class="hljs-comment">// this initialization will create myvector with {3, 0} elements </span>
<span class="hljs-comment">// instead of {0, 0, 0}</span>
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span>&lt;<span class="hljs-keyword">int</span>&gt; myvector {<span class="hljs-number">3</span>, <span class="hljs-number">0</span>};
</code></pre>
<h4 id="heading-the-strongly-prefer-stdinitializerlist-constructor">The <em>strongly prefer</em> <code>std::initializer_list</code> constructor</h4>
<p><em>Strongly prefer</em> <code>std::initializer_list</code> constructor is actually a process of constructor overload resolution within a class. The first phase of the resolution is to inspect if there's a constructor that has <code>std::initializer_list</code> as a single parameter. This is why it is said to be <em>strongly prefer</em> <code>std::initializer_list</code> constructor.</p>
<p>To be clear, let's imagine we have a class with overloaded constructor, first with whatever parameters (in the following example using <code>int</code> and <code>float</code>) and another one with <code>std::initializer_list</code> parameter.</p>
<pre><code class="lang-cpp"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">foo</span> {</span>
    <span class="hljs-keyword">public</span>:
        <span class="hljs-comment">// first constructor</span>
        foo(<span class="hljs-keyword">int</span> i, <span class="hljs-keyword">float</span> f) {}
        <span class="hljs-comment">// second constructor</span>
        foo(<span class="hljs-built_in">std</span>::<span class="hljs-built_in">initializer_list</span>&lt;<span class="hljs-keyword">bool</span>&gt; <span class="hljs-built_in">list</span>) {}
}

foo my_instance {<span class="hljs-number">4</span>, <span class="hljs-number">23.5</span>};
</code></pre>
<p>The code above won't compile. Why? because, foo has the <em>strongly preferred</em> constructor that is the second one. Thus, the creation of my_instance won't invoke the first constructor, but instead the second one. In this case, the invocation will attempt to narrow-convert the <code>int</code> and <code>float</code>, <code>4</code> and <code>23.5</code> to <code>bool</code> which of course will fail.</p>
<h2 id="heading-summary">Summary</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Key</td><td>Value</td></tr>
</thead>
<tbody>
<tr>
<td>Syntax</td><td><code>Type varName {}</code> or <code>Type varName = {}</code></td></tr>
<tr>
<td>Introduced in</td><td>C++11</td></tr>
<tr>
<td>Primary Use</td><td>Direct &amp; List initialization</td></tr>
<tr>
<td>Flexibility</td><td>More versatile</td></tr>
<tr>
<td>Type safety</td><td>More type safety</td></tr>
<tr>
<td>Type conversion</td><td>Not allow narrowing type conversion</td></tr>
<tr>
<td><strong>When to use</strong></td><td>Most of the time</td></tr>
<tr>
<td><strong>When not to use</strong></td><td>see the <em>Why not?</em> section</td></tr>
</tbody>
</table>
</div><h2 id="heading-reference">Reference</h2>
<ul>
<li><p><a target="_blank" href="https://www.intel.com/content/www/us/en/docs/sycl/introduction/latest/01-uniform-initialization.html">SYCL 101</a></p>
</li>
<li><p>Beginning C++20: From Novice to Professional (Ivor Horton, Peter Van Weert)</p>
</li>
<li><p><a target="_blank" href="https://timsong-cpp.github.io/cppwp/n4659/#over">C++ standard's draft</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[An Effort to Reorganize My Github Repositories]]></title><description><![CDATA[This actually a note to myself (and may be some of you who experience the same) to keep up the effort to maintain my Github repository better.

Background
I have a thought that my Github repository is not how it is supposed to be and I think I need t...]]></description><link>https://blog.aprksy.dev/an-effort-to-reorganize-my-github-repositories</link><guid isPermaLink="true">https://blog.aprksy.dev/an-effort-to-reorganize-my-github-repositories</guid><category><![CDATA[repository]]></category><category><![CDATA[habits]]></category><dc:creator><![CDATA[Agung Prakasya]]></dc:creator><pubDate>Wed, 30 Aug 2023 11:35:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1723436395455/12e649a7-5b4f-4e92-9e45-e4c516de9a2d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p>This actually a note to myself (and may be some of you who experience the same) to keep up the effort to maintain my Github repository better.</p>
</blockquote>
<h1 id="heading-background">Background</h1>
<p>I have a thought that my Github repository is not how it is supposed to be and I think I need to do some action for that. However, I need to know the root cause and see what I can do about that because I think it's also related to my habits.</p>
<p>Let's dig deeper into the current situation of my current Github account. First, this is my second Github account. I decided to retire the first one because it was too messy and started the second one from scratch with hopes it wouldn't be experiencing the same as the first one.</p>
<p>Guess what! <strong><em>It happened again</em></strong>. Okay, let me explain the situation of my current Github account, the <em>what</em> (the thing I see in my Github) we'll analyze, and then the <em>why</em> (a self-diagnosis of why it happened) and then the <em>how</em> (a thought on how to fix that).</p>
<h1 id="heading-analysis">Analysis</h1>
<p>Here is what I found in my Github account:</p>
<ul>
<li><p>All private, no public repositories.</p>
</li>
<li><p>No mature code, only unmaintained early-stage codes</p>
</li>
<li><p>Same idea in multiple repositories</p>
</li>
</ul>
<p>Let's think that those are signs of something or effects of some behaviour or even further mentality of the owner.</p>
<p>Before going further, let's dig deeper into each fact. After a while of trying to be honest with myself, here are the findings of my behaviour:</p>
<ul>
<li><p><em>Why are the repositories all private?</em></p>
<p>  Well, I always think that code that is published on Github should be mature, professional and in the best of its form. I feel a little bit unconfident about my code.</p>
</li>
<li><p><em>Why is there no mature code, only unmaintained early-stage codes?</em><br />  I think I was really quick to get bored with the approach, topic or the idea itself. Or it might be too long before it reaches the excitement and the passion has just gone.</p>
</li>
<li><p><em>Same idea in multiple repositories?</em></p>
<p>  I have a habit of doing in multiple ways to achieve a single objective if it's possible. Doing them in parallel and picking the most elegant one.</p>
</li>
</ul>
<h1 id="heading-problem-statement">Problem Statement</h1>
<ul>
<li><p>Setting the bar too high.</p>
</li>
<li><p>There was no milestone setup, current work is always compared with the expected final state.</p>
</li>
<li><p>There was no focus or strategy for achieving the target.</p>
</li>
</ul>
<h1 id="heading-solution-proposal">Solution Proposal</h1>
<p>Actually, this is not the final solution, except it's already been done for some time and the result is as expected. However, I need to write this and propose this to myself as the fix for my habit problem.</p>
<p>So let me propose it to myself and see if it needs some revision or adjustment in the future.</p>
<ul>
<li><p>First, let me confess: Stop being proud and prejudiced. We (me and myself) are just learners, and will always be. Even Mozart had his simple composition at the time. Nobody will laugh at our work, and we also have never done that, right? Let's confess, that we learn from somebody else who kindheartedly shares their knowledge, and is never prejudiced against anyone else.</p>
</li>
<li><p>Set milestones that can be achieved in a relatively short time and visible improvements. When I have the knowledge in terms of theory and methodology, I think I need to write something about this.</p>
</li>
<li><p>If there are some options to the approach of achieving the target, pick only one with the SMART (specific, measurable, achievable, relevant &amp; time-bound) consideration.</p>
</li>
</ul>
<h1 id="heading-action-plan">Action Plan</h1>
<p>I think this part should be a living part of the document which contains some actionable that I can add from time to time and can close when I think it's enough.</p>
<ol>
<li><p>Publishing a repository of mine, <a target="_blank" href="https://github.com/aprksy/excvtor">excvtor</a>; a repository of a simple python script to generate TeX and PDF resume from JSON formatted resume and a style/layout template.</p>
</li>
<li><p>TODO</p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[An Effort to Reorganize My Workspace, Showcase and Everything in between]]></title><description><![CDATA[Background
It's actually an old mission, a long pending mission to tidy up all my digital workspace, showcases, and everything in between. the long-time-dead blog, cluttered GitHub repositories, messed up cloud storage, tons of duplicate files, digit...]]></description><link>https://blog.aprksy.dev/an-effort-to-reorganize-my-workspace-showcase-and-everything-in-between</link><guid isPermaLink="true">https://blog.aprksy.dev/an-effort-to-reorganize-my-workspace-showcase-and-everything-in-between</guid><category><![CDATA[effort]]></category><category><![CDATA[Blogging]]></category><dc:creator><![CDATA[Agung Prakasya]]></dc:creator><pubDate>Sun, 30 Jul 2023 16:23:51 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1723436437175/482bf3c1-7b2f-4be8-a843-df6d4ca750f8.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-background">Background</h1>
<p>It's actually an old mission, a long pending mission to tidy up all my digital workspace, showcases, and everything in between. the <em>long-time-dead</em> blog, cluttered GitHub repositories, messed up cloud storage, tons of duplicate files, digital garbage and evidence of things I've done that should never exist.</p>
<h2 id="heading-problems">Problems</h2>
<p>From the background above I just use words <em>cluttered, messed up</em> etc. It does show the situation but doesn't tell the urgency. In these sub-parts, I try to express how they contribute to the <em>unright things</em> of me.</p>
<ul>
<li><p>I'm a programmer but don't have any public repository/published code, a mature code that others can get inspired with, let alone a complete app/lib that others can use.</p>
</li>
<li><p>I claim myself as a person who is experienced enough and likes to read but I don't have any published writings in the form of anything that expresses my thought or express my opinion about something relevant to my knowledge/experience.</p>
</li>
<li><p>When I think I have an idea, I usually do Self-PoC, and it's often done partially in code and another part only in the mind. With the model, I can confirm to myself it is legit proof while knowing that in the future I can guarantee that I will forget those parts in my mind.</p>
</li>
<li><p>When I need to show my off-office work, I don't have anything real to put in my showcase, it's all over the place, local disks, minds and even scratch paper. And this repeats.</p>
</li>
<li><p>and so on.</p>
</li>
</ul>
<h1 id="heading-risk-amp-impact">Risk &amp; Impact</h1>
<p>Here I'm trying to identify the risk and impact of those unright things above, to model how it will affect me and probably my life.</p>
<h2 id="heading-risks">Risks</h2>
<ul>
<li><p>There's a possibility that some audience will see what I claim about myself as a <em>false premise.</em></p>
</li>
<li><p>There's a possibility that some audience will see that I'm exaggerating the claim.</p>
</li>
<li><p>There's a possibility that some audience will see that I'm the kind of person who likes to keep everything to myself.</p>
</li>
<li><p>There's a possibility that some audience will see that I'm the kind of person who doesn't have good responsibility with the work artifacts, let alone doing documentation on them.</p>
</li>
</ul>
<h2 id="heading-impacts">Impacts</h2>
<ul>
<li><p>Companies won't get a meaningful conclusion from a false premise. Thus, they won't buy pig in the poke, i.e. not gonna hire me.</p>
</li>
<li><p>Companies, even they like to hire me. They will be in doubt. Thus, I won't get my salary expectation</p>
</li>
<li><p>Companies will value me as a nonteam player, or at least not a good one. Whether or not they hire me, my value just got dropped.</p>
</li>
<li><p>Companies will think that non-responsibility with the work artifact is very bad for the team or even the whole company, and should be avoided. And of course, company won't take the risk.</p>
</li>
</ul>
<h1 id="heading-solution">Solution</h1>
<h2 id="heading-breaking-down-the-problem">Breaking Down the Problem</h2>
<p>From the above description, we have a broad problem space and cross domains and of course, it has never been a good idea to try to solve it as a whole. We definitely need to do <em>dividee et impera</em> against it. The obvious option would be by activity, which gives us three problem sub-space:</p>
<ul>
<li><p>Coding activity: What do I need to do/have, to be a productive, consistent, and being better and better time-to-time programmer?</p>
</li>
<li><p>Writing Activity: What do I need to do/have, to be a productive, consistent, and being better and better time-to-time writer?</p>
</li>
<li><p>Self-PoC activity: What do I need to do/have, to be a proofer for concepts?</p>
</li>
</ul>
<h2 id="heading-solution-design">Solution Design</h2>
<p>We have broken down the problem into specific domains which hopefully are easier to solve. To keep them separate, I think it'd be better to try to solve the above problems in separate articles.</p>
<p>If you happen to read this and have a thought on how I should solve my problems please tell me what you think.</p>
<p>Salam,</p>
<p>aprksy</p>
]]></content:encoded></item></channel></rss>