<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Programming on Suriya's site</title><link>https://subygan.com/tags/programming/</link><description>Recent content in Programming on Suriya's site</description><generator>Hugo</generator><language>en</language><copyright>This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</copyright><item><title>binaries and postgres</title><link>https://subygan.com/tech/tinkering/postgres/binaries/</link><pubDate>Mon, 18 May 2026 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/postgres/binaries/</guid><description>&lt;p>Postgres is awesome, but can You get away with it being a filesystem or stash space for your application. here are some calculations I did.&lt;/p></description></item><item><title>recursions</title><link>https://subygan.com/tech/tinkering/recursions/</link><pubDate>Wed, 04 Mar 2026 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/recursions/</guid><description>&lt;p>Recursion is often taught in Computer Science 101 as an elegant, mathematically pure way to solve problems and used widely in leetcode style problems. However, in production environments using mainstream imperative languages (like Python, JavaScript, Java, or C++), it is heavily discouraged. Recursions are usually a footgun in waiting because of some technical&lt;/p></description></item><item><title>qmd for hugo</title><link>https://subygan.com/tech/tinkering/qmd/</link><pubDate>Mon, 29 Dec 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/qmd/</guid><description>&lt;p>I really love just taking notes, run code and having it in my blog.&lt;/p>
&lt;p>Quarto is quite cool, I end up committing both the &lt;code>.qmd&lt;/code> and &lt;code>.md&lt;/code> files generated from running &lt;code>quarto render&lt;/code> locally. (haven&amp;rsquo;t gotten to cicd yet.)&lt;/p></description></item><item><title>media processing in the cli</title><link>https://subygan.com/tech/tinkering/image-processing/</link><pubDate>Fri, 12 Dec 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/image-processing/</guid><description>&lt;p>convert &lt;code>RW2&lt;/code> format to &lt;code>jpg&lt;/code> with imagemagick. while maintaining quality.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">for&lt;/span> f in *.RW2; &lt;span style="color:#66d9ef">do&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> magick &lt;span style="color:#e6db74">&amp;#34;&lt;/span>$f&lt;span style="color:#e6db74">&amp;#34;&lt;/span> -quality &lt;span style="color:#ae81ff">85&lt;/span> &lt;span style="color:#e6db74">&amp;#34;GooglePhotosBackup/&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>f%.*&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">.jpg&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> exiftool -tagsFromFile &lt;span style="color:#e6db74">&amp;#34;&lt;/span>$f&lt;span style="color:#e6db74">&amp;#34;&lt;/span> -all:all &lt;span style="color:#e6db74">&amp;#34;GooglePhotosBackup/&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>f%.*&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">.jpg&amp;#34;&lt;/span> -overwrite_original
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">done&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>convert mp4 into good quality video.&lt;/p></description></item><item><title>1d convolution</title><link>https://subygan.com/tech/algos/cuda/06_1d_convolution/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/06_1d_convolution/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-cpp" data-lang="cpp">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;cuda_runtime.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;iostream&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;stdio.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>__global__ &lt;span style="color:#66d9ef">void&lt;/span> &lt;span style="color:#a6e22e">convolution_1d_kernel&lt;/span>(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> kernel, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> input_size, &lt;span style="color:#66d9ef">int&lt;/span> kernel_size) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> i &lt;span style="color:#f92672">=&lt;/span> blockDim.x &lt;span style="color:#f92672">*&lt;/span> blockIdx.x &lt;span style="color:#f92672">+&lt;/span> threadIdx.x;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> output_size &lt;span style="color:#f92672">=&lt;/span> input_size &lt;span style="color:#f92672">-&lt;/span> kernel_size &lt;span style="color:#f92672">+&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (i &lt;span style="color:#f92672">&amp;lt;&lt;/span> output_size ) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">float&lt;/span> sum &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">0.0f&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">for&lt;/span> ( &lt;span style="color:#66d9ef">int&lt;/span> j &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>; j&lt;span style="color:#f92672">&amp;lt;&lt;/span>kernel_size; j&lt;span style="color:#f92672">++&lt;/span>) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> sum &lt;span style="color:#f92672">+=&lt;/span> input[i&lt;span style="color:#f92672">+&lt;/span>j]&lt;span style="color:#f92672">*&lt;/span>kernel[j];
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> output[i] &lt;span style="color:#f92672">=&lt;/span> sum;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// input, kernel, output are device pointers (i.e. pointers to memory on the GPU)
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">extern&lt;/span> &lt;span style="color:#e6db74">&amp;#34;C&amp;#34;&lt;/span> &lt;span style="color:#66d9ef">void&lt;/span> solve(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> kernel, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> input_size, &lt;span style="color:#66d9ef">int&lt;/span> kernel_size) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> output_size &lt;span style="color:#f92672">=&lt;/span> input_size &lt;span style="color:#f92672">-&lt;/span> kernel_size &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> threadsPerBlock &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">256&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> blocksPerGrid &lt;span style="color:#f92672">=&lt;/span> (output_size &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> convolution_1d_kernel&lt;span style="color:#f92672">&amp;lt;&amp;lt;&amp;lt;&lt;/span>blocksPerGrid, threadsPerBlock&lt;span style="color:#f92672">&amp;gt;&amp;gt;&amp;gt;&lt;/span>(input, kernel, output, input_size, kernel_size);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cudaDeviceSynchronize();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>color inversion</title><link>https://subygan.com/tech/algos/cuda/04_color_inversion/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/04_color_inversion/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-cpp" data-lang="cpp">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;cuda_runtime.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>__global__ &lt;span style="color:#66d9ef">void&lt;/span> &lt;span style="color:#a6e22e">invert_kernel&lt;/span>(&lt;span style="color:#66d9ef">unsigned&lt;/span> &lt;span style="color:#66d9ef">char&lt;/span>&lt;span style="color:#f92672">*&lt;/span> image, &lt;span style="color:#66d9ef">int&lt;/span> width, &lt;span style="color:#66d9ef">int&lt;/span> height) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> i &lt;span style="color:#f92672">=&lt;/span> blockIdx.x &lt;span style="color:#f92672">*&lt;/span> blockDim.x &lt;span style="color:#f92672">+&lt;/span> threadIdx.x;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> image[i&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#ae81ff">4&lt;/span>] &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">255&lt;/span> &lt;span style="color:#f92672">-&lt;/span> image[i&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#ae81ff">4&lt;/span>];
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> image[i&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#ae81ff">4&lt;/span>&lt;span style="color:#f92672">+&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>] &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">255&lt;/span> &lt;span style="color:#f92672">-&lt;/span> image[i&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#ae81ff">4&lt;/span>&lt;span style="color:#f92672">+&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>];
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> image[i&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#ae81ff">4&lt;/span>&lt;span style="color:#f92672">+&lt;/span>&lt;span style="color:#ae81ff">2&lt;/span>] &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">255&lt;/span> &lt;span style="color:#f92672">-&lt;/span> image[i&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#ae81ff">4&lt;/span>&lt;span style="color:#f92672">+&lt;/span>&lt;span style="color:#ae81ff">2&lt;/span>];
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// image_input, image_output are device pointers (i.e. pointers to memory on the GPU)
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">extern&lt;/span> &lt;span style="color:#e6db74">&amp;#34;C&amp;#34;&lt;/span> &lt;span style="color:#66d9ef">void&lt;/span> solve(&lt;span style="color:#66d9ef">unsigned&lt;/span> &lt;span style="color:#66d9ef">char&lt;/span>&lt;span style="color:#f92672">*&lt;/span> image, &lt;span style="color:#66d9ef">int&lt;/span> width, &lt;span style="color:#66d9ef">int&lt;/span> height) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> threadsPerBlock &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">256&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> blocksPerGrid &lt;span style="color:#f92672">=&lt;/span> (width &lt;span style="color:#f92672">*&lt;/span> height &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> invert_kernel&lt;span style="color:#f92672">&amp;lt;&amp;lt;&amp;lt;&lt;/span>blocksPerGrid, threadsPerBlock&lt;span style="color:#f92672">&amp;gt;&amp;gt;&amp;gt;&lt;/span>(image, width, height);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cudaDeviceSynchronize();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>count 2d array element</title><link>https://subygan.com/tech/algos/cuda/14_count_2d_array/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/14_count_2d_array/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-c++" data-lang="c++">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;cuda_runtime.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>__global__ &lt;span style="color:#66d9ef">void&lt;/span> &lt;span style="color:#a6e22e">count_2d_equal_kernel&lt;/span>(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">int&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> N, &lt;span style="color:#66d9ef">int&lt;/span> M, &lt;span style="color:#66d9ef">int&lt;/span> K) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> idx &lt;span style="color:#f92672">=&lt;/span> blockDim.x&lt;span style="color:#f92672">*&lt;/span>blockIdx.x &lt;span style="color:#f92672">+&lt;/span> threadIdx.x;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> idy &lt;span style="color:#f92672">=&lt;/span> blockDim.y&lt;span style="color:#f92672">*&lt;/span>blockIdx.y &lt;span style="color:#f92672">+&lt;/span> threadIdx.y;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> ((idx&lt;span style="color:#f92672">&amp;lt;&lt;/span>N &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> idy&lt;span style="color:#f92672">&amp;lt;&lt;/span>M) &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> input[idx&lt;span style="color:#f92672">*&lt;/span>M&lt;span style="color:#f92672">+&lt;/span>idy]&lt;span style="color:#f92672">==&lt;/span>K) atomicAdd(output,&lt;span style="color:#ae81ff">1&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// input, output are device pointers (i.e. pointers to memory on the GPU)
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">extern&lt;/span> &lt;span style="color:#e6db74">&amp;#34;C&amp;#34;&lt;/span> &lt;span style="color:#66d9ef">void&lt;/span> solve(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">int&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> N, &lt;span style="color:#66d9ef">int&lt;/span> M, &lt;span style="color:#66d9ef">int&lt;/span> K) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> dim3 &lt;span style="color:#a6e22e">threadsPerBlock&lt;/span>(&lt;span style="color:#ae81ff">16&lt;/span>, &lt;span style="color:#ae81ff">16&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> dim3 &lt;span style="color:#a6e22e">blocksPerGrid&lt;/span>((N &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock.x &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock.x,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> (M &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock.y &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock.y);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> count_2d_equal_kernel&lt;span style="color:#f92672">&amp;lt;&amp;lt;&amp;lt;&lt;/span>blocksPerGrid, threadsPerBlock&lt;span style="color:#f92672">&amp;gt;&amp;gt;&amp;gt;&lt;/span>(input, output, N, M, K);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cudaDeviceSynchronize();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>count array element</title><link>https://subygan.com/tech/algos/cuda/13_count_array/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/13_count_array/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-c++" data-lang="c++">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;cuda_runtime.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>__global__ &lt;span style="color:#66d9ef">void&lt;/span> &lt;span style="color:#a6e22e">count_equal_kernel&lt;/span>(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">int&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> N, &lt;span style="color:#66d9ef">int&lt;/span> K) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> id&lt;span style="color:#f92672">=&lt;/span>blockDim.x &lt;span style="color:#f92672">*&lt;/span> blockIdx.x &lt;span style="color:#f92672">+&lt;/span> threadIdx.x;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span>(id&lt;span style="color:#f92672">&amp;lt;&lt;/span>N &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> input[id]&lt;span style="color:#f92672">==&lt;/span>K) atomicAdd(output, &lt;span style="color:#ae81ff">1&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// input, output are device pointers (i.e. pointers to memory on the GPU)
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">extern&lt;/span> &lt;span style="color:#e6db74">&amp;#34;C&amp;#34;&lt;/span> &lt;span style="color:#66d9ef">void&lt;/span> solve(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">int&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> N, &lt;span style="color:#66d9ef">int&lt;/span> K) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> threadsPerBlock &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">256&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> blocksPerGrid &lt;span style="color:#f92672">=&lt;/span> (N &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> count_equal_kernel&lt;span style="color:#f92672">&amp;lt;&amp;lt;&amp;lt;&lt;/span>blocksPerGrid, threadsPerBlock&lt;span style="color:#f92672">&amp;gt;&amp;gt;&amp;gt;&lt;/span>(input, output, N, K);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cudaDeviceSynchronize();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>leaky relu</title><link>https://subygan.com/tech/algos/cuda/09_leaky_relu/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/09_leaky_relu/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-c++" data-lang="c++">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;cuda_runtime.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>__global__ &lt;span style="color:#66d9ef">void&lt;/span> &lt;span style="color:#a6e22e">leaky_relu_kernel&lt;/span>(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> id &lt;span style="color:#f92672">=&lt;/span> blockDim.x&lt;span style="color:#f92672">*&lt;/span> blockIdx.x &lt;span style="color:#f92672">+&lt;/span> threadIdx.x;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (id&lt;span style="color:#f92672">&amp;lt;&lt;/span>N) output[id] &lt;span style="color:#f92672">=&lt;/span> input[id]&lt;span style="color:#f92672">&amp;gt;&lt;/span>&lt;span style="color:#ae81ff">0&lt;/span>&lt;span style="color:#f92672">?&lt;/span> input[id] &lt;span style="color:#f92672">:&lt;/span> &lt;span style="color:#ae81ff">0.01&lt;/span>&lt;span style="color:#f92672">*&lt;/span>input[id];
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// input, output are device pointers (i.e. pointers to memory on the GPU)
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">extern&lt;/span> &lt;span style="color:#e6db74">&amp;#34;C&amp;#34;&lt;/span> &lt;span style="color:#66d9ef">void&lt;/span> solve(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> threadsPerBlock &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">256&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> blocksPerGrid &lt;span style="color:#f92672">=&lt;/span> (N &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> leaky_relu_kernel&lt;span style="color:#f92672">&amp;lt;&amp;lt;&amp;lt;&lt;/span>blocksPerGrid, threadsPerBlock&lt;span style="color:#f92672">&amp;gt;&amp;gt;&amp;gt;&lt;/span>(input, output, N);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cudaDeviceSynchronize();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>matrix addition</title><link>https://subygan.com/tech/algos/cuda/05_matrix_addition/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/05_matrix_addition/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-c++" data-lang="c++">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;cuda_runtime.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>__global__ &lt;span style="color:#66d9ef">void&lt;/span> &lt;span style="color:#a6e22e">matrix_add&lt;/span>(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> A, &lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> B, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> C, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> id &lt;span style="color:#f92672">=&lt;/span> blockDim.x &lt;span style="color:#f92672">*&lt;/span> blockIdx.x &lt;span style="color:#f92672">+&lt;/span> threadIdx.x;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (id&lt;span style="color:#f92672">&amp;lt;&lt;/span>N) C[id] &lt;span style="color:#f92672">=&lt;/span> A[id]&lt;span style="color:#f92672">+&lt;/span>B[id];
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// A, B, C are device pointers (i.e. pointers to memory on the GPU)
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">extern&lt;/span> &lt;span style="color:#e6db74">&amp;#34;C&amp;#34;&lt;/span> &lt;span style="color:#66d9ef">void&lt;/span> solve(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> A, &lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> B, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> C, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> threadsPerBlock &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">256&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> blocksPerGrid &lt;span style="color:#f92672">=&lt;/span> (N &lt;span style="color:#f92672">*&lt;/span> N &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> matrix_add&lt;span style="color:#f92672">&amp;lt;&amp;lt;&amp;lt;&lt;/span>blocksPerGrid, threadsPerBlock&lt;span style="color:#f92672">&amp;gt;&amp;gt;&amp;gt;&lt;/span>(A, B, C, N);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cudaDeviceSynchronize();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>matrix copy</title><link>https://subygan.com/tech/algos/cuda/11_matrix_copy/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/11_matrix_copy/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-c++" data-lang="c++">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;cuda_runtime.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;stdio.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;iostream&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>__global__ &lt;span style="color:#66d9ef">void&lt;/span> &lt;span style="color:#a6e22e">copy_matrix_kernel&lt;/span>(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> A, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> B, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> idx &lt;span style="color:#f92672">=&lt;/span> blockDim.x&lt;span style="color:#f92672">*&lt;/span> blockIdx.x &lt;span style="color:#f92672">+&lt;/span> threadIdx.x;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (idx&lt;span style="color:#f92672">&amp;lt;&lt;/span>N){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> B[idx] &lt;span style="color:#f92672">=&lt;/span> A[idx];
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> } 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// A, B are device pointers (i.e. pointers to memory on the GPU)
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">extern&lt;/span> &lt;span style="color:#e6db74">&amp;#34;C&amp;#34;&lt;/span> &lt;span style="color:#66d9ef">void&lt;/span> solve(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> A, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> B, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> total &lt;span style="color:#f92672">=&lt;/span> N &lt;span style="color:#f92672">*&lt;/span> N;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> threadsPerBlock &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">256&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> blocksPerGrid &lt;span style="color:#f92672">=&lt;/span> (total &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> copy_matrix_kernel&lt;span style="color:#f92672">&amp;lt;&amp;lt;&amp;lt;&lt;/span>blocksPerGrid, threadsPerBlock&lt;span style="color:#f92672">&amp;gt;&amp;gt;&amp;gt;&lt;/span>(A, B, total);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cudaDeviceSynchronize();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>} 
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>matrix multiply</title><link>https://subygan.com/tech/algos/cuda/02_matrix_multipy/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/02_matrix_multipy/</guid><description>&lt;p>The tricky part in this was that, I took some time to intuit that each thread should associate to each value in the output matrix.&lt;/p></description></item><item><title>matrix transpose</title><link>https://subygan.com/tech/algos/cuda/03_matrix_transpose/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/03_matrix_transpose/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-cpp" data-lang="cpp">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;cuda_runtime.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;iostream&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;stdio.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>__global__ &lt;span style="color:#66d9ef">void&lt;/span> &lt;span style="color:#a6e22e">matrix_transpose_kernel&lt;/span>(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> rows, &lt;span style="color:#66d9ef">int&lt;/span> cols) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> i &lt;span style="color:#f92672">=&lt;/span> blockIdx.x &lt;span style="color:#f92672">*&lt;/span> blockDim.x &lt;span style="color:#f92672">+&lt;/span> threadIdx.x;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> j &lt;span style="color:#f92672">=&lt;/span> blockIdx.y &lt;span style="color:#f92672">*&lt;/span> blockDim.y &lt;span style="color:#f92672">+&lt;/span> threadIdx.y;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> printf(&lt;span style="color:#e6db74">&amp;#34;%d&amp;#34;&lt;/span>,i);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (i&lt;span style="color:#f92672">&amp;lt;&lt;/span>rows &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> j&lt;span style="color:#f92672">&amp;lt;&lt;/span>cols){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> output[j&lt;span style="color:#f92672">*&lt;/span>rows&lt;span style="color:#f92672">+&lt;/span>i] &lt;span style="color:#f92672">=&lt;/span> input[i&lt;span style="color:#f92672">*&lt;/span>cols&lt;span style="color:#f92672">+&lt;/span>j];
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// input, output are device pointers (i.e. pointers to memory on the GPU)
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">extern&lt;/span> &lt;span style="color:#e6db74">&amp;#34;C&amp;#34;&lt;/span> &lt;span style="color:#66d9ef">void&lt;/span> solve(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> rows, &lt;span style="color:#66d9ef">int&lt;/span> cols) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> dim3 &lt;span style="color:#a6e22e">threadsPerBlock&lt;/span>(&lt;span style="color:#ae81ff">16&lt;/span>, &lt;span style="color:#ae81ff">16&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> dim3 &lt;span style="color:#a6e22e">blocksPerGrid&lt;/span>((cols &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock.x &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock.x,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> (rows &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock.y &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock.y);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> matrix_transpose_kernel&lt;span style="color:#f92672">&amp;lt;&amp;lt;&amp;lt;&lt;/span>blocksPerGrid, threadsPerBlock&lt;span style="color:#f92672">&amp;gt;&amp;gt;&amp;gt;&lt;/span>(input, output, rows, cols);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cudaDeviceSynchronize();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>relu</title><link>https://subygan.com/tech/algos/cuda/08_ReLu/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/08_ReLu/</guid><description>&lt;p>&lt;code>ReLU(x) = max(0,x)&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-c++" data-lang="c++">&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;cuda_runtime.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>__global__ &lt;span style="color:#66d9ef">void&lt;/span> &lt;span style="color:#a6e22e">relu_kernel&lt;/span>(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> id &lt;span style="color:#f92672">=&lt;/span> blockDim.x&lt;span style="color:#f92672">*&lt;/span> blockIdx.x &lt;span style="color:#f92672">+&lt;/span> threadIdx.x;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (id&lt;span style="color:#f92672">&amp;lt;&lt;/span>N) output[id] &lt;span style="color:#f92672">=&lt;/span> std&lt;span style="color:#f92672">::&lt;/span>max(&lt;span style="color:#ae81ff">0.0f&lt;/span>,input[id]);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// input, output are device pointers (i.e. pointers to memory on the GPU)
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">extern&lt;/span> &lt;span style="color:#e6db74">&amp;#34;C&amp;#34;&lt;/span> &lt;span style="color:#66d9ef">void&lt;/span> solve(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> threadsPerBlock &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">256&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> blocksPerGrid &lt;span style="color:#f92672">=&lt;/span> (N &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> relu_kernel&lt;span style="color:#f92672">&amp;lt;&amp;lt;&amp;lt;&lt;/span>blocksPerGrid, threadsPerBlock&lt;span style="color:#f92672">&amp;gt;&amp;gt;&amp;gt;&lt;/span>(input, output, N);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cudaDeviceSynchronize();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>reverse array</title><link>https://subygan.com/tech/algos/cuda/07_reverse_array/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/07_reverse_array/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-c++" data-lang="c++">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;cuda_runtime.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;iostream&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;stdio.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>__global__ &lt;span style="color:#66d9ef">void&lt;/span> &lt;span style="color:#a6e22e">reverse_array&lt;/span>(&lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> i &lt;span style="color:#f92672">=&lt;/span> blockDim.x &lt;span style="color:#f92672">*&lt;/span> blockIdx.x &lt;span style="color:#f92672">+&lt;/span> threadIdx.x;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (i&lt;span style="color:#f92672">&amp;lt;&lt;/span>N&lt;span style="color:#f92672">/&lt;/span>&lt;span style="color:#ae81ff">2&lt;/span>) { 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> std&lt;span style="color:#f92672">::&lt;/span>swap(input[i],input[N&lt;span style="color:#f92672">-&lt;/span>i&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>]);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// input is device pointer
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">extern&lt;/span> &lt;span style="color:#e6db74">&amp;#34;C&amp;#34;&lt;/span> &lt;span style="color:#66d9ef">void&lt;/span> solve(&lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> threadsPerBlock &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">256&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> blocksPerGrid &lt;span style="color:#f92672">=&lt;/span> (N &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> reverse_array&lt;span style="color:#f92672">&amp;lt;&amp;lt;&amp;lt;&lt;/span>blocksPerGrid, threadsPerBlock&lt;span style="color:#f92672">&amp;gt;&amp;gt;&amp;gt;&lt;/span>(input, N);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cudaDeviceSynchronize();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>silu</title><link>https://subygan.com/tech/algos/cuda/15_sigmoid_linear_unit/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/15_sigmoid_linear_unit/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-cpp" data-lang="cpp">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;cuda_runtime.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>__global__ &lt;span style="color:#66d9ef">void&lt;/span> &lt;span style="color:#a6e22e">silu_kernel&lt;/span>(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> id &lt;span style="color:#f92672">=&lt;/span> blockDim.x &lt;span style="color:#f92672">*&lt;/span> blockIdx.x &lt;span style="color:#f92672">+&lt;/span> threadIdx.x;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (id&lt;span style="color:#f92672">&amp;lt;&lt;/span>N) output[id] &lt;span style="color:#f92672">=&lt;/span> input[id]&lt;span style="color:#f92672">*&lt;/span>(&lt;span style="color:#ae81ff">1&lt;/span>&lt;span style="color:#f92672">/&lt;/span>(&lt;span style="color:#ae81ff">1&lt;/span>&lt;span style="color:#f92672">+&lt;/span>std&lt;span style="color:#f92672">::&lt;/span>exp(&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>&lt;span style="color:#f92672">*&lt;/span>(input[id]))));
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// input, output are device pointers
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">extern&lt;/span> &lt;span style="color:#e6db74">&amp;#34;C&amp;#34;&lt;/span> &lt;span style="color:#66d9ef">void&lt;/span> solve(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> threadsPerBlock &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">256&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> blocksPerGrid &lt;span style="color:#f92672">=&lt;/span> (N &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> silu_kernel&lt;span style="color:#f92672">&amp;lt;&amp;lt;&amp;lt;&lt;/span>blocksPerGrid, threadsPerBlock&lt;span style="color:#f92672">&amp;gt;&amp;gt;&amp;gt;&lt;/span>(input, output, N);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cudaDeviceSynchronize();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>simple inference</title><link>https://subygan.com/tech/algos/cuda/12_simple_inference/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/12_simple_inference/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-python" data-lang="python">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">import&lt;/span> torch
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">import&lt;/span> torch.nn &lt;span style="color:#66d9ef">as&lt;/span> nn
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># input, model, and output are on the GPU&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">solve&lt;/span>(input: torch&lt;span style="color:#f92672">.&lt;/span>Tensor, model: nn&lt;span style="color:#f92672">.&lt;/span>Module, output: torch&lt;span style="color:#f92672">.&lt;/span>Tensor):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> model&lt;span style="color:#f92672">.&lt;/span>eval()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">with&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>no_grad():
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> output&lt;span style="color:#f92672">.&lt;/span>copy_(model(input))
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>swilu</title><link>https://subygan.com/tech/algos/cuda/16_swish_gated_linear_unit/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/16_swish_gated_linear_unit/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-c++" data-lang="c++">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#include&lt;/span> &lt;span style="color:#75715e">&amp;lt;cuda_runtime.h&amp;gt;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">float&lt;/span> &lt;span style="color:#a6e22e">silu&lt;/span>(&lt;span style="color:#66d9ef">float&lt;/span> x){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> x&lt;span style="color:#f92672">*&lt;/span>(&lt;span style="color:#ae81ff">1&lt;/span>&lt;span style="color:#f92672">/&lt;/span>(&lt;span style="color:#ae81ff">1&lt;/span>&lt;span style="color:#f92672">+&lt;/span>std&lt;span style="color:#f92672">::&lt;/span>exp(&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>&lt;span style="color:#f92672">*&lt;/span>(x))));
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>__global__ &lt;span style="color:#66d9ef">void&lt;/span> &lt;span style="color:#a6e22e">swiglu_kernel&lt;/span>(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> halfN) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> id &lt;span style="color:#f92672">=&lt;/span> blockDim.x &lt;span style="color:#f92672">*&lt;/span> blockIdx.x &lt;span style="color:#f92672">+&lt;/span> threadIdx.x;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span>(id&lt;span style="color:#f92672">&amp;lt;&lt;/span>halfN) output[id] &lt;span style="color:#f92672">=&lt;/span> input[id&lt;span style="color:#f92672">%&lt;/span>halfN]&lt;span style="color:#f92672">*&lt;/span>(&lt;span style="color:#ae81ff">1&lt;/span>&lt;span style="color:#f92672">/&lt;/span>(&lt;span style="color:#ae81ff">1&lt;/span>&lt;span style="color:#f92672">+&lt;/span>std&lt;span style="color:#f92672">::&lt;/span>exp(&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>&lt;span style="color:#f92672">*&lt;/span>(input[id&lt;span style="color:#f92672">%&lt;/span>halfN])))) &lt;span style="color:#f92672">*&lt;/span> input[id&lt;span style="color:#f92672">%&lt;/span>halfN &lt;span style="color:#f92672">+&lt;/span> halfN];
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// input, output are device pointers
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">extern&lt;/span> &lt;span style="color:#e6db74">&amp;#34;C&amp;#34;&lt;/span> &lt;span style="color:#66d9ef">void&lt;/span> solve(&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> input, &lt;span style="color:#66d9ef">float&lt;/span>&lt;span style="color:#f92672">*&lt;/span> output, &lt;span style="color:#66d9ef">int&lt;/span> N) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> halfN &lt;span style="color:#f92672">=&lt;/span> N &lt;span style="color:#f92672">/&lt;/span> &lt;span style="color:#ae81ff">2&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> threadsPerBlock &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">256&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> blocksPerGrid &lt;span style="color:#f92672">=&lt;/span> (halfN &lt;span style="color:#f92672">+&lt;/span> threadsPerBlock &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> threadsPerBlock;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> swiglu_kernel&lt;span style="color:#f92672">&amp;lt;&amp;lt;&amp;lt;&lt;/span>blocksPerGrid, threadsPerBlock&lt;span style="color:#f92672">&amp;gt;&amp;gt;&amp;gt;&lt;/span>(input, output, halfN);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cudaDeviceSynchronize();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>vector addition</title><link>https://subygan.com/tech/algos/cuda/01_vector_addition/</link><pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/cuda/01_vector_addition/</guid><description>&lt;p>The question was&lt;/p>
&lt;pre tabindex="0">&lt;code>Implement a program that performs element-wise addition of two vectors containing 32-bit floating point numbers on a GPU. The program should take two input vectors of equal length and produce a single output vector containing their sum.

Implementation Requirements
External libraries are not permitted
The solve function signature must remain unchanged
The final result must be stored in vector C
&lt;/code>&lt;/pre>&lt;p>Identifying the thread uniquely is always done like using
&lt;code>blockIdx.x * blockDim.x + threadIdx.x&lt;/code>&lt;/p></description></item><item><title>functional programming.</title><link>https://subygan.com/tech/practice/erlang/functional/</link><pubDate>Sat, 25 Oct 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/erlang/functional/</guid><description>&lt;p>functional programming (FP) has always seemed like a curiosity – a realm of mathematical purity with little bearing on the practical realities of building robust, scalable software. However, as the complexity of software grows and the demand for concurrent and parallel processing. This post aims to demystify functional programming for the experienced object-oriented programmer and offer a technical bridge from the familiar landscapes of Rust, Python, and C++.&lt;/p></description></item><item><title>phoenix</title><link>https://subygan.com/tech/practice/erlang/phoenix/</link><pubDate>Sat, 25 Oct 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/erlang/phoenix/</guid><description/></item><item><title>elixir</title><link>https://subygan.com/tech/practice/erlang/elixir/</link><pubDate>Fri, 03 Oct 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/erlang/elixir/</guid><description>&lt;h2 id="tools">tools&lt;/h2>
&lt;h2 id="hex">hex&lt;/h2>
&lt;p>is the package manager. similar to pip.&lt;/p>
&lt;h3 id="mix">mix&lt;/h3>
&lt;p>tooling to build, run, test, and release Erlang applications. kinda like cargo for rust.&lt;/p></description></item><item><title>software engineering agents work. but only if you do</title><link>https://subygan.com/general/gpt-code/</link><pubDate>Sat, 13 Sep 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/general/gpt-code/</guid><description>&lt;p>Every week there is a new agent that the twitter micro-cosmos gets fired up about. This week it was agent 3.
Which is apparently miles ahead of the competition and is able to plan and execute for up to 200 minutes.&lt;/p></description></item><item><title>rust `move` keyword</title><link>https://subygan.com/tech/practice/rust/move/</link><pubDate>Tue, 09 Sep 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/rust/move/</guid><description>&lt;h2 id="what-is-move">what is &amp;ldquo;move&amp;rdquo;&lt;/h2>
&lt;p>When you assign a value to a new variable or pass a value to a function, the default behavior for types that don&amp;rsquo;t implement the &lt;code>Copy&lt;/code> trait is to &amp;ldquo;move&amp;rdquo; ownership of that value. This means the original variable can no longer be used after the move. This prevents double-free errors and other memory safety issues by ensuring there&amp;rsquo;s always only one owner of the data at any given time. This forms the base of the ownership model, which can be represented like below.&lt;/p></description></item><item><title>async rust</title><link>https://subygan.com/tech/practice/rust/async-rust/</link><pubDate>Sun, 10 Aug 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/rust/async-rust/</guid><description>&lt;p>Asynchronous programming is a powerful paradigm for building highly concurrent and efficient I/O-bound applications.&lt;/p>
&lt;p>I will dissect the core components of Rust&amp;rsquo;s asynchrony, from the fundamental &lt;code>Future&lt;/code> trait to the complexities of &lt;code>Pin&lt;/code> and memory management. We will then unravel the inner workings of Tokio, the most popular async runtime, exploring its scheduler, I/O handling with &lt;code>mio&lt;/code>, and how it all comes together to execute our asynchronous code.&lt;/p></description></item><item><title>postgres</title><link>https://subygan.com/tech/tinkering/postgres/cmds/</link><pubDate>Sun, 10 Aug 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/postgres/cmds/</guid><description>&lt;p>Often in postgres, there are some unique stuff that is there for postgres which slows stuff down or speeds up the query.&lt;/p></description></item><item><title>rust benchmarking</title><link>https://subygan.com/tech/practice/rust/benchmarking/</link><pubDate>Wed, 25 Jun 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/rust/benchmarking/</guid><description>&lt;h2 id="libraries">libraries&lt;/h2>
&lt;h3 id="criterionrs">&lt;a href="https://github.com/bheisler/criterion.rs">criterion.rs&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Has really good defaults and seems to work out of the box.&lt;/li>
&lt;li>The ecosystem around criterion is really good. purely because criterion has been around for so long&lt;/li>
&lt;/ul>
&lt;h3 id="rust-iai">&lt;a href="https://github.com/bheisler/iai">rust iai&lt;/a>
&lt;/h3>
&lt;p>Even though it is supported by a lot of ecosystem tools. It hasn&amp;rsquo;t been in development for the past 4 years. and &lt;a href="https://github.com/bheisler">bheisler&lt;/a>
 is the creator of criterion, so even more reason to use criterion.&lt;/p></description></item><item><title>server setup</title><link>https://subygan.com/tech/tinkering/server/</link><pubDate>Fri, 07 Mar 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/server/</guid><description>&lt;h3 id="oh-my-zsh">oh my zsh&lt;/h3>
&lt;ul>
&lt;li>oh-my-zsh has hands down been a godsend for me.&lt;/li>
&lt;/ul>
&lt;p>for that though we first need to install &lt;code>zsh&lt;/code>&lt;/p></description></item><item><title>mobile dev</title><link>https://subygan.com/tech/tinkering/mobile_dev/</link><pubDate>Fri, 28 Feb 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/mobile_dev/</guid><description>&lt;p>Mobile development is probably the most highest abstracted operation possible. because of this there are too many pitfalls that trip up&lt;/p></description></item><item><title>source code</title><link>https://subygan.com/books/source_code/</link><pubDate>Wed, 26 Feb 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/books/source_code/</guid><description>&lt;p>Bill Gates starts this story from his roots up until the point he found Microsoft and it became a really serious thing. I like that the book closes right after the founding of Microsoft. Because much has been written about that part of the story&lt;/p></description></item><item><title>react native</title><link>https://subygan.com/tech/tinkering/react-native/</link><pubDate>Sat, 22 Feb 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/react-native/</guid><description>&lt;p>I&amp;rsquo;ve worked with React Native before but never professionally.&lt;/p>
&lt;p>Recently I&amp;rsquo;ve been getting into building a complete react-native app&lt;/p>
&lt;p>And, that is when you see the dark underside of things.&lt;/p></description></item><item><title>vscode</title><link>https://subygan.com/tech/tinkering/vscode/</link><pubDate>Sat, 15 Feb 2025 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/vscode/</guid><description>&lt;h2 id="why-switch-from-intellij">why switch from intellij&lt;/h2>
&lt;p>Intellij was my most common IDE but I&amp;rsquo;m so tired of having to be a second citizen for every single plugin. Intellij needs to do a huge platform shift and become more open or be consumed by vscode. The amount of people who start with vscode is insane.&lt;/p></description></item><item><title>poetry</title><link>https://subygan.com/tech/tinkering/poetry/</link><pubDate>Thu, 14 Nov 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/poetry/</guid><description>&lt;p>Python package management is a nightmare. Poetry somewhat solves it.&lt;/p>
&lt;h2 id="new-project">new project&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>poetry new &amp;lt;project_name&amp;gt;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="new-shell">new shell&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>poetry shell
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="setting-up">setting up&lt;/h2>
&lt;p>pipx first&lt;/p></description></item><item><title>llms and unstructured data</title><link>https://subygan.com/tech/tinkering/structure/</link><pubDate>Sat, 31 Aug 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/structure/</guid><description>&lt;p>Close on the heels of running a &lt;a href="https://subygan.com/tech/cloud/batch_processing_llm">batch processing job over 1M documents&lt;/a>
, I was thinking about how LLMs are changing the way we process unstructured data.&lt;/p></description></item><item><title>zsh</title><link>https://subygan.com/tech/tinkering/zshrc/</link><pubDate>Mon, 19 Aug 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/zshrc/</guid><description>&lt;h2 id="setting-up-new-zsh-with-oh-my-zsh">setting up new zsh with oh my zsh&lt;/h2>
&lt;p>firs installing zsh involves&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>brew install zsh
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>While I don&amp;rsquo;t really trust and run randomly downloaded shell files. This one is quite painless.&lt;/p></description></item><item><title>library of congress information</title><link>https://subygan.com/tech/tinkering/loc/</link><pubDate>Sat, 17 Aug 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/loc/</guid><description>&lt;p>Library of Congress is really an incredible repository of content.
Just scrolling through library of congress is a fascinating mental exercise.&lt;/p></description></item><item><title>terminal</title><link>https://subygan.com/tech/tinkering/terminal/</link><pubDate>Thu, 08 Aug 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/terminal/</guid><description>&lt;p>&lt;strong>Raw mode&lt;/strong> in a terminal is receiving the raw bytes from the &lt;code>STDIN&lt;/code> file.
terminal usually gets opened in &lt;strong>canonical mode&lt;/strong> which means input is fed to the program one line at a time, instead of character by character. This can be done by unsetting the &lt;code>ICANON&lt;/code> flag. There are a lot of these &lt;em>bitflags&lt;/em>&lt;/p></description></item><item><title>read the docs</title><link>https://subygan.com/tech/tinkering/read_docs/</link><pubDate>Tue, 23 Jul 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/read_docs/</guid><description>&lt;p>Failing to read the documentation and understanding the code underneath is the bane of all software bugs and I&amp;rsquo;ve guilty of it on multiple counts&lt;/p></description></item><item><title>shell hacks</title><link>https://subygan.com/tech/tinkering/shell/</link><pubDate>Tue, 23 Jul 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/shell/</guid><description>&lt;h2 id="number-of-lines-in-a-file">number of lines in a file&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-sh" data-lang="sh">&lt;span style="display:flex;">&lt;span>wc -l file.txt
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="split-file-into-multiple-files">split file into multiple files&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-sh" data-lang="sh">&lt;span style="display:flex;">&lt;span>split -l &lt;span style="color:#ae81ff">1000&lt;/span> file.txt
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="append-two-files-into-one">append two files into one&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-sh" data-lang="sh">&lt;span style="display:flex;">&lt;span>cat file1.txt file2.txt &amp;gt; file3.txt
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="find-pid-of-port">find pid of port&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-sh" data-lang="sh">&lt;span style="display:flex;">&lt;span>sudo lsof -i :&amp;lt;portnumber&amp;gt;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>git lfs</title><link>https://subygan.com/tech/tinkering/git/</link><pubDate>Thu, 11 Jul 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/git/</guid><description>&lt;h2 id="global-gitignore">global gitignore&lt;/h2>
&lt;p>I&amp;rsquo;m surprised I only came to know on 2024 that you can have a global gitignore&lt;/p>
&lt;p>you can just put this inside &lt;code>~/.gitignore&lt;/code>&lt;/p></description></item><item><title>sprites.dev</title><link>https://subygan.com/tech/tinkering/sprites/</link><pubDate>Thu, 11 Jul 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/sprites/</guid><description>&lt;p>I like to have a standard work environment that I can have multiple zellij is important, installing it with,&lt;/p>
&lt;p>&lt;code>cargo install zellij&lt;/code>&lt;/p></description></item><item><title>gccissues</title><link>https://subygan.com/tech/bugs/gcc/</link><pubDate>Sun, 07 Jul 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/bugs/gcc/</guid><description>&lt;p>A simple way to include all available libraries in cpp in most OSs is to just add &lt;code>#include &amp;lt;bits/stdc++.h&amp;gt;&lt;/code>.
This is generall good practice as it includes all the libraries and increases the compilation time.&lt;/p></description></item><item><title>chapter 1 exercises</title><link>https://subygan.com/tech/algos/problems/cp4/00_ch1_ex/</link><pubDate>Sat, 06 Jul 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/problems/cp4/00_ch1_ex/</guid><description>&lt;h3 id="exercise-111">exercise 1.1.1&lt;/h3>
&lt;p>Counter example: &lt;code>{0,0},{0,-1},{0,-2},{0,4},{0,-4},{4,4}&lt;/code>
Greedy value: 6 + 1 + 4 = 11
Correct value: 4 + 4 + 1 = 9&lt;/p></description></item><item><title>a backend engineer writes frontend</title><link>https://subygan.com/tech/bugs/frontend/</link><pubDate>Mon, 06 May 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/bugs/frontend/</guid><description>&lt;p>My friend Limin and I, were playing around with some LLM agents and realized that these agents could be a very good way to learn a language as they have a much better grip on the language and are able to provide great feedbacks.&lt;/p></description></item><item><title>wav file shenanigans</title><link>https://subygan.com/tech/bugs/wav_file/</link><pubDate>Tue, 19 Mar 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/bugs/wav_file/</guid><description>&lt;p>Reading input from users is difficult.
I faced this issue with&lt;/p>
&lt;p>Python&amp;rsquo;s default &lt;code>wave&lt;/code> library throws this error on specific wave file.&lt;/p></description></item><item><title>flutter gimmicks</title><link>https://subygan.com/tech/practice/flutter/flutter_gimmicks/</link><pubDate>Fri, 08 Mar 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/flutter/flutter_gimmicks/</guid><description>&lt;p>Flutter comes with super complex build system that ties in all the language runtimes with dart and the native rendering engine. So, naturally there is a tradeoff between having to build all these things and being slow or reusing builds and being fast but occassionally wrong.
Flutter I think, errs on the latter. So, most times when you feel like flutter is not doing something you think it should be doing, it is because the build got messed up.&lt;/p></description></item><item><title>rust cheatsheet</title><link>https://subygan.com/tech/practice/rust/cheatsheet/</link><pubDate>Wed, 28 Feb 2024 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/rust/cheatsheet/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-rust" data-lang="rust">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">let&lt;/span> x; &lt;span style="color:#75715e">// declare &amp;#34;x&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>x &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">42&lt;/span>; &lt;span style="color:#75715e">// assign 42 to &amp;#34;x&amp;#34;, type is inferred
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>or&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-rust" data-lang="rust">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">let&lt;/span> x &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">42&lt;/span> &lt;span style="color:#75715e">//assigns variable
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">let&lt;/span> x: &lt;span style="color:#66d9ef">i32&lt;/span>; &lt;span style="color:#75715e">//declaring variable &amp;#34;x&amp;#34; of 32 bit integer
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>foobar(x); &lt;span style="color:#75715e">//uninitialised variable assignment
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>x &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">52&lt;/span>; &lt;span style="color:#75715e">// assigning 52
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>foobar(x); &lt;span style="color:#75715e">//x will be called
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>x &lt;span style="color:#f92672">=&lt;/span> x &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#ae81ff">12&lt;/span>; &lt;span style="color:#75715e">// x = 64 now
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">let&lt;/span> _ &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">42&lt;/span>; &lt;span style="color:#75715e">// does nothing, since 42 is a constant and _ is a placeholder
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">let&lt;/span> _ &lt;span style="color:#f92672">=&lt;/span> get_function(); &lt;span style="color:#75715e">//calls function and throws away the result
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">let&lt;/span> _x &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">42&lt;/span>; &lt;span style="color:#75715e">//compiler wont warn about unused variable
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Just like in all languages elements within objects can be called using a dot.&lt;/p></description></item><item><title>42. trapping rain water</title><link>https://subygan.com/tech/algos/problems/leetcode/42_trapping_rain/</link><pubDate>Sun, 26 Nov 2023 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/problems/leetcode/42_trapping_rain/</guid><description>&lt;h2 id="problem-statement">problem statement&lt;/h2>
&lt;p>Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.&lt;/p></description></item><item><title>min in rotated array</title><link>https://subygan.com/tech/algos/problems/leetcode/154_min_in_rotated_arr/</link><pubDate>Sun, 26 Nov 2023 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/problems/leetcode/154_min_in_rotated_arr/</guid><description>&lt;p>Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become:&lt;/p></description></item><item><title>longest valid parentheses</title><link>https://subygan.com/tech/algos/problems/leetcode/32_longest_parentheses/</link><pubDate>Fri, 24 Nov 2023 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/algos/problems/leetcode/32_longest_parentheses/</guid><description>&lt;p>problem link: &lt;a href="https://leetcode.com/problems/longest-valid-parentheses/">https://leetcode.com/problems/longest-valid-parentheses/&lt;/a>
&lt;/p>
&lt;p>Typically, in the parentheses problem a stack is the obvious choice. I spent too much time, chasing a phantom solution by thinking about this as a DP problem and filling various arrays.&lt;/p></description></item><item><title>intellij hacks</title><link>https://subygan.com/tech/tinkering/intellij/</link><pubDate>Mon, 03 Apr 2023 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/intellij/</guid><description>&lt;p>live templates is very useful to record oft repeated patterns&lt;/p>
&lt;p>&lt;code>control + '&lt;/code> to toggle soft wrap in a file&lt;/p></description></item><item><title>system design</title><link>https://subygan.com/tech/practice/sys_design/</link><pubDate>Mon, 03 Apr 2023 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/sys_design/</guid><description>&lt;h2 id="scaling-to-million-users">scaling to million users&lt;/h2>
&lt;ul>
&lt;li>isolate, process and database&lt;/li>
&lt;/ul>
&lt;h3 id="db-scaling">db scaling&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Database replication&lt;/strong> Master(writes,updates), slave(reads) setup for databases helps scale reads in a database
&lt;ul>
&lt;li>When a master node goes down, a slave is selected and promoted to become the master\&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="process-scaling">process scaling&lt;/h3>
&lt;p>Scaling process nodes horizontally in a fan out fashion with a &lt;strong>load balancer&lt;/strong> in front, so that the requests can be distributed between servers. load balancers are able to keep track of the quality of the services. and make decisions on where to send which requests.&lt;/p></description></item><item><title>web</title><link>https://subygan.com/tech/tinkering/web/</link><pubDate>Mon, 03 Apr 2023 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/web/</guid><description>&lt;h3 id="no-cache-image">no cache image&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>curl -s -I -X GET https://i.countdownmail.com/2212f0.gif
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> HTTP/2 &lt;span style="color:#ae81ff">200&lt;/span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> date: Sat, &lt;span style="color:#ae81ff">08&lt;/span> Oct &lt;span style="color:#ae81ff">2022&lt;/span> 07:10:40 GMT
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> content-type: image/gif
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> vary: Accept-Encoding
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cache-control: no-cache,no-store,must-revalidate,max-age&lt;span style="color:#f92672">=&lt;/span>0,proxy-revalidate,no-transform,private
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> pragma: no-cache
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> expires: -1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cf-cache-status: BYPASS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> report-to: &lt;span style="color:#f92672">{&lt;/span>&lt;span style="color:#e6db74">&amp;#34;endpoints&amp;#34;&lt;/span>:&lt;span style="color:#f92672">[{&lt;/span>&lt;span style="color:#e6db74">&amp;#34;url&amp;#34;&lt;/span>:&lt;span style="color:#e6db74">&amp;#34;https:\/\/a.nel.cloudflare.com\/report\/v3?s=ojsVIWtY5FGmXMXpki%2BZhdPypWt9kJuNg1tWhv8q691GSk7n5Y2zuCCtFcFvTP%2FCMdLASEF90CYfW7sTh3rrcdGzwwEHl524UpTYmJrIU9uoFJ%2Br%2FTCOBAiBJeySbcA7UDrt%2Fr3e&amp;#34;&lt;/span>&lt;span style="color:#f92672">}]&lt;/span>,&lt;span style="color:#e6db74">&amp;#34;group&amp;#34;&lt;/span>:&lt;span style="color:#e6db74">&amp;#34;cf-nel&amp;#34;&lt;/span>,&lt;span style="color:#e6db74">&amp;#34;max_age&amp;#34;&lt;/span>:604800&lt;span style="color:#f92672">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> nel: &lt;span style="color:#f92672">{&lt;/span>&lt;span style="color:#e6db74">&amp;#34;success_fraction&amp;#34;&lt;/span>:0,&lt;span style="color:#e6db74">&amp;#34;report_to&amp;#34;&lt;/span>:&lt;span style="color:#e6db74">&amp;#34;cf-nel&amp;#34;&lt;/span>,&lt;span style="color:#e6db74">&amp;#34;max_age&amp;#34;&lt;/span>:604800&lt;span style="color:#f92672">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> server: cloudflare
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cf-ray: 756d0edc3bd13c13-BLR
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> alt-svc: h3&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;:443&amp;#34;&lt;/span>; ma&lt;span style="color:#f92672">=&lt;/span>86400, h3-29&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;:443&amp;#34;&lt;/span>; ma&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">86400&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Basically, this is a service that creates timer gifs. based on the URL. the &lt;code>cache-control&lt;/code> part is the most interesting. This is pretty efficient and asks the browser to not cache anything. This ensures that everytime the cache is new&lt;/p></description></item><item><title>hugo notes</title><link>https://subygan.com/tech/tinkering/hugo/</link><pubDate>Mon, 26 Dec 2022 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/hugo/</guid><description>&lt;h3 id="making-a-nested-map">making a nested map&lt;/h3>
&lt;p>&lt;code>$m := dict (slice &amp;quot;n&amp;quot; &amp;quot;m&amp;quot; &amp;quot;new&amp;quot;) &amp;quot;true&amp;quot;&lt;/code> creates a nested map with &lt;code>m.n.m.new&lt;/code> returning &amp;ldquo;true&amp;rdquo;&lt;/p></description></item><item><title>mapreduce</title><link>https://subygan.com/tech/practice/mapreduce/</link><pubDate>Sat, 24 Dec 2022 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/mapreduce/</guid><description>&lt;p>MapReduce is a programming model published in 2004 by google, to process large data in clusters&lt;/p>
&lt;p>in general, it involves 2 events&lt;/p></description></item><item><title>language design</title><link>https://subygan.com/tech/practice/language_design/</link><pubDate>Sat, 10 Dec 2022 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/language_design/</guid><description>&lt;h2 id="rust-and-ownership">rust and ownership&lt;/h2>
&lt;p>Rust has &lt;strong>no garbage collector&lt;/strong>&lt;/p>
&lt;h2 id="garbage-collectors">garbage collectors&lt;/h2>
&lt;h2 id="scala-and-actor-model">scala and actor model&lt;/h2></description></item><item><title>javascript for impatient programmers</title><link>https://subygan.com/tech/practice/js/js_for_impatient/</link><pubDate>Sun, 06 Nov 2022 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/js/js_for_impatient/</guid><description>&lt;p>These are my notes from following the excellent book, &lt;a href="https://exploringjs.com/impatient-js/index.html">javascript for impatient programmers&lt;/a>
 by axel Rauschmayer&lt;/p>
&lt;h3 id="understanding-let-and-var">understanding let and var&lt;/h3>
&lt;p>The &lt;code>let&lt;/code> keyword creates a new variable locally. it is &lt;strong>not attached to the global object&lt;/strong>&lt;/p></description></item><item><title>regex</title><link>https://subygan.com/tech/practice/regex/</link><pubDate>Sun, 06 Nov 2022 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/regex/</guid><description>&lt;p>?(?!.&lt;em>]).&lt;/em>[^(]) - Select all content between the last &lt;code>?&lt;/code> and the last &lt;code>)&lt;/code> in a line and excludes if &lt;code>]&lt;/code> comes between&lt;/p></description></item><item><title>designing data intensive applications notes</title><link>https://subygan.com/tech/practice/ddia/</link><pubDate>Sun, 23 Oct 2022 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/ddia/</guid><description>&lt;h1 id="ch-1-reliable-scalable-and-maintainable-applications">ch-1: reliable, scalable and maintainable applications&lt;/h1>
&lt;ul>
&lt;li>
&lt;p>reliability, The system should continue to work &lt;strong>correctly&lt;/strong> even in the face of adversity (hw, sw or human).&lt;/p></description></item><item><title>miscelaneous details about golang</title><link>https://subygan.com/tech/practice/golang/misc/</link><pubDate>Mon, 19 Sep 2022 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/golang/misc/</guid><description>&lt;h3 id="go-get-vs-go-install">&lt;code>go get&lt;/code> vs &lt;code>go install&lt;/code>&lt;/h3>
&lt;p>&lt;code>go get&lt;/code>, downloads and adds in GOPATH.
&lt;code>go install&lt;/code>, add&lt;/p>
&lt;h4 id="creating-mutex">creating mutex&lt;/h4>
&lt;p>When embedding a mutex in a struct. any functions associated to the mutex should utilize a pointer receiver.&lt;/p></description></item><item><title>pocketbase</title><link>https://subygan.com/tech/tinkering/pocketbase/</link><pubDate>Thu, 01 Sep 2022 22:15:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/pocketbase/</guid><description>&lt;p>I&amp;rsquo;ve been looking for an alternative to firebase. Because OSS FTW!!&lt;/p>
&lt;p>Pocketbase is an alternative with A bold claim.&lt;/p>
&lt;p>But, it really does 2 things very well, AUTH APIs and CRUD APIs over DBs.&lt;/p></description></item><item><title>visualising performance</title><link>https://subygan.com/tech/tinkering/profiler/</link><pubDate>Wed, 13 Apr 2022 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/profiler/</guid><description>&lt;h3 id="interesting">interesting:&lt;/h3>
&lt;ul>
&lt;li>Flame graphs don&amp;rsquo;t show sequentiality. They are not sorted based on time. They are sorted by alphabets. Which means in the flame graphs, if&lt;/li>
&lt;/ul>
&lt;p>eg.
&lt;figure>
 &lt;img src="https://subygan.com/assets/images/flamegraph.png"
 alt="flamegraph image"
 loading="lazy">
 &lt;figcaption>flamegraph image&lt;/figcaption>
&lt;/figure>
&lt;/p></description></item><item><title>fixing chrome extension issues</title><link>https://subygan.com/tech/bugs/browser_extension/</link><pubDate>Sat, 12 Feb 2022 22:15:00 +0000</pubDate><guid>https://subygan.com/tech/bugs/browser_extension/</guid><description>&lt;p>Bugs in a browser extension are always frustrating because extensions are usually so brittle. There are so many error handling and other challenges.
This is from when I was building one.&lt;/p></description></item><item><title>django issues and quick fixes</title><link>https://subygan.com/tech/tinkering/django/</link><pubDate>Fri, 04 Feb 2022 22:15:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/django/</guid><description>&lt;p>CSRF token invalid &lt;code>__URL__&lt;/code> not in trusted origin&lt;/p>
&lt;p>This happens because there is no &lt;code>CSRF_TRUSTED_ORIGINS&lt;/code> in the settings file. Also make sure that the url &lt;strong>does not have an end slash&lt;/strong>&lt;/p></description></item><item><title>building an extension</title><link>https://subygan.com/tech/tinkering/browser_extension/</link><pubDate>Wed, 02 Feb 2022 22:15:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/browser_extension/</guid><description>&lt;p>browser extensions have been an area of interest for a while. I tried building an extension that would help me save stuff in my &lt;a href="https://subygan.com/readlog">readlog&lt;/a>
. Sort of simply highlight stuff from within the page.&lt;/p></description></item><item><title>searching for a cross platform framework</title><link>https://subygan.com/tech/tinkering/search_cross_platform/</link><pubDate>Sat, 29 Jan 2022 22:15:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/search_cross_platform/</guid><description>&lt;p>This is still a WIP and I&amp;rsquo;ll be updating each one as I discover and play with new stuff.&lt;/p>
&lt;h2 id="why-cross-platform">why cross platform?&lt;/h2>
&lt;p>There are majorly 2 mobile platforms and 3 desktop platforms. Browsers are acting as a cool layer between this, within the realms of which applications are consistently rendered and usability is not spoilt. This is awesome, because now you don&amp;rsquo;t need 5X the development effort to deliver a software experience But only one. Which means velocity can be much faster. But the problem with this, is that &amp;ldquo;websites&amp;rdquo; are not really perceived as serious applicaitons. And there is very little control over the user experience. Native apps are a better way to deliver applications.&lt;/p></description></item><item><title>registering with google and other</title><link>https://subygan.com/tech/tinkering/seo/</link><pubDate>Thu, 23 Dec 2021 22:15:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/seo/</guid><description>&lt;p>Without praying at the altar of google, A site doesn&amp;rsquo;t exist in the internet.&lt;/p>
&lt;p>A site can be registered by visiting &lt;a href="https://search.google.com/search-console">search.google.com&lt;/a>

But, before I&amp;rsquo;m handed over the tools for SEO google does a &amp;ldquo;ownership validation&amp;rdquo;. they gave me a secret of sorts. I had to add a TXT Record in my DNS provider. And verify it.&lt;/p></description></item><item><title>installing jekyll for the first time and issues</title><link>https://subygan.com/tech/tinkering/ruby_v_xcode/</link><pubDate>Tue, 21 Dec 2021 22:15:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/ruby_v_xcode/</guid><description>&lt;p>I was trying to install jekyll in my local machine and faced this error&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in &lt;span style="color:#e6db74">`&lt;/span>try_do&lt;span style="color:#960050;background-color:#1e0010">&amp;#39;&lt;/span>: The compiler failed to generate an executable file. &lt;span style="color:#f92672">(&lt;/span>RuntimeError&lt;span style="color:#f92672">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>You have to install development tools first.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>this was fixed by running&lt;/p></description></item><item><title>local tunnels with cloudflare</title><link>https://subygan.com/tech/tinkering/local_tunnels/</link><pubDate>Tue, 06 Jul 2021 22:15:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/local_tunnels/</guid><description>&lt;h1 id="exposing-local-services-with-cloudflare-tunnels">Exposing Local Services with Cloudflare Tunnels&lt;/h1>
&lt;p>Cloudflare Tunnels let you expose local services to the internet without opening ports or configuring firewalls. Here&amp;rsquo;s how to set it up.&lt;/p></description></item><item><title>ruby hack</title><link>https://subygan.com/tech/tinkering/ruby/</link><pubDate>Tue, 06 Jul 2021 22:15:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/ruby/</guid><description>&lt;p>&lt;code>rvm&lt;/code> is a tool to maintain a Ruby environment.
&lt;code>rvm --default&lt;/code> is a shortcut to set the default Ruby environment.
&lt;code>rvm use&lt;/code> is a shortcut to set the current Ruby environment.&lt;/p></description></item><item><title>searching for a self-hosted vpn</title><link>https://subygan.com/tech/tinkering/vpn/</link><pubDate>Tue, 06 Jul 2021 22:15:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/vpn/</guid><description>&lt;h2 id="goals">goals:&lt;/h2>
&lt;ul>
&lt;li>Find a VPN solution that would be able to maintain an ACL.&lt;/li>
&lt;li>No licensing solutions&lt;/li>
&lt;/ul>
&lt;p>OpenVPN - Not Truly self-hosted, in the sense that you will have to pay for the software in the range of $7 per user. Even if you self host it&lt;/p></description></item><item><title>benchmarking</title><link>https://subygan.com/tech/practice/golang/benchmarking/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/golang/benchmarking/</guid><description>&lt;p>Benchmarking tools are built-in with the &amp;ldquo;testing&amp;rdquo; package&lt;/p>
&lt;p>These can be done by writing test files of the format &amp;ldquo;&lt;x>_test.go&amp;rdquo;&lt;/p></description></item><item><title>custom user agent for testing</title><link>https://subygan.com/tech/tinkering/custom_ua/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/tinkering/custom_ua/</guid><description>&lt;p>A &lt;a href="https://en.wikipedia.org/wiki/User_agent">user-agent&lt;/a>
 is used to recognize the browser and the device the project, &lt;a href="https://developers.whatismybrowser.com/useragents/explore/">whatismybrowser.com&lt;/a>
 have a database of user agents it&amp;rsquo;s just a string that says about your browser and device type that is sent as a cookie in every request. You can find your current user agent by googling &amp;ldquo;&lt;a href="https://www.google.com/search?q=what&amp;#43;is&amp;#43;my&amp;#43;user&amp;#43;agent">what is my user agent&lt;/a>
&amp;rdquo;&lt;/p></description></item><item><title>dart by example</title><link>https://subygan.com/tech/practice/flutter/dart_basics/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/flutter/dart_basics/</guid><description>&lt;h2 id="main">main&lt;/h2>
&lt;p>&lt;code>main()&lt;/code> is the entrypoint for application&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>main() {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print(&lt;span style="color:#e6db74">&amp;#39;Hello, World&amp;#39;&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Also, this works&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>main() &lt;span style="color:#f92672">=&amp;gt;&lt;/span> print(&lt;span style="color:#e6db74">&amp;#39;Hello&amp;#39;&lt;/span>)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="values">values&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>main(){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print( &lt;span style="color:#e6db74">&amp;#34;1+1=&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>&lt;span style="color:#f92672">+&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span> ) &lt;span style="color:#75715e">//prints &amp;#34;1+1=2&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="for">for&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>main(){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">for&lt;/span> (&lt;span style="color:#66d9ef">var&lt;/span> i &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>; i&lt;span style="color:#f92672">&amp;lt;&lt;/span>&lt;span style="color:#ae81ff">3&lt;/span>; i&lt;span style="color:#f92672">++&lt;/span>) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print( i )
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> collection &lt;span style="color:#f92672">=&lt;/span> [&lt;span style="color:#ae81ff">3&lt;/span>,&lt;span style="color:#ae81ff">4&lt;/span>,&lt;span style="color:#ae81ff">5&lt;/span>]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">for&lt;/span> (&lt;span style="color:#66d9ef">var&lt;/span> x &lt;span style="color:#66d9ef">in&lt;/span> collection) { &lt;span style="color:#75715e">//&amp;lt;&amp;lt;-- This works like python
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> print(x)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="conditionals">conditionals&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>main(){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (&lt;span style="color:#ae81ff">7&lt;/span>&lt;span style="color:#f92672">%&lt;/span>&lt;span style="color:#ae81ff">2&lt;/span> &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print(&lt;span style="color:#e6db74">&amp;#39;7 is even&amp;#39;&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ) &lt;span style="color:#66d9ef">else&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print(&lt;span style="color:#e6db74">&amp;#39;7 is odd&amp;#39;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e">//ternary operators
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">var&lt;/span> isAlive &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#66d9ef">true&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> monday &lt;span style="color:#f92672">=&lt;/span> isAlive&lt;span style="color:#f92672">?&lt;/span>&lt;span style="color:#e6db74">&amp;#39;doctor&amp;#39;&lt;/span>&lt;span style="color:#f92672">:&lt;/span> &lt;span style="color:#66d9ef">null&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print(&lt;span style="color:#960050;background-color:#1e0010">`&lt;/span>$moday&lt;span style="color:#960050;background-color:#1e0010">`&lt;/span>) &lt;span style="color:#75715e">//prints &amp;#34;doctor&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="null-aware-operators">null aware operators&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>main(){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> moday &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#39;doctor&amp;#39;&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> tuesday;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> next &lt;span style="color:#f92672">=&lt;/span> tuesday &lt;span style="color:#f92672">??&lt;/span> monday; &lt;span style="color:#75715e">//Assign monday if tuesday is null
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> wednesday;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> next &lt;span style="color:#f92672">??=&lt;/span> wednesday; &lt;span style="color:#75715e">// Assign if not null
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">String&lt;/span> thursday;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> length &lt;span style="color:#f92672">=&lt;/span> thursday&lt;span style="color:#f92672">?&lt;/span>.length; &lt;span style="color:#75715e">//Call function if not null
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="switch">switch&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>main(){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">var&lt;/span> piece &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#39;knight&amp;#39;&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">switch&lt;/span>(piece) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">case&lt;/span> &lt;span style="color:#e6db74">&amp;#39;queen&amp;#39;&lt;/span>&lt;span style="color:#f92672">:&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">case&lt;/span> &lt;span style="color:#e6db74">&amp;#39;bishop&amp;#39;&lt;/span>&lt;span style="color:#f92672">:&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print(&lt;span style="color:#e6db74">&amp;#39;diagonal&amp;#39;&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">case&lt;/span> &lt;span style="color:#e6db74">&amp;#39;knight&amp;#39;&lt;/span>&lt;span style="color:#f92672">:&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print(&lt;span style="color:#e6db74">&amp;#39;L-shape&amp;#39;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>} 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">class&lt;/span> &lt;span style="color:#a6e22e">FoodSpoiledError&lt;/span> &lt;span style="color:#66d9ef">extends&lt;/span> StateError {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> FoodSpoiledError (&lt;span style="color:#66d9ef">String&lt;/span> msg) &lt;span style="color:#f92672">:&lt;/span> &lt;span style="color:#66d9ef">super&lt;/span>(msg);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">class&lt;/span> &lt;span style="color:#a6e22e">Potato&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">int&lt;/span> age;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Potato(&lt;span style="color:#66d9ef">this&lt;/span>.age);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">String&lt;/span> peel() {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (age&lt;span style="color:#f92672">&amp;gt;&lt;/span>&lt;span style="color:#ae81ff">4&lt;/span>) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">throw&lt;/span> &lt;span style="color:#66d9ef">new&lt;/span> FoodSpoiledError(&lt;span style="color:#e6db74">&amp;#39;Potato is spoiled&amp;#39;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#e6db74">&amp;#34;peeled&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>main(){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> p &lt;span style="color:#f92672">=&lt;/span> Potato(&lt;span style="color:#ae81ff">7&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">try&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> p.peel();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> } on FoodSpoiledError &lt;span style="color:#66d9ef">catch&lt;/span>(_) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print(&lt;span style="color:#e6db74">&amp;#34;no&amp;#34;&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">try&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">throw&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;potato&amp;#34;&lt;/span>); &lt;span style="color:#75715e">//Anything can be thrown as an error;
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">catch&lt;/span>(_) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print(&lt;span style="color:#e6db74">&amp;#34;caught potato&amp;#34;&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e">// Exceptions without try catch halt execution
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> p.peel();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="queue">queue&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>main(){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> q &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#66d9ef">new&lt;/span> Queue.from([&lt;span style="color:#ae81ff">300&lt;/span>, &lt;span style="color:#ae81ff">200&lt;/span>, &lt;span style="color:#ae81ff">100&lt;/span>, &lt;span style="color:#ae81ff">500&lt;/span>]); &lt;span style="color:#75715e">//Optimised for adding items to the head or tail.
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e">//Queues implement Iterable
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> print(q.takewhile(i) &lt;span style="color:#f92672">=&amp;gt;&lt;/span> i &lt;span style="color:#f92672">&amp;gt;&lt;/span> &lt;span style="color:#ae81ff">100&lt;/span>)); &lt;span style="color:#75715e">//prints &amp;#34;{300, 200}&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e">//Consuming a queue
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">while&lt;/span> (q.first &lt;span style="color:#f92672">&amp;gt;&lt;/span> &lt;span style="color:#ae81ff">100&lt;/span>) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> q.removeFirst();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print(q); &lt;span style="color:#75715e">//print &amp;#34;{100,500}&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="functions">functions&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>yell(str) &lt;span style="color:#f92672">=&amp;gt;&lt;/span> str.toUpperCase(); &lt;span style="color:#75715e">//Valid function definition
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>List lines(&lt;span style="color:#66d9ef">String&lt;/span> str) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">//^^ Return type
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">return&lt;/span> str.split(&lt;span style="color:#e6db74">&amp;#39;&lt;/span>&lt;span style="color:#ae81ff">\n&lt;/span>&lt;span style="color:#e6db74">&amp;#39;&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>main(){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> poemLines &lt;span style="color:#f92672">=&lt;/span> lines(poem);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print(yell(poemLines.first)); &lt;span style="color:#75715e">//POEM
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e">//Functions are first-class citizens
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">var&lt;/span> whisper &lt;span style="color:#f92672">=&lt;/span> (&lt;span style="color:#66d9ef">String&lt;/span> str) &lt;span style="color:#f92672">=&amp;gt;&lt;/span> str.toLowerCase();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print(poemLines.map(whisper).last; &lt;span style="color:#75715e">//poem
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>poem &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#39;poem&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="optional-parameters">optional parameters&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">String&lt;/span> yell(&lt;span style="color:#66d9ef">String&lt;/span> str, [&lt;span style="color:#66d9ef">bool&lt;/span> exclaim &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#66d9ef">false&lt;/span>]) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// ^^^^^^^^^^^ ordered optional parameter 
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">var&lt;/span> result &lt;span style="color:#f92672">=&lt;/span> str.toLowerCase();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (exclaim) result &lt;span style="color:#f92672">=&lt;/span> result &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#e6db74">&amp;#39;!!!&amp;#39;&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> result
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">String&lt;/span> whisper (&lt;span style="color:#66d9ef">String&lt;/span> str, {&lt;span style="color:#66d9ef">bool&lt;/span> mysteriously:&lt;span style="color:#66d9ef">false&lt;/span>}) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// ^^^^^^^ named optional parameter
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">var&lt;/span> result &lt;span style="color:#f92672">=&lt;/span> str.toLowerCase();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">if&lt;/span> (mysteriously) result &lt;span style="color:#f92672">=&lt;/span> result &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#e6db74">&amp;#39;....&amp;#39;&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> result;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>main() {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print (yell(&lt;span style="color:#e6db74">&amp;#39;Hello, World&amp;#39;&lt;/span>)); &lt;span style="color:#75715e">// prints &amp;#34;Hello, World&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> print (yell(&lt;span style="color:#e6db74">&amp;#39;Hello, World&amp;#39;&lt;/span>, &lt;span style="color:#66d9ef">true&lt;/span>)); &lt;span style="color:#75715e">// prints &amp;#34;Hello, World!!!&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span> print (whisper(&lt;span style="color:#e6db74">&amp;#39;Hello, World&amp;#39;&lt;/span>, mysteriously: &lt;span style="color:#66d9ef">true&lt;/span>));
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="lexical-scope">lexical scope&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">//variables declared inside loops will have a new version each time.
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>main(){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">var&lt;/span> functions &lt;span style="color:#f92672">=&lt;/span> [];
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">for&lt;/span> (&lt;span style="color:#66d9ef">var&lt;/span> i&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">0&lt;/span>; i&lt;span style="color:#f92672">&amp;lt;&lt;/span>&lt;span style="color:#ae81ff">3&lt;/span>; i&lt;span style="color:#f92672">++&lt;/span>) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> functions.add(() &lt;span style="color:#f92672">=&amp;gt;&lt;/span> i);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> functions.forEach((fn) &lt;span style="color:#f92672">=&amp;gt;&lt;/span> print(fn())); &lt;span style="color:#75715e">// prints 0\n1\n2\n
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="typedef">typedef&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">typedef&lt;/span> &lt;span style="color:#66d9ef">bool&lt;/span> Validator(&lt;span style="color:#66d9ef">int&lt;/span> n); &lt;span style="color:#75715e">//Definition of a function to be used
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>main(){
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Validator validate &lt;span style="color:#f92672">=&lt;/span> (&lt;span style="color:#66d9ef">int&lt;/span> n) &lt;span style="color:#f92672">=&amp;gt;&lt;/span> n&lt;span style="color:#f92672">&amp;gt;&lt;/span>&lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> print(&lt;span style="color:#e6db74">&amp;#39;&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>both(&lt;span style="color:#ae81ff">5&lt;/span>)&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">&amp;#39;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="unused-variables">unused variables&lt;/h2>
&lt;ul>
&lt;li>use underscore to silence dartanalyzer&lt;/li>
&lt;/ul>
&lt;h2 id="constants">constants&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-dart" data-lang="dart">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">import&lt;/span> &lt;span style="color:#960050;background-color:#1e0010">`&lt;/span>dart&lt;span style="color:#960050;background-color:#1e0010">:&lt;/span>math&lt;span style="color:#960050;background-color:#1e0010">`&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">const&lt;/span> name &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;greg&amp;#34;&lt;/span>; &lt;span style="color:#75715e">//Compile time variable
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">const&lt;/span> Rectangle bounds &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#66d9ef">const&lt;/span> Rectangle (&lt;span style="color:#ae81ff">0&lt;/span>,&lt;span style="color:#ae81ff">0&lt;/span>,&lt;span style="color:#ae81ff">5&lt;/span>,&lt;span style="color:#ae81ff">5&lt;/span>); &lt;span style="color:#75715e">//Even objects can be declared compile time
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="final">final&lt;/h2>
&lt;p>Final is used when the value is not known at compile time.
The values are immutable&lt;/p></description></item><item><title>effective go practice</title><link>https://subygan.com/tech/practice/golang/Effective_go/01_intro/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/golang/Effective_go/01_intro/</guid><description>&lt;h2 id="formatting">formatting&lt;/h2>
&lt;p>There is no need to align content or comment &lt;code>go fmt&lt;/code> does that for you.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>go fmt &amp;lt;file_path&amp;gt;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>formats the file that is given&lt;/p></description></item><item><title>learning golang 01 - basics</title><link>https://subygan.com/tech/practice/golang/Go_tour/01_Intro/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/golang/Go_tour/01_Intro/</guid><description>&lt;h2 id="intro">intro&lt;/h2>
&lt;ul>
&lt;li>Every go program is made of packages and &amp;ldquo;main&amp;rdquo; package is run first.&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">package&lt;/span> &lt;span style="color:#a6e22e">main&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">import&lt;/span> (
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	&lt;span style="color:#e6db74">&amp;#34;fmt&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	&lt;span style="color:#e6db74">&amp;#34;math/rand&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">main&lt;/span>() {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	&lt;span style="color:#a6e22e">fmt&lt;/span>.&lt;span style="color:#a6e22e">Println&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;My favorite number is&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">rand&lt;/span>.&lt;span style="color:#a6e22e">Intn&lt;/span>(&lt;span style="color:#ae81ff">10&lt;/span>))
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>In the above program math/rand has a file with the first statement &lt;em>package rand&lt;/em>&lt;/p></description></item><item><title>learning golang 02 - ds and algo</title><link>https://subygan.com/tech/practice/golang/Go_tour/02_Data_structures/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/golang/Go_tour/02_Data_structures/</guid><description>&lt;h1 id="arrays">arrays&lt;/h1>
&lt;p>The type &lt;code>[n]T&lt;/code> creates an array of n values of type T.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">var&lt;/span> &lt;span style="color:#a6e22e">a&lt;/span> [&lt;span style="color:#ae81ff">10&lt;/span>]&lt;span style="color:#66d9ef">int&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">//Creates an array &amp;#39;a&amp;#39; of int type with size 10&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="slices">slices&lt;/h3>
&lt;p>An array has a fixed size. A slice is dynamically-sized
The type &lt;code>[]T&lt;/code> is a slice of elements with type T
Slices require high and low point in the array &lt;code>[low:high]&lt;/code>&lt;/p></description></item><item><title>learning golang 03 - functions</title><link>https://subygan.com/tech/practice/golang/Go_tour/03_Functions_and_pointers/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/golang/Go_tour/03_Functions_and_pointers/</guid><description>&lt;h3 id="functions-and-pointers">functions and pointers&lt;/h3>
&lt;p>Functions can receive pointers.
Any change to the pointer would change the value.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-go" data-lang="go">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">package&lt;/span> &lt;span style="color:#a6e22e">main&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">import&lt;/span> &lt;span style="color:#e6db74">&amp;#34;fmt&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">change&lt;/span>(&lt;span style="color:#a6e22e">v&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#66d9ef">int&lt;/span>) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">v&lt;/span> = &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">// ^ required, mentioning that the base value is being changed&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">main&lt;/span>() {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">a&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">12&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">change&lt;/span>(&lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">a&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e">// ^ sending argument as pointer. Throws an error if not.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">fmt&lt;/span>.&lt;span style="color:#a6e22e">Println&lt;/span>(&lt;span style="color:#a6e22e">a&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="function-closures">function closures&lt;/h3>
&lt;p>A function closure references variable from outside the function. Each closure is left to its own values&lt;/p></description></item><item><title>learning golang 04 - goroutine</title><link>https://subygan.com/tech/practice/golang/Go_tour/04_goroutines/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/golang/Go_tour/04_goroutines/</guid><description>&lt;h2 id="goroutines">goroutines&lt;/h2>
&lt;p>Goroutine is a lightweight thread managed by the Go runtime.
a &amp;ldquo;thread&amp;rdquo; does not mean virtual thread or even multiple thread. it is like async await. meaning there is one main thread and multiple seperate &amp;ldquo;threads&amp;rdquo; spawned which are technically running in the same thread instead of spawning one for every process. Each of these threads are blocked when a blocking process is run. and repicked when it is done.&lt;/p></description></item><item><title>learning golang using go by example</title><link>https://subygan.com/tech/practice/golang/GO_BY_EXAMPLE/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://subygan.com/tech/practice/golang/GO_BY_EXAMPLE/</guid><description>&lt;h1 id="go-by-example">go by example.&lt;/h1>
&lt;p>Following eli bendersky&amp;rsquo;s gobyexample.com tutorial the idea is to capture only things that were not clear in the go tour.&lt;/p></description></item></channel></rss>