# rss_item

guid: https://mitjafelicijan.com/create-placeholder-images-with-sharp.html
title: Create placeholder images with sharp Node.js image processing library
url: https://mitjafelicijan.com/create-placeholder-images-with-sharp.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I have been searching for a solution to pre-generate some placeholder images for
image server I needed to develop that resizes images on S3. I though this would
be a 15min job and quickly found out how very mistaken I was.</p>
<p>Even though Node.js is not really the best way to do this kind of things (surely
something written in C or Rust or even Golang would be the correct way to do
this but we didn't need the speed in our case) I found an excellent library
<a href="https://github.com/lovell/sharp">sharp - High performance Node.js image
processing</a>.</p>
<p>Getting things running was a breeze.</p>
<h2 id="fetch-image-from-s3-and-save-resized">Fetch image from S3 and save resized</h2>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">const</span> sharp = require(<span style="color:#a31515">&#39;sharp&#39;</span>);
</span></span><span style="display:flex;"><span><span style="color:#00f">const</span> aws = require(<span style="color:#a31515">&#39;aws-sdk&#39;</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">const</span> x,y = 100;
</span></span><span style="display:flex;"><span><span style="color:#00f">const</span> s3 = <span style="color:#00f">new</span> aws.S3({});
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>aws.config.update({
</span></span><span style="display:flex;"><span>  secretAccessKey: <span style="color:#a31515">&#39;secretAccessKey&#39;</span>,
</span></span><span style="display:flex;"><span>  accessKeyId: <span style="color:#a31515">&#39;accessKeyId&#39;</span>,
</span></span><span style="display:flex;"><span>  region: <span style="color:#a31515">&#39;region&#39;</span>
</span></span><span style="display:flex;"><span>});
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">const</span> originalImage = <span style="color:#00f">await</span> s3.getObject({
</span></span><span style="display:flex;"><span>  Bucket: <span style="color:#a31515">&#39;some-bucket-name&#39;</span>,
</span></span><span style="display:flex;"><span>  Key: <span style="color:#a31515">&#39;image.jpg&#39;</span>,
</span></span><span style="display:flex;"><span>}).promise();
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">const</span> resizedImage = <span style="color:#00f">await</span> sharp(originalImage.Body)
</span></span><span style="display:flex;"><span>  .resize(x, y)
</span></span><span style="display:flex;"><span>  .jpeg({ progressive: <span style="color:#00f">true</span> })
</span></span><span style="display:flex;"><span>  .toBuffer();
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>s3.putObject({
</span></span><span style="display:flex;"><span>  Bucket: <span style="color:#a31515">&#39;some-bucket-name&#39;</span>,
</span></span><span style="display:flex;"><span>  Key: <span style="color:#a31515">`optimized/</span><span style="color:#a31515">${</span>x<span style="color:#a31515">}</span><span style="color:#a31515">x</span><span style="color:#a31515">${</span>y<span style="color:#a31515">}</span><span style="color:#a31515">/image.jpg`</span>,
</span></span><span style="display:flex;"><span>  Body: resizedImage,
</span></span><span style="display:flex;"><span>  ContentType: <span style="color:#a31515">&#39;image/jpeg&#39;</span>,
</span></span><span style="display:flex;"><span>  ACL: <span style="color:#a31515">&#39;public-read&#39;</span>
</span></span><span style="display:flex;"><span>}).promise();
</span></span></code></pre><p>All this code was wrapped inside a web service with some additional security
checks and defensive coding to detect if key is missing on S3.</p>
<p>And at that point I needed to return placeholder images as a response in case
key is missing or x,y are not allowed by the server etc. I could have created
PNG in Gimp and just serve them but I wanted to respect aspect ratio and I
didn't want to return some mangled images.</p>
<blockquote>
<p>Main problem with finding a clean solution I could copy and paste and change a
bit was a task. API is changing constantly and there weren't clear examples or
I was unable to find them.</p>
</blockquote>
<h2 id="generating-placeholder-images-using-svg">Generating placeholder images using SVG</h2>
<p>What I ended up was using SVG to generate text and created image with sharp and
used composition to combine both layers. Response returned by this function is a
buffer you can use to either upload to S3 or save to local file.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">const</span> generatePlaceholderImageWithText = <span style="color:#00f">async</span> (width, height, message) =&gt; {
</span></span><span style="display:flex;"><span>  <span style="color:#00f">const</span> overlay = <span style="color:#a31515">`&lt;svg width=&#34;</span><span style="color:#a31515">${</span>width - 20<span style="color:#a31515">}</span><span style="color:#a31515">&#34; height=&#34;</span><span style="color:#a31515">${</span>height - 20<span style="color:#a31515">}</span><span style="color:#a31515">&#34;&gt;
</span></span></span><span style="display:flex;"><span><span style="color:#a31515">    &lt;text x=&#34;50%&#34; y=&#34;50%&#34; font-family=&#34;sans-serif&#34; font-size=&#34;16&#34; text-anchor=&#34;middle&#34;&gt;</span><span style="color:#a31515">${</span>message<span style="color:#a31515">}</span><span style="color:#a31515">&lt;/text&gt;
</span></span></span><span style="display:flex;"><span><span style="color:#a31515">  &lt;/svg&gt;`</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">return</span> <span style="color:#00f">await</span> sharp({
</span></span><span style="display:flex;"><span>    create: {
</span></span><span style="display:flex;"><span>      width: width,
</span></span><span style="display:flex;"><span>      height: height,
</span></span><span style="display:flex;"><span>      channels: 4,
</span></span><span style="display:flex;"><span>      background: { r: 230, g: 230, b: 230, alpha: 1 }
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>  })
</span></span><span style="display:flex;"><span>    .composite([{
</span></span><span style="display:flex;"><span>      input: Buffer.from(overlay),
</span></span><span style="display:flex;"><span>      gravity: <span style="color:#a31515">&#39;center&#39;</span>,
</span></span><span style="display:flex;"><span>    }])
</span></span><span style="display:flex;"><span>    .jpeg()
</span></span><span style="display:flex;"><span>    .toBuffer();
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>That is about it. Nothing more to it. You can change the color of the image by
changing <code>background</code> and if you want to change text styling you can adapt SVG
to your needs.</p>
<blockquote>
<p>Also be careful about the length of the text. This function positions text at
the center and adds <code>20px</code> padding on all sides. If text is longer than the
image it will get cut.</p>
</blockquote>


guid: https://mitjafelicijan.com/the-strange-case-of-elasticsearch-allocation-failure.html
title: The strange case of Elasticsearch allocation failure
url: https://mitjafelicijan.com/the-strange-case-of-elasticsearch-allocation-failure.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I've been using Elasticsearch in production for 5 years now and never had a
single problem with it. Hell, never even known there could be a problem. Just
worked. All this time. The first node that I deployed is still being used in
production, never updated, upgraded, touched in anyway.</p>
<p>All this bliss came to an abrupt end this Friday when I got notification that
Elasticsearch cluster went warm. Well, warm is not that bad right? Wrong!
Quickly after that I got another email which sent chills down my spine.  Cluster
is now red. RED! Now, shit really hit the fan!</p>
<p>I tried googling what could be the problem and after executing allocation
function noticed that some shards were unassigned and 5 attempts were already
made (which is BTW to my luck the maximum) and that meant I am basically fucked.
They also applied that one should wait for cluster to re-balance itself. So, I
waited. One hour, two hours, several hours. Nothing, still RED.</p>
<p>The strangest thing about it all was, that queries were still being fulfilled.
Data was coming out. On the outside it looked like nothing was wrong but
everybody that would look at the cluster would know immediately that something
was very very wrong and we were living on borrowed time here.</p>
<blockquote>
<p><strong>Please, DO NOT do what I did.</strong> Seriously! Please ask someone on official
forums or if you know an expert please consult him. There could be million of
reasons and these solution fit my problem. Maybe in your case it would
disastrous. I had all the data backed up and even if I would fail spectacularly
I would be able to restore the data. It would be a huge pain and I would loose
couple of days but I had a plan B.</p>
</blockquote>
<p>Executing allocation and told me what the problem was but no clear solution yet.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>GET /_cat/allocation?format=json
</span></span></code></pre><p>I got a message that <code>ALLOCATION_FAILED</code> with additional info <code>failed to create shard, failure ioexception[failed to obtain in-memory shard lock]</code>.  Well
splendid! I must also say that our cluster is capable more than enough to handle
the traffic. Also JVM memory pressure never was an issue. So what happened
really then?</p>
<p>I tried also re-routing failed ones with no success due to AWS restrictions on
having managed Elasticsearch cluster (they lock some of the functions).</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>POST /_cluster/reroute?retry_failed=true
</span></span></code></pre><p>I got a message that significantly reduced my options.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  &#34;Message&#34;: <span style="color:#a31515">&#34;Your request: &#39;/_cluster/reroute&#39; is not allowed.&#34;</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>After that I went on a hunt again. I won't bother you with all the details
because hours/days went by until I was finally able to re-index the problematic
index and hoped for the best. Until that moment even re-indexing was giving me
errors.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>POST _reindex
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  &#34;source&#34;: {
</span></span><span style="display:flex;"><span>    &#34;index&#34;: <span style="color:#a31515">&#34;myindex&#34;</span>
</span></span><span style="display:flex;"><span>  },
</span></span><span style="display:flex;"><span>  &#34;dest&#34;: {
</span></span><span style="display:flex;"><span>    &#34;index&#34;: <span style="color:#a31515">&#34;myindex-new&#34;</span>
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>I needed to do this multiple times to get all the documents re-indexed. Then I
dropped the original one with the following command.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>DELETE /myindex
</span></span></code></pre><p>And re-indexed again new one in the original one (well by name only).</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>POST _reindex
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  &#34;source&#34;: {
</span></span><span style="display:flex;"><span>    &#34;index&#34;: <span style="color:#a31515">&#34;myindex-new&#34;</span>
</span></span><span style="display:flex;"><span>  },
</span></span><span style="display:flex;"><span>  &#34;dest&#34;: {
</span></span><span style="display:flex;"><span>    &#34;index&#34;: <span style="color:#a31515">&#34;myindex&#34;</span>
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>On the surface it looks like all is working but I have a long road in front of
me to get all the things working again. Cluster now shows that it is in Green
mode but I am also getting a notification that the cluster has processing status
which could mean million of things.</p>
<p>Godspeed!</p>


guid: https://mitjafelicijan.com/my-love-and-hate-relationship-with-nodejs.html
title: My love and hate relationship with Node.js
url: https://mitjafelicijan.com/my-love-and-hate-relationship-with-nodejs.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Previous project I was working on was being coded in
<a href="https://golang.org/">Golang</a>. Also was my first project using it. And damn,
that was an awesome experience. The whole thing is just superb. From how errors
are handled. The C-like way you handle compiling. The way the language is
structured making it incredibly versatile and easy to learn.</p>
<p>It may cause some pain for somebody that is not used of using interfaces to map
JSON and doing the recompilation all the time. But we have tools like
<a href="http://eradman.com/entrproject/">entr</a> and
<a href="https://www.gnu.org/software/make/">make</a> to fix that.</p>
<p>But we are not here to talk about my undying love for <strong>Golang</strong>. Only in some
way we probably should. It is an excellent example of how modern language should
be designed. And because I have used it extensively in the last couple of years
this probably taints my views of other languages. And is doing me a great
disservice. Nevertheless, here we are.</p>
<p>About two years ago I started flirting with <a href="https://nodejs.org/en/">Node.js</a>
for a project I started working on. What I wanted was to have things written in
a language that is widely used, and we could get additional developers for.  As
much as <strong>Golang</strong> is amazing it's really hard to get developers for it.  Even
now. And after playing around with it for a week I felt in love with the speed
of iteration and massive package ecosystem. Do you want SSO? You got it!  Do you
want some esoteric library for something? There is a strong chance somebody
wrote it. It is so extensive that you find yourself evaluating packages based on
<strong>GitHub stars</strong> and number of contributors. You get swallowed by the vanity
metrics and that potentially will become the downfall of Node.js.</p>
<p>Because of the sheer amount of choice I often got anxiety when choosing
libraries. Will I choose the correct one? Is this library something that will be
supported for a foreseeable future or not? I am used of using libraries that are
being in development for 10 years plus (Python, C) and that gave me some sort of
comfort. And it is probably unfair to Node.js and community to expect same
dedication.</p>
<p>Moving forward ... Work started and things were great. <strong>Speed of iteration was
insane</strong>. For some feature that I would need a day in Golang only took me hour
or two. I became lazy! Using packages all over the place. Falling into the same
trap as others. Packages on top of packages.  And <a href="https://www.npmjs.com/">npm</a>
didn't help at all. The way that the package manager works is just
horrendous. And not allowing to have node_modules outside the project is also
the stupidest idea ever.</p>
<p>So at that point I started feeling the technical debt that comes with Node.js
and the whole ecosystem. What nobody tells you is that <strong>structuring large
Node.js apps</strong> is more problematic than one would think.  And going microservice
for every single thing is also a bad idea. The amount of networking you
introduce with that approach always ends up being a pain in the ass. And I don't
even want to go into system administration here. The overhead is
insane. Package-lock.json made many days feel like living hell for me. And I
would eat the cost of all this if it meant for better development
experience. Well, it didn't.</p>
<p>The <strong>lack of Typescript</strong> support in the interpreter is still mind boggling to
me. Why haven't they added native support yet for this is beyond me?! That would
have solved so many problems. Lack of type safety became a problem somewhere in
the middle of the project where the codebase was sufficiently large enough to
present problems. We started adding arguments to functions and there was <strong>no
way to implicitly define argument types</strong>. And because at that point there were
a lot of functions, it became impossible to know what each one accepts,
development became more and more trial and error based.</p>
<p>I tried <strong>implementing Typescript</strong>, but that would present a large refactor
that we were not willing to do at that point. The benefits were not enough.  I
also tried <a href="https://flow.org/">Flow - static type checker</a> but implementation
was also horrible. What Typescript and Flow forces you is to have src folder and
then <strong>transpile</strong> your code into dist folder and run it with node. WTH is that
all about. Why can't this be done in memory or some virtual file system?  Why? I
see no reason why this couldn't be done like this. But it is what it is.  I
abandoned all hope for static type checking.</p>
<p>One of the problems that resulted from not having interfaces or types was
inability to model out our data from <strong>Elasticsearch</strong>. I could have done a
<strong>pedestrian implementation</strong> of it, but there must be a better way of doing
this without resorting to some hack basically. Or maybe I haven't found a
solution, which is also a possibility. I have looked, though. No juice!</p>
<p><strong>Error handling?</strong> Is that a joke?</p>
<p>Thank god for <strong>await/async</strong>. Without it, I would have probably just abandoned
the whole thing and went with something else like Python. That's all I am going
to say about this :)</p>
<p>I started asking myself a question if Node.js is actually ready to be used in a
<strong>large scale applications</strong>? And this was a totally wrong question. What I
should have been asking myself was, how to use Node.js in large scale
application. And you don't get this in <strong>marketing material</strong> for Express or Koa
etc. They never tell you this. Making Node.js scale on infrastructure or in
codebase is really <strong>more of an art than a science</strong>. And just like with the
whole JavaScript ecosystem:</p>
<ul>
<li>impossible to master,</li>
<li>half of your time you work on your tooling,</li>
<li>just accept transpilers that convert one code into another (holly smokes),</li>
<li>error handling is a joke,</li>
<li>standards? What standards?</li>
</ul>
<p>But on the other hand. As I did, you will also learn to love it. Learn to use it
quickly and do impossible things in crazy limited time.</p>
<p>I hate to admit it. But I love Node.js. Dammit, I love it :)</p>
<p><strong>2023 Update</strong>: I hate Node.js!</p>


guid: https://mitjafelicijan.com/remote-work.html
title: Remote work and how it affects the daily lives of people
url: https://mitjafelicijan.com/remote-work.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I have been working remotely for the past 5 years. I love it. Love the freedom
and make your schedule thingy.</p>
<h2 id="you-work-more-not-less">You work more not less</h2>
<p>I've heard from people things like: &quot;Oh, you are so lucky, working from home,
having all the free time you want&quot;. It was obvious they had no clue what means
working remotely. They had this romantic idea of remote work. You can watch TV
whenever you like, you can go outside for a picnic if you want and stuff like
that.</p>
<p>This may be true if you work a day or two in a week from home. But if you go
completely remote all these changes completely. I take some time to acclimate
but then you start feeling the consequences of going fully remote. And it's not
all rainbows and unicorns. Rather the opposite.</p>
<h2 id="feeling-lost">Feeling lost</h2>
<p>At first, I remembered I felt lost. I was not used to this kind of environment.
It felt disoriented and a part of you that is used to procrastinate turns on.
You start thinking of a workday as a whole day. And soon this idea of &quot;I can do
this later&quot; starts creeping in. Well, I have the whole day ahead of me. I can do
this a bit later.</p>
<h2 id="hyper-performance">Hyper-performance</h2>
<p>As a direct result, you become more focused on your work since you don't have
all the interruptions common in the workplace. And you can quickly get used to
this hyper-performance. But this mode requires also a lot of peace and quiet.</p>
<p>And here we come to the ugly parts of all this. <strong>People rarely have the
self-control</strong> to not waste other people's time. It is paralyzing when people
start calling you, sending you chat messages, etc. The thing is, that when I
achieve this hyper-performance mode I am completely embroiled in the problem I
am solving and this kind of interruptions mess with your head. I need an hour at
least to get back in the zone. Sometimes not achieving the same focus the whole
day.</p>
<p>I know that life is not how you want it to be and takes its route but from what
I've learned this kind of interruptions can be avoided in 90% of the case easily
just by closing any chat programs and putting your phone in a drawer.</p>
<h2 id="suggestion-to-all-the-new-remote-workers">Suggestion to all the new remote workers</h2>
<ul>
<li>Stop wasting other people's time. You don't bother people at their desks in
the office either.</li>
<li>Do not replace daily chats in the hallways with instant messaging software.
It will only interrupt people. Nothing good will come of it.</li>
<li>Set your working hours and try to not allow it to bleed outside these
boundaries and maintain your routine.</li>
<li>Be prepared that hours will be longer regardless of your good intentions and
your well thought of routine.</li>
<li>Try to be hyper-focused and do only one thing at the time. Multitasking is the
enemy of progress.</li>
<li>Avoid long meetings and if possible eliminate them. Rather take time to write
them out and allow others to respond in their own time. Meetings are usually a
large waste of time and most of the people attending them are there just
because the manager said so.</li>
<li>The software will not solve your problems. And throwing money at problems
neither.</li>
<li>If you are in a managerial position don't supervise any single minute of
workers. They are probably giving you more hours anyways. Track progress
weekly not daily. You hired them and give them the benefit of the doubt that
they will deliver what you agreed upon.</li>
</ul>


guid: https://mitjafelicijan.com/disable-mouse-wake-from-suspend-with-systemd-service.html
title: Disable mouse wake from suspend with systemd service
url: https://mitjafelicijan.com/disable-mouse-wake-from-suspend-with-systemd-service.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I recently bought <a href="https://www.laptopmag.com/reviews/laptops/lenovo-thinkpad-x220">ThinkPad
X220</a> just as a
joke on eBay to test Linux distributions and play around with things and not
destroy my main machine. Little to my knowledge I felt in love with it.  Man,
they really made awesome machines back then.</p>
<p>After changing disk that came with it to SSD and installing Ubuntu to test if 
everything works I noticed that even after a single touch of my external mouse
the system would wake up from sleep even though the lid was shut down.</p>
<p>I wouldn't even noticed it if laptop didn't have <a href="https://support.lenovo.com/lk/en/solutions/~/media/Images/ContentImages/p/pd025386_x1_status_03.ashx?w=426&amp;h=262">LED
sleep indicator</a>.
I already had a bad experience with Linux and it's power management. I had a
<a href="https://www.pcmag.com/reviews/dell-inspiron-15-7537">Dell Inspiron 7537</a> laptop
with a touchscreen and while traveling it decided to wake up and started cooking
in my backpack to the point that the digitizer responsible for touch actually
glue off and the whole screen got wrecked. So, I am a bit touchy about this.</p>
<p>I went on solution hunting and to my surprise there is no easy way to disable
specific devices to perform wake up. Why is this not under the power management 
tab in setting is really strange.</p>
<p>After googling for a solution I found <a href="https://codetrips.com/2020/03/18/ubuntu-disable-mouse-wake-from-suspend/">this nice article describing the
solution</a>
that worked for me. The only problem with this solution was that he added his
solution to <code>.bashrc</code> and this triggers <code>sudo</code> that asks for a password each
time new terminal is opened, which get annoying quickly since I open a lot of
terminals all the time.</p>
<p>I followed his instructions and got to solution <code>sudo sh -c &quot;echo 'disabled' &gt; /sys/bus/usb/devices/2-1.1/power/wakeup&quot;</code>.</p>
<p>I created a system service file <code>sudo nano /etc/systemd/system/disable-mouse-wakeup.service</code> and removed <code>sudo</code> and
replaced <code>sh</code> with <code>/usr/bin/sh</code> and pasted all that in <code>ExecStart</code>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">[Unit]</span>
</span></span><span style="display:flex;"><span>Description=<span style="color:#a31515">Disables wakeup on mouse event</span>
</span></span><span style="display:flex;"><span>After=<span style="color:#a31515">network.target</span>
</span></span><span style="display:flex;"><span>StartLimitIntervalSec=<span style="color:#a31515">0</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">[Service]</span>
</span></span><span style="display:flex;"><span>Type=<span style="color:#a31515">simple</span>
</span></span><span style="display:flex;"><span>Restart=<span style="color:#a31515">always</span>
</span></span><span style="display:flex;"><span>RestartSec=<span style="color:#a31515">1</span>
</span></span><span style="display:flex;"><span>User=<span style="color:#a31515">root</span>
</span></span><span style="display:flex;"><span>ExecStart=<span style="color:#a31515">/usr/bin/sh -c &#34;echo &#39;disabled&#39; &gt; /sys/bus/usb/devices/2-1.1/power/wakeup&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">[Install]</span>
</span></span><span style="display:flex;"><span>WantedBy=<span style="color:#a31515">multi-user.target</span>
</span></span></code></pre><p>After that I enabled, started and checked status of service.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo systemctl enable disable-mouse-wakeup.service
</span></span><span style="display:flex;"><span>sudo systemctl start disable-mouse-wakeup.service
</span></span><span style="display:flex;"><span>sudo systemctl status disable-mouse-wakeup.service
</span></span></code></pre><p>This will permanently disable that device from wakeing up you computer on boot.
If you have many devices you would like to surpress from waking up your machine
I would create a shell script and call that instead of direclty doing it in
service file.</p>


guid: https://mitjafelicijan.com/esp8266-and-micropython-guide.html
title: Getting started with MicroPython and ESP8266
url: https://mitjafelicijan.com/esp8266-and-micropython-guide.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<h2 id="introduction">Introduction</h2>
<p>A while ago I bought some
<a href="https://www.espressif.com/en/products/socs/esp8266">ESP8266</a> and
<a href="https://www.espressif.com/en/products/socs/esp32">ESP32</a> dev boards to play
around with and I finally found a project to try it out.</p>
<p>For my project, I used <a href="https://www.espressif.com/en/products/socs/esp32">ESP32</a>
but I could easily choose
<a href="https://www.espressif.com/en/products/socs/esp8266">ESP8266</a>.  This guide
contains which tools I use and how I prepared my workspace to code for
<a href="https://www.espressif.com/en/products/socs/esp8266">ESP8266</a>.</p>
<figure>
<img src="/assets/posts/esp8366-micropython/boards.jpg" alt="ESP8266 and ESP32 boards" />
</figure>
<p>This guide covers:</p>
<ul>
<li>flashing SOC</li>
<li>install proper tooling</li>
<li>deploying a simple script</li>
</ul>
<blockquote>
<p>Make sure that you are using <strong>a good USB cable</strong>. I had some problems with
mine and once I replaced it everything started to work.</p>
</blockquote>
<h2 id="flashing-the-soc">Flashing the SOC</h2>
<p>Plug your ESP8266 to USB port and check if the device was recognized with
executing <code>dmesg | grep ch341-uart</code>.</p>
<p>Then check if the device is available under <code>/dev/</code> by running <code>ls /dev/ttyUSB*</code>.</p>
<blockquote>
<p><strong>Linux users</strong>: if a device is not available be sure you are in <code>dialout</code>
group. You can check this by executing <code>groups $USER</code>. You can add a user to
<code>dialout</code> group with <code>sudo adduser $USER dialout</code>.</p>
</blockquote>
<p>After these conditions are meet go to the navigate to
<a href="https://micropython.org/download/esp8266/">https://micropython.org/download/esp8266/</a>
and download <code>esp8266-20200902-v1.13.bin</code>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>mkdir esp8266-test
</span></span><span style="display:flex;"><span>cd esp8266-test
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>wget https://micropython.org/resources/firmware/esp8266-20200902-v1.13.bin
</span></span></code></pre><p>After obtaining firmware we will need some tooling to flash the firmware to the
board.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo pip3 install esptool
</span></span></code></pre><p>You can read more about <code>esptool</code> at
<a href="https://github.com/espressif/esptool/">https://github.com/espressif/esptool/</a>.</p>
<p>Before flashing the firmware we need to erase the flash on device. Substitute
<code>USB0</code> with the device listed in output of <code>ls /dev/ttyUSB*</code>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>esptool.py --port /dev/ttyUSB0 erase_flash
</span></span></code></pre><p>If flash was successfully erased it is now time to flash the new firmware to it.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-20200902-v1.13.bin
</span></span></code></pre><p>If everything went ok you can try accessing MicroPython REPL with <code> screen /dev/ttyUSB0 115200</code> or <code>picocom /dev/ttyUSB0 -b115200</code>.</p>
<blockquote>
<p>Sometimes you will need to press <code>ENTER</code> in <code>screen</code> or <code>picocom</code> to access
REPL.</p>
</blockquote>
<p>When you are in REPL you can test if all is working properly following steps.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>&gt; <span style="color:#00f">import</span> machine
</span></span><span style="display:flex;"><span>&gt; machine.freq()
</span></span></code></pre><p>This should output a number representing a frequency of the CPU (mine was
<code>80000000</code>).</p>
<p>When you are in <code>screen</code> or <code>picocom</code> these can help you a bit.</p>
<table>
<thead>
<tr>
<th>Key</th>
<th>Command</th>
</tr>
</thead>
<tbody>
<tr>
<td>CTRL+d</td>
<td>preforms soft reboot</td>
</tr>
<tr>
<td>CTRL+a x</td>
<td>exits picocom</td>
</tr>
<tr>
<td>CTRL+a \</td>
<td>exits screen</td>
</tr>
</tbody>
</table>
<h2 id="install-better-tooling">Install better tooling</h2>
<p>Now, to make our lives a little bit easier there are couple of additional tools
that will make this whole experience a little more bearable.</p>
<p>There are twq cool ways of uploading local files to SOC flash.</p>
<ul>
<li>ampy → <a href="https://github.com/scientifichackers/ampy">https://github.com/scientifichackers/ampy</a></li>
<li>rshell → <a href="https://github.com/dhylands/rshell">https://github.com/dhylands/rshell</a></li>
</ul>
<h3 id="ampy">ampy</h3>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># installing ampy</span>
</span></span><span style="display:flex;"><span>sudo pip3 install adafruit-ampy
</span></span></code></pre><p>Listed below are some common commands I used.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># uploads file to flash</span>
</span></span><span style="display:flex;"><span>ampy --delay 2 --port /dev/ttyUSB0 put boot.py
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># lists file on flash</span>
</span></span><span style="display:flex;"><span>ampy --delay 2 --port /dev/ttyUSB0 ls
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># outputs contents of file on flash</span>
</span></span><span style="display:flex;"><span>ampy --delay 2 --port /dev/ttyUSB0 cat boot.py
</span></span></code></pre><blockquote>
<p>I added <code>delay</code> of 2 seconds because I had problems with executing commands.</p>
</blockquote>
<h3 id="rshell">rshell</h3>
<p>Even though <code>ampy</code> is a cool tool I opted with <code>rshell</code> in the end since it's
much more polished and feature rich.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># installing ampy</span>
</span></span><span style="display:flex;"><span>sudo pip3 install rshell
</span></span></code></pre><p>Now that <code>rshell</code> is installed we can connect to the board.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>rshell --buffer-size=30 -p /dev/ttyUSB0 -a
</span></span></code></pre><p>This will open a shell inside bash and from here you can execute multiple
commands. You can check what is supported with <code>help</code> once you are inside of a
shell.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>m@turing ~/Junk/esp8266-test
</span></span><span style="display:flex;"><span>$ rshell --buffer-size=30 -p /dev/ttyUSB0 -a
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Using buffer-size of 30
</span></span><span style="display:flex;"><span>Connecting to /dev/ttyUSB0 (buffer-size 30)...
</span></span><span style="display:flex;"><span>Trying to connect to REPL  connected
</span></span><span style="display:flex;"><span>Testing <span style="color:#00f">if</span> ubinascii.unhexlify exists ... Y
</span></span><span style="display:flex;"><span>Retrieving root directories ... /boot.py/
</span></span><span style="display:flex;"><span>Setting time ... Sep 06, 2020 23:54:28
</span></span><span style="display:flex;"><span>Evaluating board_name ... pyboard
</span></span><span style="display:flex;"><span>Retrieving time epoch ... Jan 01, 2000
</span></span><span style="display:flex;"><span>Welcome to rshell. Use Control-D (or the exit command) to exit rshell.
</span></span><span style="display:flex;"><span>/home/m/Junk/esp8266-test&gt; help
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Documented commands (type help &lt;topic&gt;):
</span></span><span style="display:flex;"><span>========================================
</span></span><span style="display:flex;"><span>args    cat  connect  date  edit  filesize  help  mkdir  rm     shell
</span></span><span style="display:flex;"><span>boards  cd   cp       echo  exit  filetype  ls    repl   rsync
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Use Control-D (or the exit command) to exit rshell.
</span></span></code></pre><blockquote>
<p>Inside a shell <code>ls</code> will display list of files on your machine. To get list
of files on flash folder <code>/pyboard</code> is remapped inside the shell. To list files
on flash you must perform <code>ls /pyboard</code>.</p>
</blockquote>
<h4 id="moving-files-to-flash">Moving files to flash</h4>
<p>To avoid copying files all the time I used <code>rsync</code> function from the inside of
<code>rshell</code>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>rsync . /pyboard
</span></span></code></pre><h4 id="executing-scripts">Executing scripts</h4>
<p>It is a pain to continuously reboot the device to trigger <code>/pyboard/boot.py</code> and
there is a better way of testing local scripts on remote device.</p>
<p>Lets assume we have <code>src/freq.py</code> file that displays CPU frequency of a remote
device.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># src/freq.py</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">import</span> machine
</span></span><span style="display:flex;"><span>print(machine.freq())
</span></span></code></pre><p>Now lets upload this and execute it.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># syncs files to remove device</span>
</span></span><span style="display:flex;"><span>rsync ./src /pyboard
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># goes into REPL</span>
</span></span><span style="display:flex;"><span>repl
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># we import file by importing it without .py extension and this will run the script</span>
</span></span><span style="display:flex;"><span>&gt; import freq
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># CTRL+x will exit REPL</span>
</span></span></code></pre><h2 id="additional-resources">Additional resources</h2>
<ul>
<li><a href="https://randomnerdtutorials.com/getting-started-micropython-esp32-esp8266/">https://randomnerdtutorials.com/getting-started-micropython-esp32-esp8266/</a></li>
<li><a href="http://docs.micropython.org/en/latest/esp8266/quickref.html">http://docs.micropython.org/en/latest/esp8266/quickref.html</a></li>
</ul>


guid: https://mitjafelicijan.com/bind-warning-on-login-in-ubuntu.html
title: Fix bind warning in .profile on login in Ubuntu
url: https://mitjafelicijan.com/bind-warning-on-login-in-ubuntu.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Recently I moved back to <a href="https://www.gnu.org/software/bash/">bash</a> as my
default shell. I was previously using <a href="https://fishshell.com/">fish</a> and got
used to the cool features it has. But, regardless of that, I wanted to move to a
more standard shell because I was hopping back and forth with exporting
variables and stuff like that which got pretty annoying.</p>
<p>So I embarked on a mission to make <a href="https://www.gnu.org/software/bash/">bash</a>
more like <a href="https://fishshell.com/">fish</a> and in the process found that I really
missed autosuggest with TAB on changing directories.</p>
<p>I found a nice alternative that emulates <a href="http://zsh.sourceforge.net/">zsh</a> like
autosuggestion and autocomplete so I added the following to my <code>.bashrc</code> file.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>bind <span style="color:#a31515">&#34;TAB:menu-complete&#34;</span>
</span></span><span style="display:flex;"><span>bind <span style="color:#a31515">&#34;set show-all-if-ambiguous on&#34;</span>
</span></span><span style="display:flex;"><span>bind <span style="color:#a31515">&#34;set completion-ignore-case on&#34;</span>
</span></span><span style="display:flex;"><span>bind <span style="color:#a31515">&#34;set menu-complete-display-prefix on&#34;</span>
</span></span><span style="display:flex;"><span>bind <span style="color:#a31515">&#39;&#34;\e[Z&#34;:menu-complete-backward&#39;</span>
</span></span></code></pre><p>I haven't noticed anything wrong with this and all was working fine until I
restarted my machine and then I got this error.</p>
<figure>
<img src="/assets/posts/profile-bind-error/error.jpg" alt="Profile bind error" />
</figure>
<p>When I pressed OK, I got into the <a href="https://wiki.gnome.org/Projects/GnomeShell">Gnome
shell</a> and all was working fine, but
the error was still bugging me. I started looking for the reason why this is
happening and found a solution to this error on <a href="https://superuser.com/a/892682">Remote SSH Commands - bash bind
warning: line editing not enabled</a>.</p>
<p>So I added a simple <code>if [ -t 1 ]</code> around <code>bind</code> statements to avoid running
commands that presume the session is interactive when it isn't.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">if</span> [ -t 1 ]; <span style="color:#00f">then</span>
</span></span><span style="display:flex;"><span>  bind <span style="color:#a31515">&#34;TAB:menu-complete&#34;</span>
</span></span><span style="display:flex;"><span>  bind <span style="color:#a31515">&#34;set show-all-if-ambiguous on&#34;</span>
</span></span><span style="display:flex;"><span>  bind <span style="color:#a31515">&#34;set completion-ignore-case on&#34;</span>
</span></span><span style="display:flex;"><span>  bind <span style="color:#a31515">&#34;set menu-complete-display-prefix on&#34;</span>
</span></span><span style="display:flex;"><span>  bind <span style="color:#a31515">&#39;&#34;\e[Z&#34;:menu-complete-backward&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#00f">fi</span>
</span></span></code></pre><p>After logging out and back in the problem was gone.</p>


guid: https://mitjafelicijan.com/digitalocean-spaces-to-sync-between-computers.html
title: Using Digitalocean Spaces to sync between computers
url: https://mitjafelicijan.com/digitalocean-spaces-to-sync-between-computers.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I've been using <a href="https://www.dropbox.com/">Dropbox</a> for probably <strong>10+ years</strong>
now and I-ve became so used to it that it runs in the background that I don't
even imagine a world without it. But it's not without problems.</p>
<p>At first I had problems with <code>.venv</code> environments for Python and the only
solution for excluding synchronization for this folder was to manually exclude a
specific folder which is not really scalable. FYI, my whole project folder is
synced on <a href="https://www.dropbox.com/">Dropbox</a>. This of course introduced a lot
of syncing of files and folders that are not needed or even break things on
other machines. In the case of <strong>Python</strong>, I couldn't use that on my second
machine. I needed to delete <code>.venv</code> folder and pip it again which synced files
again to the main machine. This was very frustrating. <strong>Nodejs</strong> handles this
much nicer and I can just run the scripts without deleting <code>node_modules</code> again
and reinstalling. However, <code>node_modules</code> is a beast of its own. It creates so
many files that OS has a problem counting them when you check the folder
contents for size.</p>
<p>I wanted something similar to Dropbox. I could without the instant syncing but
it would need to be fast and had the option for me to exclude folders like
<code>node_modules, .venv, .git</code> and folders like that.</p>
<p>I went on a hunt for an alternative to <a href="https://www.dropbox.com/">Dropbox</a>
and found:</p>
<ul>
<li><a href="https://tresorit.com/">Tresorit</a></li>
<li><a href="https://sync.com">Sync.com</a></li>
<li><a href="https://www.box.com/">Box</a></li>
</ul>
<p>You know, the usual list of suspects. I didn't include <a href="https://drive.google.com">Google
drive</a> or <a href="https://onedrive.live.com/">One drive</a>
since they are even more draconian than Dropbox.</p>
<blockquote>
<p>All this does not stem from me being paranoid but recently these companies
have became more and more aggressive and they keep violating our privacy when
they share our data with 3rd party services. It is getting out of control.</p>
</blockquote>
<p>So, my main problem was still there. No way of excluding a specific folder from
syncing. And before we go into &quot;<em>But you have git, isn't that enough?</em>&quot;, I must
say, that many of the files (PDFs, spreadsheets, etc) I have in a <code>git</code> repo
don't get pushed upstream to Git and I still want to have them synced across my
computers.</p>
<p>I initially wanted to use <a href="https://linux.die.net/man/1/rsync">rsync</a> but I would
need to then have a remote VPS or transfer between my computers directly.  I
wanted a solution where all my files could be accessible to me without my
machine.</p>
<blockquote>
<p><strong>WARNING: This solution will cost you money!</strong> DigitalOcean Spaces are $5 per
month and there are some bandwidth limitations and if you go beyond that you get
billed additionally.</p>
</blockquote>
<p>Then I remembered that I could use something like
<a href="https://en.wikipedia.org/wiki/Amazon_S3">S3</a> since it has versioning and is
fully managed. I didn't want to go down the AWS rabbit hole with this so I
choose <a href="https://www.digitalocean.com/products/spaces/">DigitalOcean Spaces</a>.</p>
<p>Then I needed a command-line tool to sync between source and target. I found
this nice tool <a href="https://s3tools.org/s3cmd">s3cmd</a> and it is in the Ubuntu
repositories.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo apt install s3cmd
</span></span></code></pre><p>After installation will I create a new Space bucket on DigitalOcean. Remember
the zone you will choose because you will need it when you will configure
<code>s3cmd</code>.</p>
<p>Then I visited <a href="https://cloud.digitalocean.com/account/api/tokens">Digitalocean Applications &amp;
API</a> and generated <strong>Spaces
access keys</strong>. Save both key and secret somewhere safe because when you will
leave the page secret will not be available anymore to you and you will need to
re-generate it.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># enter your key and secret and correct endpoint</span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># my endpoint is ams3.digitaloceanspaces.com because</span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># I created my bucket in Amsterdam regiin</span>
</span></span><span style="display:flex;"><span>s3cmd --configure
</span></span></code></pre><p>After that I played around with options for <code>s3cmd</code> and got to the following
command.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># I executed this command from my projects folder</span>
</span></span><span style="display:flex;"><span>cd projects
</span></span><span style="display:flex;"><span>s3cmd sync --delete-removed --exclude <span style="color:#a31515">&#39;node_modules/*&#39;</span> --exclude <span style="color:#a31515">&#39;.git/*&#39;</span> --exclude <span style="color:#a31515">&#39;.venv/*&#39;</span> ./ s3://my-bucket-name/projects/
</span></span></code></pre><p>When syncing int he other direction you will need to change the order of the
<code>SOURCE</code> and <code>TARGET</code> to <code>s3://my-bucket-name/projects/</code> and <code>./</code>.</p>
<blockquote>
<p>Be sure that all the paths have trailing slash so that sync knows that this
are directories.</p>
</blockquote>
<p>I am planning to implement some sort of a <code>.ignore</code> file that will enable me to
have a project-specific exclude options.</p>
<p>I am currently running this every hour as a cronjob which is perfectly fine for
now when I am testing how this whole thing works and how it all will turn out.</p>
<p>I have also created a small Gnome extension which is still very unstable, but
when/if this whole experiment pays of I will share on Github.</p>


guid: https://mitjafelicijan.com/replacing-dropbox-in-favor-of-digitalocean-spaces.html
title: Replacing Dropbox in favor of DigitalOcean spaces
url: https://mitjafelicijan.com/replacing-dropbox-in-favor-of-digitalocean-spaces.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>A few months ago I experimented with DigitalOcean spaces as my backup solution
that could <a href="/digitalocean-spaces-to-sync-between-computers.html">replace Dropbox
eventually</a>.  That solution
worked quite nicely, and I was amazed how smashing together a couple of existing
solutions would work this fine.</p>
<p>I have been running that solution in the background for a couple of months now
and kind of forgot about it. But recent developments around deplatforming and
having us people hostages of technology and big companies speed up my goals to
become less dependent on
<a href="https://edition.cnn.com/2020/12/17/tech/google-antitrust-lawsuit/index.html">Google</a>,
<a href="https://www.pcworld.com/article/2048680/dropbox-takes-a-peek-at-files.html">Dropbox</a>
etc and take back some control.</p>
<p>I am not a conspiracy theory nut, but to be honest, what these companies are
doing lately is out of control. It is a matter of principle at this point. I
have almost completely degoogled my life all the way from ditching Gmail,
YouTube and most of the services surrounding Google. And I must tell you, I feel
so good. I haven't felt this way for a long time.</p>
<p><strong>Anyways. Let's get to the meat of things.</strong></p>
<p>Before you continue you should read my post about <a href="/digitalocean-spaces-to-sync-between-computers.html">syncing to
Dropbox</a>.</p>
<blockquote>
<p>Also to note, I am using Linux on my machine with Gnome desktop environment.
This should work on MacOS too. To use this on Windows I suggest using
<a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">Subsystem for Linux</a>
or <a href="https://www.cygwin.com/">Cygwin</a>.</p>
</blockquote>
<h2 id="folder-structure">Folder structure</h2>
<p>I liked structure from Dropbox. One folder where everything is located and
synced. So, that's why adopted this also for my sync setup.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="">~</span>/Vault
</span></span><span style="display:flex;"><span>   <span style="">↳</span> backup
</span></span><span style="display:flex;"><span>   <span style="">↳</span> bin
</span></span><span style="display:flex;"><span>   <span style="">↳</span> documents
</span></span><span style="display:flex;"><span>   <span style="">↳</span> projects
</span></span></code></pre><p>All of my code is located in <code>~/Vault/projects</code> folder. And most of the projects
are Git repositories. I do not use this sync method for backup per see but in
case I reinstall my machine I can easily recreate all the important folder
structure with one quick command. No external drives needed that can fail etc.</p>
<h2 id="sync-script">Sync script</h2>
<p>My sync script is located in <code>~/Vault/bin/vault-backup.sh</code></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#00f"></span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># dconf load /com/gexperts/Tilix/ &lt; tilix.dconf</span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># 0 2 * * * sh ~/Vault/bin/vault-backup.sh</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>cd ~/Vault/backup/dotfiles
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>MACHINE=<span style="color:#00f">$(</span>whoami<span style="color:#00f">)</span>@<span style="color:#00f">$(</span>hostname<span style="color:#00f">)</span>
</span></span><span style="display:flex;"><span>mkdir -p $MACHINE
</span></span><span style="display:flex;"><span>cd $MACHINE
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>cp ~/.config/VSCodium/User/settings.json settings.json
</span></span><span style="display:flex;"><span>cp ~/.s3cfg s3cfg
</span></span><span style="display:flex;"><span>cp ~/.bash_extended bash_extended
</span></span><span style="display:flex;"><span>cp ~/.ssh ssh -rf
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>codium --list-extensions &gt; vscode-extension.txt
</span></span><span style="display:flex;"><span>dconf dump /com/gexperts/Tilix/ &gt; tilix.dconf
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>cd ~/Vault
</span></span><span style="display:flex;"><span>s3cmd sync --delete-removed --exclude <span style="color:#a31515">&#39;node_modules/*&#39;</span> --exclude <span style="color:#a31515">&#39;.git/*&#39;</span> --exclude <span style="color:#a31515">&#39;.venv/*&#39;</span> ./ s3://bucket-name/backup/
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>echo <span style="color:#a31515">`</span>date +<span style="color:#a31515">&#34;%D %T&#34;</span><span style="color:#a31515">`</span> &gt;&gt; ~/.vault.log
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>notify-send <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>	-u normal <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>	-i /usr/share/icons/Adwaita/96x96/status/security-medium-symbolic.symbolic.png <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>	<span style="color:#a31515">&#34;Vault sync succeded at `date +&#34;</span>%D %T<span style="color:#a31515">&#34;`&#34;</span>
</span></span></code></pre><p>This script also backups some of the dotfiles I use and sends notification to
Gnome notification center. It is a straightforward solution. Nothing special
going on.</p>
<blockquote>
<p>One obvious benefit of this is that I can omit syncing Node's <code>node_modules</code>
or Python's <code>.venv</code> and <code>.git</code> folders.</p>
</blockquote>
<p>You can use this script in a combination with <a href="https://en.wikipedia.org/wiki/Cron">Cron</a>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>0 2 * * * sh ~/Vault/bin/vault-backup.sh
</span></span></code></pre><p>When you start syncing your local stuff with a remote server you can review your
items on DigitalOcean.</p>
<figure>
<img src="/assets/posts/dropbox-sync/dropbox-spaces.png" alt="Dropbox Spaces" />
</figure>
<p>I have been using this script now for quite some time, and it's working
flawlessly. I also uninstalled Dropbox and stopped using it completely.</p>
<p>All I need to do is write a Bash script that does the reverse and downloads from
remote server to local folder. This could be another post.</p>


guid: https://mitjafelicijan.com/using-goaccess-with-nginx-to-replace-google-analytics.html
title: Using GoAccess with Nginx to replace Google Analytics
url: https://mitjafelicijan.com/using-goaccess-with-nginx-to-replace-google-analytics.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<h2 id="introduction">Introduction</h2>
<p>I know! You cannot simply replace Google Analytics with parsing access logs and
displaying a couple of charts. But to be honest, I actually never used Google
Analytics to the fullest extent and was usually interested in seeing page hits
and which pages were visited most often.</p>
<p>I recently moved my blog from Firebase to a VPS and also decided to remove
Google Analytics tracking code from the site since its quite malicious and
tracks users across other pages also and is creating a profile of a user, and
I've had it. But I also need some insight of what is happening on a server and
which content is being read the most etc.</p>
<p>I have looked at many existing solutions like:</p>
<ul>
<li><a href="https://umami.is/">Umami</a></li>
<li><a href="https://github.com/sheshbabu/freshlytics">Freshlytics</a></li>
<li><a href="https://matomo.org/">Matomo</a></li>
</ul>
<p>But the more I looked at them the more I noticed that I am replacing one evil
with another one. Don't get me wrong. Some of these solutions are absolutely
fantastic but would require installation of databases and something like PHP or
Node. And I was not ready to put those things on my fresh server. Also having
Docker installed is out of the question.</p>
<h2 id="opting-for-log-parsing">Opting for log parsing</h2>
<p>So, I defaulted to parsing already existing logs and generating HTML reports
from this data.</p>
<p>I found this amazing software <a href="https://goaccess.io/">GoAccess</a> which provides
all the functionalities I need, and it's a single binary. Written in Go.</p>
<p>GoAccess can be used in two different modes.</p>
<figure>
<img src="/assets/posts/goaccess/goaccess-dash-term.png" alt="GoAccess Terminal" />
</figure>
<p><em>Running in a terminal</em></p>
<figure>
<img src="/assets/posts/goaccess/goaccess-dash-html.png" alt="GoAccess HTML" />
</figure>
<p><em>Running in a browser</em></p>
<p>I, however, need this to run in a browser. So, the second option is the way to
go. The Idea is to periodically run cronjob and export this report into a folder
that gets then server by Nginx behind a Basic authentication.</p>
<h2 id="getting-nginx-ready">Getting Nginx ready</h2>
<p>I choose Ubuntu on <a href="https://www.digitalocean.com/">DigitalOcean</a>. First I
installed <a href="https://nginx.org/en/">Nginx</a>, and
<a href="https://letsencrypt.org/getting-started/">Letsencrypt</a> certbot and all the
necessary dependencies.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># log in as root user</span>
</span></span><span style="display:flex;"><span>sudo su -
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># first let&#39;s update the system</span>
</span></span><span style="display:flex;"><span>apt update &amp;&amp; apt upgrade -y
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># let&#39;s install</span>
</span></span><span style="display:flex;"><span>apt install nginx certbot python3-certbot-nginx apache2-utils
</span></span></code></pre><p>After all this is installed we can create a new configuration for a statistics.
Stats will be available at <code>stats.domain.com</code>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># creates directory where html will be hosted</span>
</span></span><span style="display:flex;"><span>mkdir -p /var/www/html/stats.domain.com
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>cp /etc/nginx/sites-available/default /etc/nginx/sites-available/stats.domain.com
</span></span><span style="display:flex;"><span>nano /etc/nginx/sites-available/stats.domain.com
</span></span></code></pre><pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">server</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#00f">root</span> <span style="color:#a31515">/var/www/html/stats.domain.com</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#00f">server_name</span> <span style="color:#a31515">stats.domain.com</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">index</span> <span style="color:#a31515">index.html</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#00f">location</span> <span style="color:#a31515">/</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#00f">try_files</span> $uri $uri/ =404;
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>Now we check if the configuration is ok. We can do this with <code>nginx -t</code>. If all
is ok, we can restart Nginx with <code>service nginx restart</code>.</p>
<p>After all that you should add A record for this domain that points to IP of a
droplet.</p>
<p>Before enabling SSL you should test if DNS records have propagated with <code>curl stats.domain.com</code>.</p>
<p>Now, it's time to provision TLS certificate. To achieve this, you execute
command <code>certbot --nginx</code>. Follow the wizard and when you are asked about
redirection always choose 2 (always redirect to HTTPS).</p>
<p>When this is done you can visit <a href="https://stats.domain.com">https://stats.domain.com</a> and you should get 404
not found error which is correct.</p>
<h2 id="getting-goaccess-ready">Getting GoAccess ready</h2>
<p>If you are using Debian like system GoAccess should be available in repository.
Otherwise refer to the official website.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>apt install goaccess
</span></span></code></pre><p>To enable Geo location we also need one additiona thing.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>cd /var/www/html/stats.stats.com
</span></span><span style="display:flex;"><span>wget https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-City.mmdb
</span></span></code></pre><p>Now we create a shell script that will be executed every 10 minutes.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>nano /var/www/html/stats.domain.com/generate-stats.sh
</span></span></code></pre><p>Contents of this file should look like this.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">#!/bin/sh
</span></span></span><span style="display:flex;"><span><span style="color:#00f"></span>
</span></span><span style="display:flex;"><span>zcat -f /var/log/nginx/access.log* &gt; /var/log/nginx/access-all.log
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>goaccess <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --log-file=/var/log/nginx/access-all.log <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --log-format=COMBINED <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --exclude-ip=0.0.0.0 <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --geoip-database=/var/www/html/stats.domain.com/GeoLite2-City.mmdb <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --ignore-crawlers <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --real-os <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --output=/var/www/html/stats.domain.com/index.html
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>rm /var/log/nginx/access-all.log
</span></span></code></pre><p>Because after a while nginx creates multiple files with access logs we use
<a href="https://linux.die.net/man/1/zcat"><code>zcat</code></a> to extract Gziped contents and create
a file that has all the access logs. After this file is used we delete it.</p>
<p>If you want to exclude your home IP's result look at the <code>--exclude-ip</code> option
in script and instead of <code>0.0.0.0</code> add your own home IP address. You can find
your home IP by executing <code>curl ifconfig.me</code> from your local machine and NOT
from the droplet.</p>
<p>Test the script by executing <code>sh /var/www/html/stats.domain.com/generate-stats.sh</code> and then checking
<code>https://stats.domain.com</code>. If you can see stats instead of 404 than you are
set.</p>
<p>It's time to add this script to cron with <code>cron -e</code>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>*/10 * * * * sh /<span style="color:#00f">var</span>/www/html/stats.domain.com/generate-stats.sh
</span></span></code></pre><h2 id="securing-with-basic-authentication">Securing with Basic authentication</h2>
<p>You probably don't want stats to be publicly available, so we should create a
user and a password for Basic authentication.</p>
<p>First we create a password for a user <code>stats</code> with <code>htpasswd -c /etc/nginx/.htpasswd stats</code>.</p>
<p>Now we update config file with <code>nano /etc/nginx/sites-available/stats.domain.com</code>.  You probably noticed that the
file looks a bit different from before. This is because <code>certbot</code> added
additional rules for SSL.</p>
<p>Your location portion the config file should now look like. You should add
<code>auth_basic</code> and <code>auth_basic_user_file</code> lines to the file.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">location</span> <span style="color:#a31515">/</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#00f">try_files</span> $uri $uri/ =404;
</span></span><span style="display:flex;"><span>  <span style="color:#00f">auth_basic</span> <span style="color:#a31515">&#34;Private</span> <span style="color:#a31515">Property&#34;</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#00f">auth_basic_user_file</span> <span style="color:#a31515">/etc/nginx/.htpasswd</span>;
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>Test if config is still ok with <code>nginx -t</code> and if it is you can restart Nginx
with <code>service nginx restart</code>.</p>
<p>If you now visit <code>https://stats.domain.com</code> you should be prompted for username
and password. If not, try reopening your browser.</p>
<p>That is all. You now have analytics for your server that gets refreshed every 10
minutes.</p>


guid: https://mitjafelicijan.com/simple-world-clock-with-eiink-display-and-raspberry-pi-zero.html
title: Simple world clock with eInk display and Raspberry Pi Zero
url: https://mitjafelicijan.com/simple-world-clock-with-eiink-display-and-raspberry-pi-zero.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Our team is spread across the world, from the USA all the way to Australia, so
having some sort of world clock makes sense.</p>
<p>Currently, I am using an extension for Gnome called <a href="https://extensions.gnome.org/extension/2657/timezones-extension/">Timezone
extension</a>,
and it serves the purpose quite well.</p>
<p>But I also have a bunch of electronics that I bought through the time, and I am
not using any of them, and it's time to stop hording this stuff and use it in a
project.</p>
<p>A while ago I bought a small eInk display <a href="https://shop.pimoroni.com/products/inky-phat?variant=12549254217811">Inky
pHAT</a> and I
have a bunch of <a href="https://www.raspberrypi.org/products/raspberry-pi-zero/">Raspberry Pi's
Zero</a> lying around that
I really need to use.</p>
<figure>
<img src="/assets/posts/world-clock/hardware.jpg" alt="Inky pHAT, Raspberry Pi Zero" />
</figure>
<p>Since the Inky <a href="https://shop.pimoroni.com/products/inky-phat?variant=12549254217811">Inky
pHAT</a> is
essentially a HAT, it can easily be added on top of the <a href="https://www.raspberrypi.org/products/raspberry-pi-zero/">Raspberry Pi
Zero</a>.</p>
<p>First, I installed the necessary software on Raspberry Pi with <code>pip3 install inky</code>.</p>
<p>And then I created a file <code>clock.py</code> in home directory <code>/home/pi</code>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000">#!/usr/bin/env python</span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># -*- coding: utf-8 -*-</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">import</span> sys
</span></span><span style="display:flex;"><span><span style="color:#00f">import</span> os
</span></span><span style="display:flex;"><span><span style="color:#00f">from</span> inky.auto <span style="color:#00f">import</span> auto
</span></span><span style="display:flex;"><span><span style="color:#00f">from</span> PIL <span style="color:#00f">import</span> Image, ImageFont, ImageDraw
</span></span><span style="display:flex;"><span><span style="color:#00f">from</span> font_fredoka_one <span style="color:#00f">import</span> FredokaOne
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>clocks = [
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#39;America/New_York&#39;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#39;Europe/Ljubljana&#39;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#39;Australia/Brisbane&#39;</span>,
</span></span><span style="display:flex;"><span>]
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>board = auto()
</span></span><span style="display:flex;"><span>board.set_border(board.WHITE)
</span></span><span style="display:flex;"><span>board.rotation = 90
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>img = Image.new(<span style="color:#a31515">&#39;P&#39;</span>, (board.WIDTH, board.HEIGHT))
</span></span><span style="display:flex;"><span>draw = ImageDraw.Draw(img)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>big_font = ImageFont.truetype(FredokaOne, 18)
</span></span><span style="display:flex;"><span>small_font = ImageFont.truetype(FredokaOne, 13)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>x = board.WIDTH / 3
</span></span><span style="display:flex;"><span>y = board.HEIGHT / 3
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>idx = 1
</span></span><span style="display:flex;"><span><span style="color:#00f">for</span> clock <span style="color:#00f">in</span> clocks:
</span></span><span style="display:flex;"><span>  ctime = os.popen(<span style="color:#a31515">&#39;TZ=&#34;</span><span style="color:#a31515">{}</span><span style="color:#a31515">&#34; date +&#34;</span><span style="color:#a31515">%a</span><span style="color:#a31515">,%H:%M&#34;&#39;</span>.format(clock))
</span></span><span style="display:flex;"><span>  ctime = ctime.read().strip().split(<span style="color:#a31515">&#39;,&#39;</span>)
</span></span><span style="display:flex;"><span>  city = clock.split(<span style="color:#a31515">&#39;/&#39;</span>)[1].replace(<span style="color:#a31515">&#39;_&#39;</span>, <span style="color:#a31515">&#39; &#39;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  draw.text((15, (idx*y)-y+10), city, fill=board.BLACK, font=small_font)
</span></span><span style="display:flex;"><span>  draw.text((110, (idx*y)-y+7), str(ctime[0]), fill=board.BLACK, font=big_font)
</span></span><span style="display:flex;"><span>  draw.text((155, (idx*y)-y+7), str(ctime[1]), fill=board.BLACK, font=big_font)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  idx += 1
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>board.set_image(img)
</span></span><span style="display:flex;"><span>board.show()
</span></span></code></pre><p>And because eInk displays are rather slow to refresh and the clock requires
refreshing only once a minute, this can be done through cronjob.</p>
<p>Before we add this job to cron we need to make <code>clock.py</code> executable with <code>chmod +x clock.py</code>.</p>
<p>Then we add a cronjob with <code>crontab -e</code>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>* * * * * /home/pi/clock.py
</span></span></code></pre><p>So, we end up with a result like this.</p>
<figure>
<img src="/assets/posts/world-clock/world-clock.jpg" alt="World Clock" />
</figure>
<p>You can download my <a href="/assets/posts/world-clock/enclosure.stl">STL file for the enclosure
here</a>, but make sure that dimensions make
sense and also opening for USB port should be added or just use a drill and some
hot glue to make it stick in the enclosure.</p>


guid: https://mitjafelicijan.com/from-internet-consumer-to-full-hominum-again.html
title: My journey from being an internet über consumer to being a full hominum again
url: https://mitjafelicijan.com/from-internet-consumer-to-full-hominum-again.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>It's been almost a year since I started purging all my online accounts and
going down this rabbit hole of being almost independent of the current internet
machine. Even though I initially thought that I will have problems adapting,
I was pleasantly surprised that the transition went so smoothly. Even better,
it brought many benefits to my life. Such as increased focus, less stress
about trivial things, etc.</p>
<p>It all started with me doing small changes like unsubscribing from emails that I
have either subscribed to by accepting terms and conditions. Or even some more
malicious emails that I was getting because I was on a shared mailing list. And
the later ones I hate the most of all. How the hell do they keep sharing my
email and sending me unsolicited emails and get away with it? I have a suspicion
that these marketing people share an Excel file between them and keep
resubscribing me when they import lists into Mailchimp or similar software.</p>
<p>It's fascinating to see how much crap you get subscribed to when you are not
paying attention. It got so bad that my primary Gmail address is a full of junk
and need constant monitoring and cleaning up. And because I want to have Inbox
Zero, this presents an additional problem for me.</p>
<p>The stress that email presented for me didn't occur to me for a long time. I was
noticing that I was unable to go through one single hour without hysterically
refreshing email. And if somebody wrote me something, I needed to see it right
then, even though I didn't immediately reply to it. I can only describe this
with FOMO (fear of missing out). I have no other explanation than that. It was
crippling, and I was constantly context switching, which I will address further
down this post in more details.</p>
<p>This was one of the reasons why I spawned up my personal email server, and I am
using it now as my primary and person email. I still have Gmail as my “junk”
email that I use for throw away stuff. I log in to Gmail once a week and check
if there are any important emails that I got, but apart from that, it's sitting
dormant and collecting dust.</p>
<p>The more I was watching the world loose it's self with allowing anti freedom
things to happen to it, the more I started to realize that something has to
change. I don't have the power to change the world. And I also don't have a
grandiose opinion of myself to even think to try it. But what I can do is to not
subscribe to this consumer way of thinking. I will not be complicit in this. My
moral and ethical stances won't allow it. So, this brings us to the second part
of my journey.</p>
<p>I was using all these 3rd party services because I was either lazy or OK with
the drawbacks of them. I watched these services and companies became more and
privacy policies and everybody is OK with accepting them, and they pray on that
more evil. It is evil if you sell your user's data in this manner. Nobody reads
flaw in human nature. I really hate the hypocrisy they manage to muster. These
companies prey on our laziness, and we are at fault here. Nobody else. And I
truly understand the reasons why we rather accept and move on, and not object
and have our lives a little more difficult. They have perfected this through
years of small changes that make us a little more dependent on them. You could
not convince a person to give away all his rights and data in one day. This was
gradual and slow. And it caught us all in surprise. When I really stopped and
thought about it, I felt repulsed. By really stopping and thinking about it, I
really mean stopping and thinking about it. Thoroughly and in depth.</p>
<p>Each step I took depleted my character a bit more. Like I was trading myself bit
by bit without understanding what it all meant. What it meant to be a full
person, not divided by all this bought attention they want from me. They don't
just get your data, but they also take your attention away from you. They
scatter your and go with the divide and conquer tactic from there. And a person
divided is a person not fully there. Not at the moment. Not alive fully.</p>
<p>I was unable to form long thoughts. Well, I thought I was. But now that I see
what being a full person is again, I can see that I was not at my 100% back
then.</p>
<p>A revolt was inevitable. There was no other way of continuing my story without
it. Without taking back my attention, my thoughts, my time, and my privacy,
regardless of how too late it maybe is.</p>
<p>This has nothing to do with conspiracy theories. Even less with changing the
world. All I wanted was to get my life back in order and not waste the energy
that could be spent in other, better places.</p>
<p>I started reading more. I can focus now fully on things I work on. Furthermore,
I have the mental acuity that I never had before. My mind feels sharp. I don't
get angry so much. I can cherish the finer things in life now without the need
to interpret them intellectually. Not only that, but I have a feeling of
belonging again. Sense of purpose has returned with a vengeance. And I can now
help people without depleting myself.</p>
<p>The last step so far was to finish closing all the remaining online accounts
that I still had. And when I was thinking what value they bring me, I wasn't
surprised that the answer was none. I wasn't logging in them and using them.  I
stopped being afraid of FOMO. If somebody wants to get in contact me, they will
find a way. I am one search away.</p>
<p>We are not beholden to anybody. Our lives are our own. So dare yourself to
delete Facebook, LinkedIn. To unsubscribe. Dare yourself to take your time and
attention back. Use that time and energy to go for a walk without thinking about
work. Read a book instead of reading comment on social media that you will
forget in an hour. Enrich your life instead of wasting it. It only requires a
small step. And you will feel the benefits immediately. Lose the weight of the
world that is crushing you without your consent.</p>


guid: https://mitjafelicijan.com/linux-cheatsheet.html
title: List of essential Linux commands for server management
url: https://mitjafelicijan.com/linux-cheatsheet.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p><strong>Generate SSH key</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>ssh-keygen -t ed25519 -C <span style="color:#a31515">&#34;your_email@example.com&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># when no support for Ed25519 present</span>
</span></span><span style="display:flex;"><span>ssh-keygen -t rsa -b 4096 -C <span style="color:#a31515">&#34;your_email@example.com&#34;</span>
</span></span></code></pre><p>Note: By default SSH keys get stored to <code>/home/&lt;username&gt;/.ssh/</code> folder.</p>
<p><strong>Login to host via SSH</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># connect to host as your local username</span>
</span></span><span style="display:flex;"><span>ssh host
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># connect to host as user</span>
</span></span><span style="display:flex;"><span>ssh &lt;user&gt;@&lt;host&gt;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># connect to host using port</span>
</span></span><span style="display:flex;"><span>ssh -p &lt;port&gt; &lt;user&gt;@&lt;host&gt;
</span></span></code></pre><p><strong>Execute command on a server through SSH</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># execute one command</span>
</span></span><span style="display:flex;"><span>ssh root@100.100.100.100 <span style="color:#a31515">&#34;ls /root&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># execute many commands</span>
</span></span><span style="display:flex;"><span>ssh root@100.100.100.100 <span style="color:#a31515">&#34;cd /root;touch file.txt&#34;</span>
</span></span></code></pre><p><strong>Displays currently logged in users in the system</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>w
</span></span></code></pre><p><strong>Displays Linux system information</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>uname
</span></span></code></pre><p><strong>Displays kernel release information</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>uname -r
</span></span></code></pre><p><strong>Shows the system hostname</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>hostname
</span></span></code></pre><p><strong>Shows system reboot history</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>last reboot
</span></span></code></pre><p><strong>Displays information about the user</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo apt install finger
</span></span><span style="display:flex;"><span>finger &lt;username&gt;
</span></span></code></pre><p><strong>Displays IP addresses and all the network interfaces</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>ip addr show
</span></span></code></pre><p><strong>Downloads a file from an online source</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>wget https://example.com/example.tgz
</span></span></code></pre><p>Note: If URL contains ?, &amp; enclose the URL in double quotes.</p>
<p><strong>Compress a file with gzip</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># will not keep the original file</span>
</span></span><span style="display:flex;"><span>gzip file.txt
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># will keep the original file</span>
</span></span><span style="display:flex;"><span>gzip --keep file.txt
</span></span></code></pre><p><strong>Interactive disk usage analyzer</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo apt install ncdu
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>ncdu
</span></span><span style="display:flex;"><span>ncdu &lt;path/to/directory&gt;
</span></span></code></pre><p><strong>Install Node.js using the Node Version Manager</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
</span></span><span style="display:flex;"><span>source ~/.bashrc
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>nvm install v13
</span></span></code></pre><p><strong>Too long; didn't read</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>npm install -g tldr
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>tldr tar
</span></span></code></pre><p><strong>Combine all Nginx access logs to one big log file</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>zcat -f /var/log/nginx/access.log* &gt; /var/log/nginx/access-all.log
</span></span></code></pre><p><strong>Set up Redis server</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo apt install redis-server redis-tools
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># check if server is running</span>
</span></span><span style="display:flex;"><span>sudo service redis status
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># set and get a key value</span>
</span></span><span style="display:flex;"><span>redis-cli set mykey myvalue
</span></span><span style="display:flex;"><span>redis-cli get mykey
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># interactive shell</span>
</span></span><span style="display:flex;"><span>redis-cli
</span></span></code></pre><p><strong>Generate statistics of your webserver</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo apt install goaccess
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># check if installed</span>
</span></span><span style="display:flex;"><span>goaccess -v
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># combine logs</span>
</span></span><span style="display:flex;"><span>zcat -f /var/log/nginx/access.log* &gt; /var/log/nginx/access-all.log
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># export to single html</span>
</span></span><span style="display:flex;"><span>goaccess <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --log-file=/var/log/nginx/access-all.log <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --log-format=COMBINED <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --exclude-ip=0.0.0.0 <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --ignore-crawlers <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --real-os <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --output=/var/www/html/stats.html
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># cleanup afterwards</span>
</span></span><span style="display:flex;"><span>rm /var/log/nginx/access-all.log
</span></span></code></pre><p><strong>Search for a given pattern in files</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>grep -r ‘pattern’ files
</span></span></code></pre><p><strong>Find proccess ID for a specific program</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>pgrep nginx
</span></span></code></pre><p><strong>Print name of current/working directory</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>pwd
</span></span></code></pre><p><strong>Creates a blank new file</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>touch newfile.txt
</span></span></code></pre><p><strong>Displays first lines in a file</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># -n &lt;x&gt; presents the number of lines (10 by default)</span>
</span></span><span style="display:flex;"><span>head -n 20 somefile.txt
</span></span></code></pre><p><strong>Displays last lines in a file</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># -n &lt;x&gt; presents the number of lines (10 by default)</span>
</span></span><span style="display:flex;"><span>tail -n 20 somefile.txt
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># -f follows the changes in file (doesn&#39;t closes)</span>
</span></span><span style="display:flex;"><span>tail -f somefile.txt
</span></span></code></pre><p><strong>Count lines in a file</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>wc -l somefile.txt
</span></span></code></pre><p><strong>Find all instances of the file</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo apt install mlocate
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>locate somefile.txt
</span></span></code></pre><p><strong>Find file names that begin with ‘index’ in /home folder</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>find /home/ -name <span style="color:#a31515">&#34;index&#34;</span>
</span></span></code></pre><p><strong>Find files larger than 100MB in the home folder</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>find /home -size +100M
</span></span></code></pre><p><strong>Displays block devices related information</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>lsblk
</span></span></code></pre><p><strong>Displays free space on mounted systems</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>df -h
</span></span></code></pre><p><strong>Displays free and used memory in the system</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>free -h
</span></span></code></pre><p><strong>Displays all active listening ports</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo apt install net-tools
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>netstat -pnltu
</span></span></code></pre><p><strong>Kill a process violently</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>kill -9 &lt;pid&gt;
</span></span></code></pre><p><strong>List files opened by user</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>lsof -u &lt;user&gt;
</span></span></code></pre><p><strong>Execute &quot;df -h&quot;, showing periodic updates</strong></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># -n 1 means every second</span>
</span></span><span style="display:flex;"><span>watch -n 1 df -h
</span></span></code></pre>


guid: https://mitjafelicijan.com/debian-based-riced-up-distribution-for-developers-and-devops-folks.html
title: Debian based riced up distribution for Developers and DevOps folks
url: https://mitjafelicijan.com/debian-based-riced-up-distribution-for-developers-and-devops-folks.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<h2 id="introduction">Introduction</h2>
<p>I have been using <a href="https://ubuntu.com/">Ubuntu</a> for quite a longtime now. I have
used <a href="https://www.debian.org/">Debian</a> in the past and
<a href="https://manjaro.org/">Manjaro</a>.  Also had <a href="https://archlinux.org/">Arch</a> for
some time and even ran <a href="https://www.gentoo.org/">Gentoo</a> way back.</p>
<p>What I learned from all this is that I prefer running a bit older versions and
having them be stable than run bleeding edge rolling release. For that reason, I
stuck with Ubuntu for a couple of years now. I am also at a point in my life
where I just don't care what is cool or hip anymore. I just want a stable system
that doesn't get in my way.</p>
<p>During all this, I noticed that these distributions were getting very bloated
and a lot of software got included that I usually uninstall on fresh
installation. Maybe this is my OCD speaking, but why do I have to give fresh
installation min 1 GB of ram out of the box just to have a blank screen in front
of me? I get it, there are many things included in the distro to make my life
easier. I understand. But at this point I have a feeling that modern Linux
distributions are becoming similar to <a href="https://devhumor.com/content/uploads/images/August2017/node-modules.jpg">Node.js project with
node_modules</a>.
Just a crazy number of packages serving very little or no purpose, just
supporting other software.</p>
<p>I felt I needed a fresh start. To start over with something minimal and clean.
Something that would put a little more joy into using a computer again.</p>
<p>For the first version, I wanted to target the following machines I have at home
that I want this thing to work on.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># My main stationary work machine</span>
</span></span><span style="display:flex;"><span>Resolution: 3840x1080 (Super Ultrawide Monitor 32:9)
</span></span><span style="display:flex;"><span>CPU: Intel i7-8700 (12) @ 4.600GHz
</span></span><span style="display:flex;"><span>GPU: AMD ATI Radeon RX 470/480/570/570X/580/580X/590
</span></span><span style="display:flex;"><span>Memory: 32020MiB
</span></span></code></pre><pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># Thinkpad x220 for testing things and goofing around</span>
</span></span><span style="display:flex;"><span>Resolution: 1366x768
</span></span><span style="display:flex;"><span>CPU: Intel i5-2520M (4) @ 3.200GHz
</span></span><span style="display:flex;"><span>GPU: Intel 2nd Generation Core Processor Family
</span></span><span style="display:flex;"><span>Memory: 15891MiB
</span></span></code></pre><h2 id="how-should-i-approach-this">How should I approach this?</h2>
<p>I knew I wanted to use <a href="https://www.debian.org/CD/netinst/">minimal Debian netinst
</a> for the base to give myself a head
start. No reason to go through changing the installer and also testing all that
behemoth of a thing. So, some sort of ricing was the only logical option to get
this thing of the grounds somewhat quickly.</p>
<blockquote>
<p><strong>What is ricing anyway?</strong>
The term “RICE” stands for Race Inspired Cosmetic Enhancement. A group of
people (could be one, idk) decided to see if they could tweak their own
distros like they/others did their cars. This gave rise to a community of
Linux/Unix enthusiasts trying to make their distros look cooler and better
than others... For more information, read this article
<a href="https://pesos.github.io/2020/07/14/what-is-ricing.html">What in the world is ricing!?</a>.</p>
</blockquote>
<p>I didn't want this to just be a set of config files for theming purpose. I
wanted this to include a set of pre-installed tools and services that are being
used all the time by a modern developer. Theming is just a tiny part of it.
Fonts being applied across the distro and things like that.</p>
<p>First, I choose terminal installer and left it to load additional components.
Avoid using graphical installer in this case.</p>
<figure>
<img src="/assets/posts/dfd-rice/install-00.png" alt="" />
</figure>
<p>After that I selected hostname and created a normal user and set password for
that user and root user and choose guided mode for disk partitioning.</p>
<figure>
<img src="/assets/posts/dfd-rice/install-01.png" alt="" />
</figure>
<p>I left it run to install all the things required for the base system and opted
out of scanning additional media for use by the package manager. Those will be
downloaded from the internet during installation.</p>
<figure>
<img src="/assets/posts/dfd-rice/install-02.png" alt="" />
</figure>
<p>I opted out of the popularity contest, and <strong>now comes the important part</strong>.
Uncheck all the boxes in Software selection and only leave 'standard system
utilities'. I also left an SSH server, so I was able to log in to the machine
from my main PC.</p>
<figure>
<img src="/assets/posts/dfd-rice/install-03.png" alt="" />
</figure>
<p>At this point, I installed GRUB bootloader on the disk where I installed the
system.</p>
<figure>
<img src="/assets/posts/dfd-rice/install-04.png" alt="" />
</figure>
<p>That concluded the installation of base Debian and after restarting the computer
I was prompted with the login screen.</p>
<figure>
<img src="/assets/posts/dfd-rice/install-05.png" alt="" />
</figure>
<p>Now that I had the base installation, it was time to choose what software do I
want to include in this so-called distribution. I wanted out of the box
developer experience, so I had plenty to choose.</p>
<p>Let's not waste time and go through the list.</p>
<h2 id="desktop-environments">Desktop environments</h2>
<p>I have been using <a href="https://www.gnome.org/">Gnome</a> for my whole Linux life.  From
version 2 forward. It's been quite a ride. I hated version 3 when it came out
and replaced version 2. But I got used to it. And now with version 40+ they also
made couple of changes which I found both frustrating and presently surprised.</p>
<p>The amount of vertical space you loose because of the beefy title bars on
windows is ridiculous. And then in case of
<a href="https://gnunn1.github.io/tilix-web/">Tilix</a> you also have tabs, and you are
100px deep. Vertical space is one of the most important things for a
developer. The more real estate you have, the more code you can have in a
viewport.</p>
<p>But on the other hand, I still love how Gnome feels and looks. I gotta give them
that. They really are trying to make Gnome feel unified and modern.</p>
<p>Regardless of all the nice things Gnome has, I was looking at the tiling window
managers for some time, but never had the nerve to actually go with it. But now
was the ideal time to give it a go. No guts, no glory kind of a thing.</p>
<p>One of the requirements for me was easy custom layouts because I use a really
strange monitor with aspect ratio of 32:9. So relying on included layouts most
of them have is a non-starter.</p>
<p>What I was doing in Gnome was having windows in a layout like the diagram
below. This is my common practice. And if you look at it you can clearly see I
was replicating tiling window manager setup in Gnome.</p>
<figure>
<img src="/assets/posts/dfd-rice/layout.png" alt="" />
</figure>
<p>That made me look into a bunch of tiling window managers and then tested them
out. Candidates I was looking at were:</p>
<ul>
<li><a href="https://i3wm.org/">i3</a></li>
<li><a href="https://github.com/baskerville/bspwm">bspwm</a></li>
<li><a href="https://awesomewm.org/index.html">awesome</a></li>
<li><a href="https://xmonad.org/">XMonad</a></li>
<li><a href="https://swaywm.org/">sway</a></li>
<li><a href="http://www.qtile.org/">Qtile</a></li>
<li><a href="https://dwm.suckless.org/">dwm</a></li>
</ul>
<p>You can also check article <a href="https://www.tecmint.com/best-tiling-window-managers-for-linux/">13 Best Tiling Window Managers for
Linux</a> I was
referencing while testing them out.</p>
<p>While all of them provided what I needed, I liked i3 the most. What particular
caught my eye was the ease to use and tree based layouts which allows flexible
layouts. I know others can be set up also to have custom layouts other than<br />
spiral, dwindle etc. I think i3 is a good entry-level window manager for
somebody like me.</p>
<h2 id="batteries-included">Batteries included</h2>
<p>The source for the whole thing is located on Github
<a href="https://github.com/mitjafelicijan/dfd-rice">https://github.com/mitjafelicijan/dfd-rice</a>.</p>
<p>Currenly included:</p>
<ul>
<li><code>non-free</code> (enables non-free packages in apt)</li>
<li><code>sudo</code> (adds sudo and adds user to sudo group)</li>
<li><code>essentials</code> (gcc, htop, zip, curl, etc...)</li>
<li><code>wifi</code> (network manager nmtui)</li>
<li><code>desktop</code> (i3, dmenu, fonts, configurations)</li>
<li><code>pulseaudio</code> (pulseaudio with pavucontrol)</li>
<li><code>code-editors</code> (vim, micro, vscode)</li>
<li><code>ohmybash</code> (make bash pretty)</li>
<li><code>file-managers</code> (mc)</li>
<li><code>git-ui</code> (terminal git gui)</li>
<li><code>meld</code> (diff tool)</li>
<li><code>profiling</code> (kcachegrind, valgrind, strace, ltrace)</li>
<li><code>browsers</code> (brave, firefox, chromium)</li>
<li>programming languages:
<ul>
<li><code>python</code></li>
<li><code>golang</code></li>
<li><code>nodejs</code></li>
<li><code>rust</code></li>
<li><code>nim</code></li>
<li><code>php</code></li>
<li><code>ruby</code></li>
</ul>
</li>
<li><code>docker</code> (with docker-compose)</li>
<li><code>ansible</code></li>
</ul>
<p>Install script also allows you to install only specific packages (example for:
essentials ohmybash docker rust).</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>su - root <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>    bash -c <span style="color:#a31515">&#34;</span><span style="color:#00f">$(</span>wget -q https://raw.github.com/mitjafelicijan/dfd-rice/master/tools/install.sh -O -<span style="color:#00f">)</span><span style="color:#a31515">&#34;</span> -- <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>    essentials ohmybash docker rust
</span></span></code></pre><p>Currently, most of these recipes use what Debian and this is totally fine with
me since I never use bleeding edge features of a package. But if something major
would come to light, I will replace it with a possible compilation script or
something similar.</p>
<p>This is some of the output from the installation script.</p>
<figure>
<img src="/assets/posts/dfd-rice/script.png" alt="" />
</figure>
<p>Let's take a look at some examples in the installation script.</p>
<h3 id="docker-recipe">Docker recipe</h3>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># docker</span>
</span></span><span style="display:flex;"><span>print_header <span style="color:#a31515">&#34;Installing Docker&#34;</span>
</span></span><span style="display:flex;"><span>curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --yes --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
</span></span><span style="display:flex;"><span>echo <span style="color:#a31515">&#34;deb [arch=</span><span style="color:#00f">$(</span>dpkg --print-architecture<span style="color:#00f">)</span><span style="color:#a31515"> signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian </span><span style="color:#00f">$(</span>lsb_release -cs<span style="color:#00f">)</span><span style="color:#a31515"> stable&#34;</span> | tee /etc/apt/sources.list.d/docker.list &gt; /dev/null
</span></span><span style="display:flex;"><span>apt update
</span></span><span style="display:flex;"><span>apt -y install docker-ce docker-ce-cli containerd.io docker-compose
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>systemctl start docker
</span></span><span style="display:flex;"><span>systemctl enable docker
</span></span><span style="display:flex;"><span>systemctl status docker --no-pager
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>/sbin/usermod -aG docker $USERNAME
</span></span></code></pre><h3 id="making-bash-pretty">Making bash pretty</h3>
<p>I really like <a href="https://ohmyz.sh/">Oh My Zsh</a>, but I don't like zsh shell.  When
I used it, I constantly needed to be aware of it and running bash scripts was a
pain. So, I was really delighted when I found out that a version for bash
existed called <a href="https://ohmybash.nntoan.com/">Oh My Bash</a>. Let's take a look at
the recipe for installing it.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># ohmybash</span>
</span></span><span style="display:flex;"><span>print_header <span style="color:#a31515">&#34;Enabling OhMyBash&#34;</span>
</span></span><span style="display:flex;"><span>sudo -u $USERNAME sh -c <span style="color:#a31515">&#34;</span><span style="color:#00f">$(</span>curl -fsSL https://raw.github.com/ohmybash/oh-my-bash/master/tools/install.sh<span style="color:#00f">)</span><span style="color:#a31515">&#34;</span> &amp;
</span></span><span style="display:flex;"><span>T1=<span style="color:#a31515">${</span>!<span style="color:#a31515">}</span>
</span></span><span style="display:flex;"><span>wait <span style="color:#a31515">${</span>T1<span style="color:#a31515">}</span>
</span></span></code></pre><p>Because OhMyBash does <code>exec bash</code> at the end, this traps our script inside
another shell and our script cannot continue.  For that reason, I executed this
in background. But that presents a new problem. Because this is executed in
background, we lose track of progress naturally. And that strange trick with
<code>T1=${!}</code> and <code>wait ${T1}</code> waits for the background process to finish before
continuing to another task in bash script.</p>
<p>Check <a href="https://www.cloudsavvyit.com/12277/how-to-use-multi-threaded-processing-in-bash-scripts/">Multi-Threaded Processing in Bash Scripts</a>
for more details.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Take a look at
<a href="https://github.com/mitjafelicijan/dfd-rice/blob/develop/tools/install.sh">https://github.com/mitjafelicijan/dfd-rice/blob/develop/tools/install.sh</a> script
to get familiar with it. This is just a first iteration and I will continue to
update it because I need this in my life.</p>
<p>The current version boots in 4s to the login prompt, and after you log in, the
desktop environment loads in 2s. So, its fast, very fast. And on clean boot, I
measured ~230 MB of RAM usage.</p>
<p>And this is how it looks with two terminals side by side. I really like the
simplicity and clean interface. I will polish the colors and stuff like that,
but I really do like the results.</p>
<figure>
<img src="/assets/posts/dfd-rice/desktop.png" alt="" />
</figure>


guid: https://mitjafelicijan.com/running-golang-application-as-pid1.html
title: Running Golang application as PID 1 with Linux kernel
url: https://mitjafelicijan.com/running-golang-application-as-pid1.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<h2 id="unikernels-kernels-and-alike">Unikernels, kernels, and alike</h2>
<p>I have been reading a lot about
<a href="https://en.wikipedia.org/wiki/Unikernel">unikernernels</a> lately and found them
very intriguing. When you push away all the marketing speak and look at the
idea, it makes a lot of sense.</p>
<blockquote>
<p>A unikernel is a specialized, single address space machine image constructed
by using library operating systems. (<a href="https://en.wikipedia.org/wiki/Unikernel">Wikipedia</a>)</p>
</blockquote>
<p>I really like the explanation from the article
<a href="https://queue.acm.org/detail.cfm?id=2566628">Unikernels: Rise of the Virtual Library Operating System</a>.
Really worth a read.</p>
<p>If we compare a normal operating system to a unikernel side by side, they would
look something like this.</p>
<figure>
<img src="/assets/posts/pid1/unikernels.webp" alt="Virtual machines vs Containers vs Unikernels" />
</figure>
<p>From this image, we can see how the complexity significantly decreases with
the use of Unikernels. This comes with a price, of course. Unikernels are hard
to get running and require a lot of work since you don't have an actual proper
kernel running in the background providing network access and drivers etc.</p>
<p>So as a half step to make the stack simpler, I started looking into using
Linux kernel as a base and going from there. I came across this
<a href="https://www.youtube.com/watch?v=Sk9TatW9ino">Youtube video talking about Building the Simplest Possible Linux System</a>
by <a href="https://landley.net">Rob Landley</a> and apart from statically compiling the
application to be run as PID1 there was really no other obstacles.</p>
<h2 id="what-is-pid-1">What is PID 1?</h2>
<p>PID 1 is the first process that Linux kernel starts after the boot process.
It also has a couple of unique properties that are unique to it.</p>
<ul>
<li>When the process with PID 1 dies for any reason, all other processes are
killed with KILL signal.</li>
<li>When any process having children dies for any reason, its children are
re-parented to process with PID 1.</li>
<li>Many signals which have default action of Term do not have one for PID 1.</li>
<li>When the process with PID 1 dies for any reason, kernel panics, which
result in system crash.</li>
</ul>
<p>PID 1 is considered as an Init application which takes care of running other
and handling services like:</p>
<ul>
<li>sshd,</li>
<li>nginx,</li>
<li>pulseaudio,</li>
<li>etc.</li>
</ul>
<p>If you are on a Linux machine, you can check what your process is with PID 1
by running the following.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>$ cat /proc/1/status
</span></span><span style="display:flex;"><span>Name:	systemd
</span></span><span style="display:flex;"><span>Umask:	0000
</span></span><span style="display:flex;"><span>State:	S (sleeping)
</span></span><span style="display:flex;"><span>Tgid:	1
</span></span><span style="display:flex;"><span>Ngid:	0
</span></span><span style="display:flex;"><span>Pid:	1
</span></span><span style="display:flex;"><span>PPid:	0
</span></span><span style="display:flex;"><span>...
</span></span></code></pre><p>As we can see on my machine the process with id of 1 is <a href="https://systemd.io/">systemd</a>
which is a software suite that provides an array of system components for Linux
operating systems. If you look closely you can also see that the <code>PPid</code>
(process id of the parent process) is <code>0</code> which additionally confirms that
this process doesn't have a parent.</p>
<h2 id="so-why-even-run-application-as-pid-1-instead-of-just-using-a-container">So why even run application as PID 1 instead of just using a container?</h2>
<p>Containers are wonderful, but they come with a lot of baggage. And because they
are in their nature layered, the images require quite a lot of space and also a
lot of additional software to handle them. They are not as lightweight as they
seem, and many popular images require 500 MB plus disk space.</p>
<p>The idea of running this as PID 1 would result in a significantly smaller footprint,
as we will see later in the post.</p>
<blockquote>
<p>You could run a simple init system inside Docker container described more
in this article <a href="https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/">Docker and the PID 1 zombie reaping problem</a>.</p>
</blockquote>
<h2 id="the-master-plan">The master plan</h2>
<ol>
<li>Compile Linux kernel with the default definitions.</li>
<li>Prepare a Hello World application in Golang that is statically compiled.</li>
<li>Run it with <a href="https://www.qemu.org/">QEMU</a> and providing Golang application
as init application / PID 1.</li>
</ol>
<p>For the sake of simplicity we will not be cross-compiling any of it and just
use the 64bit version.</p>
<h2 id="compiling-linux-kernel">Compiling Linux kernel</h2>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>$ wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.7.tar.xz
</span></span><span style="display:flex;"><span>$ tar xf linux-5.15.7.tar.xz
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>$ cd linux-5.15.7
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>$ make clean
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># read more about this https://stackoverflow.com/a/41886394</span>
</span></span><span style="display:flex;"><span>$ make defconfig
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>$ time make -j <span style="color:#a31515">`</span>nproc<span style="color:#a31515">`</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>$ cd ..
</span></span></code></pre><p>At this point we have kernel image that is located in <code>arch/x86_64/boot/bzImage</code>.
We will use this in QEMU later.</p>
<p>To make our lives a bit easier lets move the kernel image to another place.
Lets create a folder <code>bin/</code> in the root of our project with <code>mkdir -p bin</code>.</p>
<p>At this point we can copy <code>bzImage</code> to <code>bin/</code> folder with
<code>cp linux-5.15.7/arch/x86_64/boot/bzImage bin/bzImage</code>.</p>
<p>The folder structure of this experiment should look like this.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>pid1/
</span></span><span style="display:flex;"><span>  bin/
</span></span><span style="display:flex;"><span>    bzImage
</span></span><span style="display:flex;"><span>  linux-5.15.7/
</span></span><span style="display:flex;"><span>  linux-5.15.7.tar.xz
</span></span></code></pre><h2 id="preparing-pid-1-application-in-golang">Preparing PID 1 application in Golang</h2>
<p>This step is relatively easy. The only thing we must have in mind that we will
need to compile the binary as a static one.</p>
<p>Let's create <code>init.go</code> file in the root of the project.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">package</span> main
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">import</span> (
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#34;fmt&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#34;time&#34;</span>
</span></span><span style="display:flex;"><span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">func</span> main() {
</span></span><span style="display:flex;"><span>  <span style="color:#00f">for</span> {
</span></span><span style="display:flex;"><span>    fmt.Println(<span style="color:#a31515">&#34;Hello from Golang&#34;</span>)
</span></span><span style="display:flex;"><span>    time.Sleep(1 * time.Second)
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>If you notice, we have a forever loop in the main, with a simple sleep of 1
second to not overwhelm the CPU. This is because PID 1 should never complete
and/or exit. That would result in a kernel panic. Which is BAD!</p>
<p>There are two ways of compiling Golang application. Statically and dynamically.</p>
<p>To statically compile the binary, use the following command.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>$ go build -ldflags=<span style="color:#a31515">&#34;-extldflags=-static&#34;</span> init.go
</span></span></code></pre><p>We can also check if the binary is statically compiled with:</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>$ file init
</span></span><span style="display:flex;"><span>init: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=Ypu8Zw_4NBxm1Yxg2OYO/H5x721rQ9uTPiDVh-VqP/vZN7kXfGG1zhX_qdHMgH/9vBfmK81tFrygfOXDEOo, not stripped
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>$ ldd init
</span></span><span style="display:flex;"><span>not a dynamic executable
</span></span></code></pre><p>At this point, we need to create <a href="https://www.linuxfromscratch.org/blfs/view/svn/postlfs/initramfs.html">initramfs</a>
(abbreviated from &quot;initial RAM file system&quot;, is the successor of initrd. It
is a cpio archive of the initial file system that gets loaded into memory
during the Linux startup process).</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>$ echo init | cpio -o --format=newc &gt; initramfs
</span></span><span style="display:flex;"><span>$ mv initramfs bin/initramfs
</span></span></code></pre><p>The projects at this stage should look like this.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>pid1/
</span></span><span style="display:flex;"><span>  bin/
</span></span><span style="display:flex;"><span>    bzImage
</span></span><span style="display:flex;"><span>    initramfs
</span></span><span style="display:flex;"><span>  linux-5.15.7/
</span></span><span style="display:flex;"><span>  linux-5.15.7.tar.xz
</span></span><span style="display:flex;"><span>  init.go
</span></span></code></pre><h2 id="running-all-of-it-with-qemu">Running all of it with QEMU</h2>
<p><a href="https://www.qemu.org/">QEMU</a> is a free and open-source hypervisor. It emulates
the machine's processor through dynamic binary translation and provides a set
of different hardware and device models for the machine, enabling it to run a
variety of guest operating systems.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>$ qemu-system-x86_64 -serial stdio -kernel bin/bzImage -initrd bin/initramfs -append <span style="color:#a31515">&#34;console=ttyS0&#34;</span> -m 128
</span></span></code></pre><pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>$ qemu-system-x86_64 -serial stdio -kernel bin/bzImage -initrd bin/initramfs -append <span style="color:#a31515">&#34;console=ttyS0&#34;</span> -m 128
</span></span><span style="display:flex;"><span>[    0.000000] Linux version 5.15.7 (m@khan) (gcc (GCC) 11.2.1 20211203 (Red Hat 11.2.1-7), GNU ld version 2.37-10.fc35) <span style="color:#008000">#7 SMP Mon Dec 13 10:23:25 CET 2021</span>
</span></span><span style="display:flex;"><span>[    0.000000] Command line: console=ttyS0
</span></span><span style="display:flex;"><span>[    0.000000] x86/fpu: x87 FPU will use FXSAVE
</span></span><span style="display:flex;"><span>[    0.000000] signal: max sigframe size: 1440
</span></span><span style="display:flex;"><span>[    0.000000] BIOS-provided physical RAM map:
</span></span><span style="display:flex;"><span>[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
</span></span><span style="display:flex;"><span>[    0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
</span></span><span style="display:flex;"><span>[    0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
</span></span><span style="display:flex;"><span>[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x0000000007fdffff] usable
</span></span><span style="display:flex;"><span>[    0.000000] BIOS-e820: [mem 0x0000000007fe0000-0x0000000007ffffff] reserved
</span></span><span style="display:flex;"><span>[    0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
</span></span><span style="display:flex;"><span>[    0.000000] NX (Execute Disable) protection: active
</span></span><span style="display:flex;"><span>[    0.000000] SMBIOS 2.8 present.
</span></span><span style="display:flex;"><span>[    0.000000] DMI: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-6.fc35 04/01/2014
</span></span><span style="display:flex;"><span>[    0.000000] tsc: Fast TSC calibration failed
</span></span><span style="display:flex;"><span>...
</span></span><span style="display:flex;"><span>[    2.016106] ALSA device list:
</span></span><span style="display:flex;"><span>[    2.016329]   No soundcards found.
</span></span><span style="display:flex;"><span>[    2.053176] Freeing unused kernel image (initmem) memory: 1368K
</span></span><span style="display:flex;"><span>[    2.056095] Write protecting the kernel read-only data: 20480k
</span></span><span style="display:flex;"><span>[    2.058248] Freeing unused kernel image (text/rodata gap) memory: 2032K
</span></span><span style="display:flex;"><span>[    2.058811] Freeing unused kernel image (rodata/data gap) memory: 500K
</span></span><span style="display:flex;"><span>[    2.059164] Run /init as init process
</span></span><span style="display:flex;"><span>Hello from Golang
</span></span><span style="display:flex;"><span>[    2.386879] tsc: Refined TSC clocksource calibration: 3192.032 MHz
</span></span><span style="display:flex;"><span>[    2.387114] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x2e02e31fa14, max_idle_ns: 440795264947 ns
</span></span><span style="display:flex;"><span>[    2.387380] clocksource: Switched to clocksource tsc
</span></span><span style="display:flex;"><span>[    2.587895] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input3
</span></span><span style="display:flex;"><span>Hello from Golang
</span></span><span style="display:flex;"><span>Hello from Golang
</span></span><span style="display:flex;"><span>Hello from Golang
</span></span></code></pre><p>The whole <a href="/assets/posts/pid1/qemu.log">log file here</a>.</p>
<h2 id="size-comparison">Size comparison</h2>
<p>The cool thing about this approach is that the Linux kernel and the application
together only take around 12 MB, which is impressive as hell. And we need to
also know that the size of bzImage (Linux kernel) could be greatly decreased
by going into <code>make menuconfig</code> and removing a ton of features from the kernel,
making the size even smaller. I managed to get kernel size down to 2 MB and
still working properly.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>total 12M
</span></span><span style="display:flex;"><span>-rw-r--r--. 1 m m 9.3M Dec 13 10:24 bzImage
</span></span><span style="display:flex;"><span>-rw-r--r--. 1 m m 1.9M Dec 27 01:19 initramfs
</span></span></code></pre><h2 id="creating-iso-image-and-running-it-with-gnome-boxes">Creating ISO image and running it with Gnome Boxes</h2>
<p>First we need to create proper folder structure with <code>mkdir -p iso/boot/grub</code>.</p>
<p>Then we need to download the <a href="https://github.com/littleosbook/littleosbook/raw/master/files/stage2_eltorito">grub binary</a>.
You can read more about this program on <a href="https://github.com/littleosbook/littleosbook">https://github.com/littleosbook/littleosbook</a>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>$ wget -O iso/boot/grub/stage2_eltorito https://github.com/littleosbook/littleosbook/raw/master/files/stage2_eltorito
</span></span></code></pre><pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>$ tree iso/boot/
</span></span><span style="display:flex;"><span>iso/boot/
</span></span><span style="display:flex;"><span>├── bzImage
</span></span><span style="display:flex;"><span>├── grub
</span></span><span style="display:flex;"><span>│   ├── menu.lst
</span></span><span style="display:flex;"><span>│   └── stage2_eltorito
</span></span><span style="display:flex;"><span>└── initramfs
</span></span></code></pre><p>Let's copy files into proper folders.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>$ cp stage2_eltorito iso/boot/grub/
</span></span><span style="display:flex;"><span>$ cp bin/bzImage iso/boot/
</span></span><span style="display:flex;"><span>$ cp bin/initramfs iso/boot/
</span></span></code></pre><p>Lets create a GRUB config file at <code>nano iso/boot/grub/menu.lst</code> with contents.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>default=<span style="color:#a31515">0</span>
</span></span><span style="display:flex;"><span>timeout=<span style="color:#a31515">5</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>title GoAsPID1
</span></span><span style="display:flex;"><span>kernel /boot/bzImage
</span></span><span style="display:flex;"><span>initrd /boot/initramfs
</span></span></code></pre><p>Let's create iso file by using genisoimage:</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>genisoimage -R                              <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>            -b boot/grub/stage2_eltorito    <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>            -no-emul-boot                   <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>            -boot-load-size 4               <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>            -A os                           <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>            -input-charset utf8             <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>            -quiet                          <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>            -boot-info-table                <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>            -o GoAsPID1.iso                 <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>            iso
</span></span></code></pre><p>This will produce <code>GoAsPID1.iso</code> which you can use with <a href="https://www.virtualbox.org/">Virtualbox</a>
or <a href="https://apps.gnome.org/app/org.gnome.Boxes/">Gnome Boxes</a>.</p>
<p><video src="/assets/posts/pid1/boxes.mp4" controls></video></p>
<h2 id="is-running-applications-as-pid-1-even-worth-it">Is running applications as PID 1 even worth it?</h2>
<p>Well, the answer to this is not as simple as one would think. Sometimes it is
and sometimes it's not. For embedded systems and very specialized applications
it is worth for sure. But in normal uses, I don't think so. It was an interesting
exercise in compiling kernels and looking at the guts of the Linux kernel,
but sticking to containers for most of the things is a better option in my
opinion.</p>
<p>An interesting experiment would be creating an image that supports networking
and could be deployed to AWS as an EC2 instance and observing how it fares.
But in that case, we would need to write some sort of supervisor that would
run on a separate EC2 that would check if other EC2 instances are running
properly. Remember that if your application fails, kernel panics and the
whole machine is inoperable in this case.</p>


guid: https://mitjafelicijan.com/wap-mobile-web-before-the-web.html
title: Wireless Application Protocol and the mobile web before the web
url: https://mitjafelicijan.com/wap-mobile-web-before-the-web.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<h2 id="a-little-stroll-down-the-history-lane">A little stroll down the history lane</h2>
<p>About two weeks ago, I watched this outstanding documentary on YouTube
<a href="https://www.youtube.com/watch?v=b9_Vh9h3Ohw">Springboard: the secret history of the first real
smartphone</a> about the history of
smartphones and phones in general. It brought back so many memories. I never had
an actual smartphone before the Android. The closest to smartphone was <a href="https://www.gsmarena.com/sony_ericsson_p1-1982.php">Sony
Ericsson P1</a>.  A fantastic
phone and I broke it in Prague after a party and that was one of those rare
occasions where I was actually mad at myself. But nevertheless, after that
phone, the next one was an Android one.</p>
<p>Before that, I only owned normal phones from Nokia and Siemens etc. Nothing
special, actually. These are the phones we are talking about. Before 2007.
Apple and Android phones didn't exist yet.</p>
<p>These phones were rocking:</p>
<ul>
<li>No selfie cameras.</li>
<li>~2 inch displays.</li>
<li>~120 MHz beast CPU's.</li>
<li>144p main cameras.</li>
<li>But they had a headphone jack.</li>
</ul>
<p>Let's take a look at these beauties.</p>
<figure>
<img src="/assets/posts/wap/phones.gif" alt="Old phones" />
</figure>
<h2 id="wap---wireless-application-protocol">WAP - Wireless Application Protocol</h2>
<p>Not that one! We are talking about Wireless Application Protocol and not Cardi
B's song 😃</p>
<p>WAP stands for Wireless Application Protocol. It is a protocol designed for
micro-browsers, and it enables the access of internet in the mobile devices.  It
uses the mark-up language WML (Wireless Markup Language and not HTML), WML is
defined as XML 1.0 application. Furthermore, it enables creating web
applications for mobile devices. In 1998, WAP Forum was founded by Ericson,
Motorola, Nokia and Unwired Planet whose aim was to standardize the various
wireless technologies via protocols.
<a href="https://www.geeksforgeeks.org/wireless-application-protocol/">(source)</a></p>
<p>WAP protocol was resulted by the joint efforts of the various members of WAP
Forum. In 2002, WAP forum was merged with various other forums of the industry,
resulting in the formation of Open Mobile Alliance (OMA).
<a href="https://www.geeksforgeeks.org/wireless-application-protocol/">(source)</a></p>
<p>These were some wild times. Devices had tiny screens and data transmission rates
were abominable. But they were capable of rendering WML (Wireless Markup
Language). This was very similar to HTML, actually. It is a markup language,
after all.</p>
<p>These pages could be served by <a href="https://apache.org/">Apache</a> and could be
generated by CGI scripts on the backend. The only difference was the limited
markup language.</p>
<h2 id="wml---wireless-markup-language">WML - Wireless Markup Language</h2>
<p>Just like web browsers use HTML for content structure, older mobile device
browsers use WML - if you need to support really old mobile phones using WML
browsers, you will need to know about it. WML is XML-based (an XML vocabulary
just like XHTML and MathML, but not HTML) and does not use the same metaphor as
HTML. HTML is a single document with some metadata packed away in the head, and
a body encapsulating the visible page. With WML, the metaphor does not envisage
a page, but rather a deck of cards. A WML file might have several pages or cards
contained within it.
<a href="https://www.w3.org/wiki/Introduction_to_mobile_web">(source)</a></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">&lt;?xml version=&#34;1.0&#34;?&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#00f">&lt;!DOCTYPE wml PUBLIC &#34;-//WAPFORUM//DTD WML 1.1//EN&#34; &#34;http://www.wapforum.org/DTD/wml_1.1.xml&#34;&gt;</span>
</span></span><span style="display:flex;"><span>&lt;wml&gt;
</span></span><span style="display:flex;"><span>  &lt;card id=<span style="color:#a31515">&#34;home&#34;</span> title=<span style="color:#a31515">&#34;Example Homepage&#34;</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;p&gt;Welcome to the Example homepage&lt;/p&gt;
</span></span><span style="display:flex;"><span>  &lt;/card&gt;
</span></span><span style="display:flex;"><span>&lt;/wml&gt;
</span></span></code></pre><p>There is an amazing tutorial on <a href="https://www.tutorialspoint.com/wml/index.htm">Tutorialpoint about
WML</a>.</p>
<h2 id="converting-digg-to-wml">Converting Digg to WML</h2>
<p>This task is completely useless and not really feasible nowadays, but I had to
give it a try for old-time sake. Since the data is already there in a form of
RSS feed, I could take this feed and parse it and create a WML version of the
homepage.</p>
<p>We will need:</p>
<ul>
<li>Python3 + Pip</li>
<li>ImageMagick</li>
<li>feedparser and mako templating</li>
</ul>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># for fedora 35</span>
</span></span><span style="display:flex;"><span>sudo dnf install ImageMagick python3-pip
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># tempalting engine for python</span>
</span></span><span style="display:flex;"><span>pip install mako --user
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># for parsing rss feeds</span>
</span></span><span style="display:flex;"><span>pip install feedparser --user
</span></span></code></pre><p>Project folder structure should look like the following.</p>
<pre><code>12:43:53 m@khan wap → tree -L 1
.
├── generate.py
└── template.wml

</code></pre>
<p>After that, I created a small template for the homepage.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">&lt;?xml version=&#34;1.0&#34;?&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#00f">&lt;!DOCTYPE wml PUBLIC &#34;-//WAPFORUM//DTD WML 1.2//EN&#34; &#34;http://www.wapforum.org/DTD/wml_1.2.xml&#34;&gt;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>&lt;wml&gt;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  &lt;card title=<span style="color:#a31515">&#34;Digg - What the Internet is talking about right now&#34;</span>&gt;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    % for item in entries:
</span></span><span style="display:flex;"><span>      &lt;p&gt;&lt;img src=<span style="color:#a31515">&#34;/images/${item.id}.jpg&#34;</span> width=<span style="color:#a31515">&#34;175&#34;</span> height=<span style="color:#a31515">&#34;95&#34;</span> alt=<span style="color:#a31515">&#34;${item.title}&#34;</span> /&gt;&lt;/p&gt;
</span></span><span style="display:flex;"><span>      &lt;p&gt;&lt;small&gt;${item.kicker}&lt;/small&gt;&lt;/p&gt;
</span></span><span style="display:flex;"><span>      &lt;p&gt;&lt;big&gt;&lt;b&gt;${item.title}&lt;/b&gt;&lt;/big&gt;&lt;/p&gt;
</span></span><span style="display:flex;"><span>      &lt;p&gt;${item.description}&lt;/p&gt;
</span></span><span style="display:flex;"><span>    % endfor
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  &lt;/card&gt;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>&lt;/wml&gt;
</span></span></code></pre><p>And the parser that parses RSS feed looks like this.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">import</span> os
</span></span><span style="display:flex;"><span><span style="color:#00f">import</span> feedparser
</span></span><span style="display:flex;"><span><span style="color:#00f">from</span> mako.template <span style="color:#00f">import</span> Template
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>os.system(<span style="color:#a31515">&#39;mkdir -p www/images&#39;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>template = Template(filename=<span style="color:#a31515">&#39;template.wml&#39;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>feed = feedparser.parse(<span style="color:#a31515">&#39;https://digg.com/rss/top.xml&#39;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>entries = feed.entries[:15]
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">for</span> entry <span style="color:#00f">in</span> entries:
</span></span><span style="display:flex;"><span>  print(<span style="color:#a31515">&#39;Processing image with id </span><span style="color:#a31515">{}</span><span style="color:#a31515">&#39;</span>.format(entry.id))
</span></span><span style="display:flex;"><span>  os.system(<span style="color:#a31515">&#39;wget -q -O www/images/</span><span style="color:#a31515">{}</span><span style="color:#a31515">.jpg &#34;</span><span style="color:#a31515">{}</span><span style="color:#a31515">&#34;&#39;</span>.format(entry.id, entry.links[1].href))
</span></span><span style="display:flex;"><span>  os.system(<span style="color:#a31515">&#39;convert www/images/</span><span style="color:#a31515">{}</span><span style="color:#a31515">.jpg -type Grayscale -resize 175x -depth 3 -quality 30 www/images/</span><span style="color:#a31515">{}</span><span style="color:#a31515">.jpg&#39;</span>.format(entry.id, entry.id))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>html = template.render(entries = entries)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">with</span> open(<span style="color:#a31515">&#39;www/index.wml&#39;</span>, <span style="color:#a31515">&#39;w+&#39;</span>) <span style="color:#00f">as</span> fp:
</span></span><span style="display:flex;"><span>  fp.write(html)
</span></span></code></pre><p>This script will create a folder <code>www</code> and in the folder <code>www/images</code> for
storing resized images.</p>
<blockquote>
<p>Be sure you don't use SSL and use just normal HTTP for serving the content.
These old phones will have problems with TLS 1.3 etc.</p>
</blockquote>
<p>If you look at the python file, I convert all the images into tiny B&amp;W images.
They should be WBMP (Wireless BitMaP) but I choose JPEGs for this, and it seems
to work properly.</p>
<p>Because I currently don't have a phone old enough to test it on, I used an
emulator. And it was really hard to find one. I found <a href="http://wap-proof.sharewarejunction.com/">WAP
Proof</a> on shareware junction, and it
did the job well enough. I will try to find and actual device to test it on.</p>
<p><video src="/assets/posts/wap/emulator.mp4" controls></video></p>
<p>If you are using Nginx to serve the contents, add a directive to the hosts file
that will automatically server <code>index.wml</code> file.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">server</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#00f">index</span> <span style="color:#a31515">index.wml</span> <span style="color:#a31515">index.html</span> <span style="color:#a31515">index.htm</span> <span style="color:#a31515">index.nginx-debian.html</span>;
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><h2 id="conclusion">Conclusion</h2>
<p>Well, this was pointless, but very fun! I hope you enjoyed it as much as I did.
I will try to find an old phone to test it on. If you have any questions, feel
free to ask in the comments.</p>


guid: https://mitjafelicijan.com/tying-out-helix-code-editor.html
title: Trying out Helix code editor as my main editor
url: https://mitjafelicijan.com/tying-out-helix-code-editor.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I have been searching for a lightweight code editor for quite some time. One of
the main reasons was that I wanted something that doesn't burn through CPU and
RAM usage is not through the roof. I have been mostly using Visual Studio Code.
It's been an outstanding editor. I have no quarrel with it at all. It's just
time to spice life up with something new.</p>
<p>I have been on this search for a couple of years. I have tried Vim, Neovim,
Emacs, Doom Emacs, Micro and couple more. Among most of them, I liked Micro and
Doom Emacs the most. Micro editor was a little too basic for me. And Doom Emacs
was a bit too hardcore. This does not reflect on any of the editors. It's just
my personal preference.</p>
<blockquote>
<p>I tried Helix Editor about a year ago. But I didn't pay attention to it.
Tried it and saw it's similar to Vi and just said no. I was premature to
dismiss it.</p>
</blockquote>
<p>One of the things I actually miss is line wrapping for certain files. When
writing Markdown, line wrapping would be very helpful. Editing such a document
is frustrating to say the least. Some of the Markdown to HTML converters don't
take kindly of new lines between sentences. Not paragraphs, sentences. And I use
Markdown to write this blog you are reading.</p>
<p>But other than this, I have been extremely satisfied by it. It's been a pleasant
surprise. There have been zero issues with the editor.</p>
<p>One thing to do before you are able to use autocompletion and make use Language
Server support is to install the language server with NPM.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># For C development this installs C LSP.</span>
</span></span><span style="display:flex;"><span>sudo dnf install clang-tools-extra
</span></span></code></pre><p>I am still getting used to the keyboard shortcuts and getting better. What Helix
does really well is packing in sane defaults and even though because currently
there is no plugin support I haven't found any need for them. It has all that
you would need. It goes to extreme measures to show a user what is going on with
popups that show you what the keyboard shortcuts are.</p>
<p>And it comes us packed with many
<a href="https://github.com/helix-editor/helix/wiki/Themes">really good themes</a>.</p>
<figure>
<img src="/assets/posts/helix-editor/editor.png" alt="Editor" />
</figure>
<p>It's still young but has this mature feeling to it. It has sane defaults and
mimics Vim (works a bit differently, but the overall idea is similar).</p>


guid: https://mitjafelicijan.com/what-would-dna-sound-if-synthesized.html
title: What would DNA sound if synthesized to an audio file
url: https://mitjafelicijan.com/what-would-dna-sound-if-synthesized.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<h2 id="introduction">Introduction</h2>
<p>Lately, I have been thinking a lot about the nature of life, what are the
foundation blocks of life and things like that. It's remarkable how complex and
on the other hand simple the creation is when you look at it. The miracle of
life keeps us grounded when our imagination goes wild. If the DNA are the blocks
of life, you could consider them to be an API nature provided us to better
understand all of this chaos masquerading as order.</p>
<p>I have been reading a lot about superintelligence and our somehow misguided path
to create general artificial intelligence. What would the building blocks or our
creation look like? Is the compression really the ultimate storage of
information? Will our creation also ponder this questions when creating new
worlds for themselves, or will we just disappear into the vastness of
possibilities? It is a little offensive that we are playing God whilst being
completely ignorant of our own reality. Who knows! Like many other
breakthroughs, this one will also come at a cost not known to us when it finally
happens.</p>
<p>To keep things a bit lighter, I decided to convert some popular DNA sequences
into an audio files for us to listen to. I am not the first one, nor I will be
the last one to do this. But it is an interesting exercise in better
understanding the relationship between art and science. Maybe listening to DNA
instead of parsing it will find a way into better understanding, or at least
enjoying the creation and cryptic nature of life.</p>
<h2 id="dna-encoding-and-primer-example">DNA encoding and primer example</h2>
<p>I have been exploring DNA in the past in my post from about 3 years ago in
<a href="/encoding-binary-data-into-dna-sequence.html">Encoding binary data into DNA
sequence</a> where I have been
converting all sorts of data into DNA sequences.</p>
<p>This will be a similar exercise but instead of converting to DNA, I will be
generating tones from Nucleotides.</p>
<table>
<thead>
<tr>
<th>Nucleotides</th>
<th>Note</th>
<th>Frequency</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>A</strong> (Adenine)</td>
<td>A</td>
<td>440 Hz</td>
</tr>
<tr>
<td><strong>C</strong> (Cytosine)</td>
<td>C</td>
<td>783.99 Hz</td>
</tr>
<tr>
<td><strong>G</strong> (Guanine)</td>
<td>G</td>
<td>523.25 Hz</td>
</tr>
<tr>
<td><strong>T</strong> (Thymine)</td>
<td>D</td>
<td>587.33 Hz</td>
</tr>
</tbody>
</table>
<p>Since we do not have T in equal-tempered scale, I choose D to represent T note.</p>
<p>You can check <a href="https://pages.mtu.edu/~suits/notefreqs.html">Frequencies for equal-tempered scale, A4 = 440
Hz</a>.  For this tuning, we also
choose <code>Speed of Sound = 345 m/s = 1130 ft/s = 770 miles/hr</code>.</p>
<p>Now that we have this out of the way, we can also brush up on the DNA sequencing
a bit. This is a famous quote I also used for the encoding tests, and it goes
like this.</p>
<blockquote>
<p>How wonderful that we have met with a paradox. Now we have some hope of
making progress.
― Niels Bohr</p>
</blockquote>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>&gt;SEQ1
</span></span><span style="display:flex;"><span>GACAGCTTGTGTACAAGTGTGCTTGCTCGCGAGCGGGTACGCGCGTGGGCTAACAAGTGA
</span></span><span style="display:flex;"><span>GCCAGCAGGTGAACAAGTGTGCGGACAAGCCAGCAGGTGCGCGGACAAGCTGGCGGGTGA
</span></span><span style="display:flex;"><span>ACAAGTGTGCCGGTGAGCCAACAAGCAGACAAGTAAGCAGGTACGCAGGCGAGCTTGTCA
</span></span><span style="display:flex;"><span>ACTCACAAGATCGCTTGTGTACAAGTGTGCGGACAAGCCAGCAGGTGCGCGGACAAGTAT
</span></span><span style="display:flex;"><span>GCTTGCTGGCGGACAAGCCAGCTTGTAAGCGGACAAGCTTGCGCACAAGCTGGCAGGCCT
</span></span><span style="display:flex;"><span>GCCGGCTCGCGTACAAATTCACAAGTAAGTACGCTTGCGTGTACGCGGGTATGTATACTC
</span></span><span style="display:flex;"><span>AACCTCACCAAACGGGACAAGATCGCCGGCGGGCTAGTATACAAGAACGCTTGCCAGTAC
</span></span><span style="display:flex;"><span>AACC
</span></span></code></pre><p>This is what we gonna work with to get things rolling forward, when creating
parser and waveform generator.</p>
<h2 id="parsing-dna-data">Parsing DNA data</h2>
<p>This step is rather simple one. All we need to do is parse input DNA sequence in
<a href="https://en.wikipedia.org/wiki/FASTA_format">FASTA format</a> well known in
<a href="https://en.wikipedia.org/wiki/Bioinformatics">Bioinformatics</a> to extract single
Nucleotides that will be converted into separate tones based on equal-tempered
scale explained above.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>nucleotide_tone_map = {
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#39;A&#39;</span>: 440,
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#39;C&#39;</span>: 523.25,
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#39;G&#39;</span>: 783.99,
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#39;T&#39;</span>: 587.33,  <span style="color:#008000"># converted to D</span>
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">def</span> split(word):
</span></span><span style="display:flex;"><span>  <span style="color:#00f">return</span> [char <span style="color:#00f">for</span> char <span style="color:#00f">in</span> word]
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">def</span> generate_from_dna_sequence(sequence):
</span></span><span style="display:flex;"><span>  <span style="color:#00f">for</span> nucleotide <span style="color:#00f">in</span> split(sequence):
</span></span><span style="display:flex;"><span>    print(nucleotide, nucleotide_tone_map[nucleotide])
</span></span></code></pre><h2 id="generating-sine-wave">Generating sine wave</h2>
<p>Because we are essentially creating a long stream of notes we will be appending
sine notes to a global array we will later use for creating a WAV file out of
it.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">import</span> math
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">def</span> append_sinewave(freq=440.0, duration_milliseconds=500, volume=1.0):
</span></span><span style="display:flex;"><span>  <span style="color:#00f">global</span> audio
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  num_samples = duration_milliseconds * (sample_rate / 1000.0)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">for</span> x <span style="color:#00f">in</span> range(int(num_samples)):
</span></span><span style="display:flex;"><span>    audio.append(volume * math.sin(2 * math.pi * freq * (x / sample_rate)))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">return</span>
</span></span></code></pre><p>The sine wave generated here is the standard beep. If you want something more
aggressive, you could try a square or saw tooth waveform.</p>
<h2 id="generating-a-wav-file-from-accumulated-sine-waves">Generating a WAV file from accumulated sine waves</h2>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">import</span> wave
</span></span><span style="display:flex;"><span><span style="color:#00f">import</span> struct
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">def</span> save_wav(file_name):
</span></span><span style="display:flex;"><span>  wav_file = wave.open(file_name, <span style="color:#a31515">&#39;w&#39;</span>)
</span></span><span style="display:flex;"><span>  nchannels = 1
</span></span><span style="display:flex;"><span>  sampwidth = 2
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  nframes = len(audio)
</span></span><span style="display:flex;"><span>  comptype = <span style="color:#a31515">&#39;NONE&#39;</span>
</span></span><span style="display:flex;"><span>  compname = <span style="color:#a31515">&#39;not compressed&#39;</span>
</span></span><span style="display:flex;"><span>  wav_file.setparams((nchannels, sampwidth, sample_rate, nframes, comptype, compname))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">for</span> sample <span style="color:#00f">in</span> audio:
</span></span><span style="display:flex;"><span>    wav_file.writeframes(struct.pack(<span style="color:#a31515">&#39;h&#39;</span>, int(sample * 32767.0)))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  wav_file.close()
</span></span></code></pre><p>44100 is the industry standard sample rate - CD quality.  If you need to save on
file size, you can adjust it downwards. The standard for low quality is, 8000 or
8kHz.</p>
<p>WAV files here are using short, 16 bit, signed integers for the sample size.
So, we multiply the floating-point data we have by 32767, the maximum value for
a short integer.</p>
<blockquote>
<p>It is theoretically possible to use the floating point -1.0 to 1.0 data
directly in a WAV file, but not obvious how to do that using the wave module
in Python.</p>
</blockquote>
<h2 id="generating-spectograms">Generating Spectograms</h2>
<p>I have tried two methods of doing this and both were just fine. I however opted
out to use the <a href="https://linux.die.net/man/1/sox">SoX - Sound eXchange, the Swiss Army knife of audio
manipulation</a> one because it didn't require
anything else.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sox output.wav -n spectrogram -o spectrogram.png
</span></span></code></pre><p>An example spectrogram of Ludwig van Beethoven Symphony No. 6 First movement.</p>
<audio controls>
  <source src="/assets/posts/dna-synthesized/symphony-no6-1st-movement.mp3" type="audio/mpeg">
</audio>
<figure>
<img src="/assets/posts/dna-synthesized/symphony-no6-1st-movement.png" alt="Ludwig van Beethoven Symphony No. 6 First movement" />
</figure>
<p>The other option could also be in combination with
<a href="http://www.gnuplot.info/">gnuplot</a>.  This would require an intermediary step,
however.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sox output.wav audio.dat
</span></span><span style="display:flex;"><span>tail -n+3 audio.dat &gt; audio_only.dat
</span></span><span style="display:flex;"><span>gnuplot audio.gpi
</span></span></code></pre><p>And input file <code>audio.gpi</code> that would be passed to gnuplot looks something like
this.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span># set output format and size
</span></span><span style="display:flex;"><span>set term png size 1000,280
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span># set output file
</span></span><span style="display:flex;"><span>set output &#34;audio.png&#34;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span># set y range
</span></span><span style="display:flex;"><span>set yr [-1:1]
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span># we want just the data
</span></span><span style="display:flex;"><span>unset key
</span></span><span style="display:flex;"><span>unset tics
</span></span><span style="display:flex;"><span>unset border
</span></span><span style="display:flex;"><span>set lmargin 0
</span></span><span style="display:flex;"><span>set rmargin 0
</span></span><span style="display:flex;"><span>set tmargin 0
</span></span><span style="display:flex;"><span>set bmargin 0
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span># draw rectangle to change background color
</span></span><span style="display:flex;"><span>set obj 1 rectangle behind from screen 0,0 to screen 1,1
</span></span><span style="display:flex;"><span>set obj 1 fillstyle solid 1.0 fillcolor rgbcolor &#34;#ffffff&#34;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span># draw data with foreground color
</span></span><span style="display:flex;"><span>plot &#34;audio_only.dat&#34; with lines lt rgb &#39;red&#39;
</span></span></code></pre><h2 id="pre-generated-sequences">Pre-generated sequences</h2>
<p>What I did was take interesting parts from an animal's genome and feed it to a
tone generator script. This then generated a WAV file and I converted those to
MP3, so they can be played in a browser. The last step was creating a
spectrogram based on a WAV file.</p>
<h3 id="niels-bohr-quote">Niels Bohr quote</h3>
<audio controls>
  <source src="/assets/posts/dna-synthesized/quote/out.mp3" type="audio/mpeg">
</audio>
<figure>
<img src="/assets/posts/dna-synthesized/quote/spectogram.png" alt="Spectogram" />
</figure>
<h3 id="mouse">Mouse</h3>
<p>This is part of a mouse genome <code>Mus_musculus.GRCm39.dna.nonchromosomal</code>.  You
can get <a href="http://ftp.ensembl.org/pub/release-106/fasta/mus_musculus/dna/">genom data
here</a>.</p>
<audio controls>
  <source src="/assets/posts/dna-synthesized/mouse/out.mp3" type="audio/mpeg">
</audio>
<figure>
<img src="/assets/posts/dna-synthesized/mouse/spectogram.png" alt="Spectogram" />
</figure>
<h3 id="bison">Bison</h3>
<p>This is part of a bison genome <code>Bison_bison_bison.Bison_UMD1.0.cdna</code>.  You can
get <a href="http://ftp.ensembl.org/pub/release-106/fasta/bison_bison_bison/cdna/">genom data
here</a>.</p>
<audio controls>
  <source src="/assets/posts/dna-synthesized/bison/out.mp3" type="audio/mpeg">
</audio>
<figure>
<img src="/assets/posts/dna-synthesized/bison/spectogram.png" alt="Spectogram" />
</figure>
<h3 id="taurus">Taurus</h3>
<p>This is part of a taurus genome <code>Bos_taurus.ARS-UCD1.2.cdna</code>.  You can get
<a href="http://ftp.ensembl.org/pub/release-106/fasta/bos_taurus/cdna/">genom data
here</a>.</p>
<audio controls>
  <source src="/assets/posts/dna-synthesized/taurus/out.mp3" type="audio/mpeg">
</audio>
<figure>
<img src="/assets/posts/dna-synthesized/taurus/spectogram.png" alt="Spectogram" />
</figure>
<h2 id="making-a-drummer-out-of-a-dna-sequence">Making a drummer out of a DNA sequence</h2>
<p>To make things even more interesting, I decided to send this data via MIDI to my
<a href="https://www.elektron.se/en/model-samples">Elektron Model:Samples</a>. This is a
really cool piece of equipment that supports MIDI in via USB and 3.5 mm audio
jack.</p>
<p>Elektron is connected to my MacBook via USB cable and audio out is patched to a
Sony Bluetooth speaker I have that supports 3.5 mm audio in. Elektron doesn't
have internal speakers.</p>
<figure>
<img src="/assets/posts/dna-synthesized/elektron/IMG_0619.jpg" alt="" />
</figure>
<figure>
<img src="/assets/posts/dna-synthesized/elektron/IMG_0620.jpg" alt="" />
</figure>
<figure>
<img src="/assets/posts/dna-synthesized/elektron/IMG_0622.jpg" alt="" />
</figure>
<p>For communicating with Elektron, I choose <code>pygame</code> Python module that has MIDI
built in. With this, it was rather simple to send notes to the device. All I did
was map MIDI notes to the actual Nucleotides.</p>
<p>Before all of this I also checked Audio MIDI Setup app under MacOS and checked
MIDI Studio by pressing ⌘-2.</p>
<figure>
<img src="/assets/posts/dna-synthesized/elektron/midi-studio.jpg" alt="" />
</figure>
<p>The whole script that parses and send notes to the Elektron looks like this.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">import</span> pygame.midi
</span></span><span style="display:flex;"><span><span style="color:#00f">import</span> time
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>pygame.midi.init()
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>print(pygame.midi.get_default_output_id())
</span></span><span style="display:flex;"><span>print(pygame.midi.get_device_info(0))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>player = pygame.midi.Output(1)
</span></span><span style="display:flex;"><span>player.set_instrument(2)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">def</span> send_note(note, velocity):
</span></span><span style="display:flex;"><span>  <span style="color:#00f">global</span> player
</span></span><span style="display:flex;"><span>  player.note_on(note, velocity)
</span></span><span style="display:flex;"><span>  time.sleep(0.3)
</span></span><span style="display:flex;"><span>  player.note_off(note, velocity)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>nucleotide_midi_map = {
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#39;A&#39;</span>: 60,
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#39;C&#39;</span>: 90,
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#39;G&#39;</span>: 160,
</span></span><span style="display:flex;"><span>  <span style="color:#a31515">&#39;T&#39;</span>: 180,  <span style="color:#008000"># is D</span>
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">with</span> open(<span style="color:#a31515">&#34;quote.fa&#34;</span>) <span style="color:#00f">as</span> f:
</span></span><span style="display:flex;"><span>  sequence = f.read().replace(<span style="color:#a31515">&#39;</span><span style="color:#a31515">\n</span><span style="color:#a31515">&#39;</span>, <span style="color:#a31515">&#39;&#39;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">for</span> nucleotide <span style="color:#00f">in</span> [char <span style="color:#00f">for</span> char <span style="color:#00f">in</span> sequence]:
</span></span><span style="display:flex;"><span>  print(<span style="color:#a31515">&#34;Playing nucleotide </span><span style="color:#a31515">{}</span><span style="color:#a31515"> with MIDI note </span><span style="color:#a31515">{}</span><span style="color:#a31515">&#34;</span>.format(
</span></span><span style="display:flex;"><span>      nucleotide, nucleotide_midi_map[nucleotide]))
</span></span><span style="display:flex;"><span>  send_note(nucleotide_midi_map[nucleotide], 127)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">del</span> player
</span></span><span style="display:flex;"><span>pygame.midi.quit()
</span></span></code></pre><p><video src="/assets/posts/dna-synthesized/elektron/elektron.mp4" controls></video></p>
<p>All of this could be made much more interesting if I choose different
instruments for different Nucleotides, or doing more funky stuff with Elektron.
But for now, this should be enough. It is just a proof of concept. Something to
play around with.</p>
<h2 id="going-even-further">Going even further</h2>
<p>As you probably notice, the end results are quite similar to each other. This is
to be expected because we are operating only with 4 notes essentially. What
could make this more interesting is using something like
<a href="https://supercollider.github.io/">Supercollider</a> to create more interesting
sounds. By transposing notes or using effects based on repeated data in a
sequence. Possibilities are endless.</p>
<p>It is really astonishing what can be achieved with a little bit of code and an
idea. I could see this becoming an interesting background soundscape instrument
if done properly. It could replace random note generator with something more
intriguing, biological, natural.</p>
<p>I actually find the results fascinating. I took some time and listened to this
music of nature. Even though it's quite the same, it's also quite different.
The subtle differences on repeat kind of creates music on its own. Makes you
wonder. It kind of puts Occam’s Razor in its place. Nature for sure loves to
make things as energy efficient as possible.</p>


guid: https://mitjafelicijan.com/aerial-photography-of-algae-spotted-on-river-sava.html
title: Aerial photography of algae spotted on river Sava
url: https://mitjafelicijan.com/aerial-photography-of-algae-spotted-on-river-sava.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>This is a bit of a different post than I usually write, but quite interesting
one to me. River Sava has plenty of hydropower plants located down the stream.
This makes regulating the strength of a current easier than normally. Because of
lower stream strength and high temperatures, algae has formed on the river.
This is the first time I've seen something like this in my whole life.</p>
<p>Below are some photographs taken from a DJI drone capturing the event.</p>
<figure>
<img src="/assets/posts/algae-sava/dji-algae-0.jpg" alt="Algae on Sava" />
</figure>
<figure>
<img src="/assets/posts/algae-sava/dji-algae-1.jpg" alt="Algae on Sava" />
</figure>
<figure>
<img src="/assets/posts/algae-sava/dji-algae-2.jpg" alt="Algae on Sava" />
</figure>
<figure>
<img src="/assets/posts/algae-sava/dji-algae-3.jpg" alt="Algae on Sava" />
</figure>
<figure>
<img src="/assets/posts/algae-sava/dji-algae-4.jpg" alt="Algae on Sava" />
</figure>
<figure>
<img src="/assets/posts/algae-sava/dji-algae-5.jpg" alt="Algae on Sava" />
</figure>
<p>I will try to get more photos of this in the future days and if something
intriguing shows up will post it again on the blog.</p>


guid: https://mitjafelicijan.com/state-of-web-technologies-and-web-development-in-year-2022.html
title: State of Web Technologies and Web development in year 2022
url: https://mitjafelicijan.com/state-of-web-technologies-and-web-development-in-year-2022.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<h2 id="initial-thoughts">Initial thoughts</h2>
<p><em>This post is a critique on the current state of web development. It is an
opinionated post! I will learn more about this in the future, and probably
slightly change my mind about some of the things I criticize.</em></p>
<p>I have started working on a hobby project about two weeks ago, and I wanted to
use that situation as a learning one. Trying new things, new technologies, new
tools. I always considered myself to be an adventurous person when it comes to
technology. I never shy away from trying new languages, new operating systems
etc. Likewise, I find the whole experience satisfying, and it tickles that part
of my brain that finds discovery the highest of the mountains to climb.</p>
<p>What I always wanted to make was a coding game, that you would play in a browser
(just to eliminate building binaries for each operating system) where you would
level up your character and go into these scriptable battles. You know, RPG
elements.</p>
<p>So, the natural way to go would be some sort of SPA (single page application)
with basic routing and some state management. Nothing crazy.</p>
<blockquote>
<p><strong>Before we move on</strong>, I have to be transparent. Take my views on this with
a grain of salt. I have only scratched the surface with these technologies,
and my knowledge is full of gaps. This is my experience using some of these
products for the first time or in a limited capacity.</p>
</blockquote>
<p>Having this out of the way, I got myself a fresh pot of coffee and down the
rabbit hole I went.</p>
<h2 id="giving-react-js-a-spin">Giving React JS a spin</h2>
<p>I first tried <a href="https://reactjs.org/">React JS</a>. I kind of like it. Furthermore,
I have worked with libraries like this in the past and also wrote a couple of
them (nothing compared to that level), but I had the basic understanding of what
was going on. I rolled up a project quickly and had basic things done in a
matter of two hours, which was impressive.</p>
<p>I prefer using <a href="https://tailwindcss.com/">Tailwind CSS</a> for my styling
pleasures, and integrating that was also a painless experience. It was actually
nice to see that some things got better with time. In about 2 minutes I got
Tailwind working, and I was able to use classes at my disposal. All that
<code>postcss</code> stuff was taken care of by adding a couple of things in config files
(all described really well in their documentation).</p>
<p>It is not that different from Vue which I have had more encounters with in the
past People will probably call me a lunatic for saying this. But you know, it is
the truth. Same same, but different. I still believe that using libraries like
this is beneficial. I am not a JavaScript purist. They all have their quirks,
but at the end of the day, I truly believe it’s worth it.</p>
<h2 id="bundlers-and-transpilers">Bundlers and Transpilers</h2>
<p>I still reject calling <a href="https://www.typescriptlang.org/">Typescript</a> to
<a href="https://www.javascript.com/">JavaScript</a> conversion a &quot;compilation process&quot;.  I
call them <a href="https://devopedia.org/transpiler">transpilers</a>, and I don’t care! 😈</p>
<p>The first one that I ever used was <a href="https://webpack.js.org/">webpack</a>, and it
was an absolute horrific experience. Saying this, it is an absolutely fantastic
tool. I felt more like a config editor than actually a programmer.  To be fair,
I am a huge fan of <a href="https://www.gnu.org/software/make/">make</a>, and you can do as
you wish with this information. I like my build systems simple.</p>
<p>Also, isn’t it interesting that we need something like
<a href="https://babeljs.io/">Babel</a> to make JavaScript code work in a browser that has
only one client side scripting available, which is by no accident also
JavaScript. Why? I know why it’s needed, but seriously, why.</p>
<p>I haven’t used Babel for years now. Or if I did, it was packaged together by
some other bundler thingy. Which does not make things better, but at least I
didn’t need to worry about it.</p>
<p>I really don’t like complicated build systems. I really don’t like abstracting
code and making things appear magical. The older I get, the more I appreciate
clear and clean, expressive code. No one-liners, if possible.</p>
<p>But I have to give props to <a href="https://vitejs.dev/">Vite</a>! This was one of the
best developer experiences I have ever had. Granted, it still has magical
properties. And yes, it still is a bundler and abstracts things to the nth
degree. But at least it didn’t force me to configure 700 lines of JSON. And I
know that this makes me a hypocrite. You can’t have it all. Nonetheless, my
reasoning here is, if using bundlers is inevitable, then at least they should
provide an excellent developer experience.</p>
<p>I also noticed that now the catch-all phrase is “blazingly fast” and “lightning
fast” and “next generation” and stuff like that. I mean, yeah, tools should get
faster with time. But saying that starting a project now takes 2 seconds instead
of 20 seconds is something that is a break it or make it kind of a deal is
ridiculous. I don’t mind waiting a couple of seconds every couple of days. I
also don’t create 700 projects every day, and also who does? This argument has
no bite. All I want is a decent reload time (~100ms is more than good enough for
me) and that is it.</p>
<p>You don’t need to sell me benefits if I only get them when I start a fresh
project, and then try to convince me that this is somehow changing the fate of
the universe. First of all, it is not. And second, if this is your only argument
for your tool, I would advise you to maybe re-focus your efforts to something
else. Vite says that startup times are really fast. And if that would be the
only thing differentiating it from other tools, I would ignore it. But it has
some really compelling features like <a href="https://www.geeksforgeeks.org/reactjs-hot-module-replacement/">Hot Module
Replacement</a> that
really works well. It was a joy to use.</p>
<p>So, I will be definitely using Vite in the future.</p>
<h2 id="jam-stack-mach-stack-no-snack">Jam Stack, Mach Stack no snack</h2>
<p>Let's get a couple of the acronyms out of the way, so we all know what we are
talking about:</p>
<ul>
<li>Jam Stack - JavaScript, API and Markup</li>
<li>Mach Stack - Microservices, API-first, Cloud-Native SaaS, Headless</li>
</ul>
<p>It is so hard to follow all these new trendy things happening around you, that
it makes you have a massive <strong>FOMO</strong> all the time. But on the other hand, you
also don’t want to be that old fart that doesn’t move with the times and still
writes his trusty jQuery code while listening to Blink 182 All the small things
on full blast. It’s a good song, don’t get me wrong, but there are other songs
out there.</p>
<p>I have to admit. <a href="https://vercel.com/">Vercel</a> is really cool! Love the
simplicity of the service. You could compare it to
<a href="https://www.netlify.com/">Netlify</a>.  I haven’t tried Netlify extensively, but
from a couple of experimental deployments I still prefer Vercel. It is much more
streamlined, but maybe this is bias in me. I really like Vercel’s Analytics,
which give you a <a href="https://web.dev/vitals/">Core Web Vitals report</a> in their
admin console. Kind of cool, I’m not going to lie.</p>
<p>This whole idea about frontend and backend merging into <a href="https://www.debugbear.com/blog/server-side-rendering">SSR (server-side
rendering)</a> looks so good
on paper. It almost doesn’t come with any major flaws.</p>
<p>But when it comes to the actual implementation, there is much to be desired.
I’m going to lump <a href="https://nextjs.org/">Next.js</a> and
<a href="https://nuxtjs.org/">Nuxt.js</a> together because they are essentially the same
thing, just a different library.</p>
<p>Now comes the reality. Mixing backend and frontend in this manner creates this
weird mental model where you kind of rely on magical properties of these
libraries. You relinquish control over to them for better developer experience.
But is that really true? Initially, I was so stoked about it. However, the more
I used them, the more I felt uncomfortable. I felt dirty, actually. Maybe this
is because I come from old ways of doing things where you control every step of
request, and allowing something to hijack it feels like blasphemy.</p>
<p>More than that, some pretty significant technical issues arose from this. How do
you do JWT token authentication? You put it in <code>api</code> folder and then do some
fetching and storing into local state management. But doing this also requires
some tinkering with await/async stuff on the React/Vue side of things. And then
you need to write middleware for it. And the more I look at it, the more I see
that this whole thing was not meant to be used like this, and it all feels and
looks like a huge hack.</p>
<p>The issue I have with this is that they over-promise and under-deliver. They
want to be an all-in-one replacement for everything, and they don’t deliver on
this promise. And how could they?! We have to be fair. It is an impossible task.</p>
<p>They sell you <a href="https://www.geeksforgeeks.org/overview-of-noops/">NoOps</a>, but
when you need to accomplish something a little bit more out of the scope of
Hello World, you have to make hacky decisions to make it work. And having a
deployment strategy that relies on many moving parts is never a good idea.
Abstracting too much is usually a sign of bad architecture.</p>
<p>Lately, this has become a huge trend that will for sure bite us in the future.
And let’s not get it twisted. By doing this, PaaS providers like
<a href="https://aws.amazon.com/">AWS</a>, <a href="https://cloud.google.com/">GCS</a>, etc. obscure
their billing, and you end up paying more than you really should. And even if
that is not an issue, it comes down to the principle of things. AWS is known for
having multiple “currencies“ inside their projects like write operations, read
operations, etc. which add up, and it creates this impossible to track billing
scheme. It all behaves suspiciously like a pay-to-win game you could find on
mobile phones that scams you out of your money.</p>
<p>And as far as I am concerned, the most important thing was me not coding the
functionalities for the game I want to make. I was battling libraries and cloud
providers. How to deploy, what settings are relevant. Bad documentation or
multiple versions of achieving the same thing. You are getting bombarded by all
this information, and you don’t really have any control over it.
Production-ready code becomes a joke, essentially. Especially if you tend to
work on that project for a prolonged period of time.</p>
<p>All of these options end up creating a fatigue. What to choose, what not to
choose. Unnecessary worrying about if the stack will still be deemed worthy in
six months. There is elegance in simplicity.</p>
<blockquote>
<p>JavaScript UI frameworks and libraries work in cycles. Every six months or
so, a new one pops up, claiming that it has revolutionized UI development.
Thousands of developers adopt it into their new projects, blog posts are
written, Stack Overflow questions are asked and answered, and then a newer
(and even more revolutionary) framework pops up to usurp the throne.
— Ian Allen</p>
</blockquote>
<p>And this jab at these libraries and cloud providers is not done out of malice.
It is a real concern that I have about them. In my life, I have seen
technologies come and go, but the basics always stick around. So surrendering
all the power you have to a library or a cloud provider is in my opinion a
stupid move.</p>
<h2 id="tailwind-css-still-rocks">Tailwind CSS still rocks!</h2>
<p>You know, many people say negative things about Tailwind. And after a lot of
deliberation, I came to the conclusion that Tailwind is good for two types of
developers. Tailwind is good for a complete noob or a senior developer. A
complete noob doesn’t really care about inner workings of CSS, and a senior
developer also doesn’t care about CSS. Well, at least, not anymore. And
developers in between usually have the biggest issues with it. Not always of
course, but in a lot of cases.</p>
<p>I like the creature comforts of Tailwind. Being utility first would make me
argue that it is actually more similar to <a href="https://sass-lang.com/">Sass</a> or
<a href="https://lesscss.org/">Less</a> than something like Bootstrap. Not technically, but
ideologically. After I started using it, I never looked back. I use it every
time I need to do something web related.</p>
<p>Writing CSS for general things feels like going several steps back. Instead of
focusing on what you are actually trying to achieve, you focus on notations like
<a href="https://en.bem.info/methodology/css/">BEM</a>, code structuring, optimizing HTML
size. Just doing things that make 0.1% difference. You know that saying: Early
optimization is the root of all evil. Exactly that.</p>
<p>I am also not saying that Tailwind is the cure for everything. Sometimes custom
CSS is necessary. But from what I found out in using it for almost two years in
a production environment (on a site getting quite a lot of traffic and
constantly being changed), I can say without any reservations that Tailwind
saved our asses countless times. We would be rewriting CSS all the time without
it. And I don’t really think writing CSS is the best way to spend my time.</p>
<p>I have also noticed that people who criticize Tailwind the most never actually
used it in a real project that has a long lifetime with plenty of changes that
will happen in the future.</p>
<p>But you know, whatever floats your boat!</p>
<h2 id="code-maintainability">Code maintainability</h2>
<p>Somehow, people also stopped talking about maintenance. If you constantly try to
catch the latest and greatest train, you are by that logic always trying new
things. Which is a good thing if you want to learn about technologies and try
them. But for the production environment, you have to have a stable stack that
doesn’t change every 6 months.</p>
<p>You can lock dependencies for sure. Nevertheless, the hype train moves along
anyway. And the mindset this breeds goes against locking the code. This
bleeding-edge rolling release cycle is not helping. That is why enterprise
solutions usually look down on these popular stacks and only do bare minimum to
appear hip and cool.</p>
<p>With that said, I still think that progress is good, but should be taken with a
grain of salt. If your project is something that should be built once and then
rarely updated, going with the latest stack is a possible way to go. But, if you
are working on a project that lasts for years, you should probably approach it
with some level of caution. Web development is often times too volatile.</p>
<h2 id="web-development-has-a-marketing-issue">Web development has a marketing issue</h2>
<p>I noticed that almost every project now has this marketing spin put on it.
Everything is blazingly fast now. I get it, they are competing for your
attention, but what happened to just being truthful and not inflating reality.</p>
<p>And in order to appeal to mass market, they leave things out of their marketing
materials. These open-source projects are now behaving more and more like
companies do. Which is a scary thought on its self.</p>
<p>And we are also seeing a rise in a concept of building a company in the open,
which is a good thing, don't get me wrong. But when it is using open-source to
lure people and then lock them in their ecosystem, there is where I have issues
with it.</p>
<p>This might be because I have been using GNU/Linux for 20 years now and have been
so beholden for my success to open-source that I see issues when open-source is
being used to trick people into a false sense of security that these projects
are built in the spirit of open-source. Because there is a difference. They are
NOT! They have a really specific goal in mind. And the open-source is being used
as a delivery system. Which is in my opinion disgusting!</p>
<h2 id="conclusion">Conclusion</h2>
<p>I will end my post with this. Web development is running now in circles. People
are discovering <a href="https://www.tutorialspoint.com/remote-procedure-call-rpc">RPC</a>
now and this is the now the next big thing. <a href="https://graphql.org/">GraphQL</a> is
so passé. And I am so tired of it all. Of blazingly fast libraries, of all these
new technologies that are actually just a remake of old ones. Of just the
general spirit of the web. I will just use what I already know. Which worked 10
years ago and will work 10 years after this. I will adopt a couple of little
tools like Vite. But I will not waste my time on this anymore.</p>
<p>It was a good exercise to get in touch with what’s new now. Nothing really
changed that much. FOMO is now cured! Now I have to get my ass back to actually
code and make the project that I wanted to make in the first place.</p>


guid: https://mitjafelicijan.com/that-sound-that-machine-makes-when-struggling.html
title: Microsoundtrack — That sound that machine makes when struggling
url: https://mitjafelicijan.com/that-sound-that-machine-makes-when-struggling.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>A couple of months ago, I got an idea about micro soundtracks. In this concept,
you are the observer, director, and audience in this tiny movies.</p>
<p>What you do is to attempt to imagine what would be happening around you based on
a title of the song and let the song help you fill the void in your story.</p>
<p>I made these songs is Logic Pro X. Every year or so I do this kind of thing and
make a couple of songs similar to this. But this is the first time I am posting
about it.</p>
<p>You can listen to the whole set on
<a href="https://www.youtube.com/watch?v=_5oXBhSmF3c">Youtube</a> or scroll down the page
and there are embedded players for each song.</p>
<h2 id="a-bunch-of-inter-dimensional-people-with-loud-clocks">A bunch of inter-dimensional people with loud clocks</h2>
<p>A group of inter-dimensional people are going up and down the elevator with you
while having loud clocks around their necks. Each clock ticks on a different
frequency. A lot of other sounds are getting drawn into your dimension,
resulting in a strange merging of dimensions.</p>
<iframe style="border: 0; width: 100%; height: 42px;" src="https://bandcamp.com/EmbeddedPlayer/album=3913808801/size=small/bgcol=ffffff/linkcol=0687f5/track=1349272965/transparent=true/" seamless title="Bandcamp"><a href="https://mitjafelicijan.bandcamp.com/album/that-sound-that-machine-makes-when-struggling">That sound that machine makes when struggling by Mitja Felicijan</a></iframe>
<h2 id="two-black-holes-conversing-about-the-weather">Two black holes conversing about the weather</h2>
<p>You are a traveler in a spaceship flying very close to two colliding black holes
having a discussion about the weather while tearing each other apart. During all
this your ship is getting pulled into the event horizon of both black holes,
putting a lot of strain on your spaceship.</p>
<iframe style="border: 0; width: 100%; height: 42px;" src="https://bandcamp.com/EmbeddedPlayer/album=3913808801/size=small/bgcol=ffffff/linkcol=0687f5/track=1756714200/transparent=true/" seamless title="Bandcamp"><a href="https://mitjafelicijan.bandcamp.com/album/that-sound-that-machine-makes-when-struggling">That sound that machine makes when struggling by Mitja Felicijan</a></iframe>
<h2 id="a-planet-where-every-organism-is-a-plant">A planet where every organism is a plant</h2>
<p>You land on a planet where every living organism is a plant and among those
plants some of them are highly intelligent, and you were asked to make first
contact with the native species. Your visit takes place in a giant cave where
you are meeting these plants, and they are talking to you.</p>
<iframe style="border: 0; width: 100%; height: 42px;" src="https://bandcamp.com/EmbeddedPlayer/album=3913808801/size=small/bgcol=ffffff/linkcol=0687f5/track=3710973979/transparent=true/" seamless title="Bandcamp"><a href="https://mitjafelicijan.bandcamp.com/album/that-sound-that-machine-makes-when-struggling">That sound that machine makes when struggling by Mitja Felicijan</a></iframe>
<h2 id="bio-implants-having-a-fit-and-reprogramming-your-brain">Bio implants having a fit and reprogramming your brain</h2>
<p>In a distant future where everybody has bio implants, you have just received
your first one, which happens to be a brain implant. Something goes wrong, and
your implant is starting to misbehave, and you are experiencing brain
malfunctions. You are on the streets at night a couple of hours after your
procedure. You can feel your sanity breaking down.</p>
<iframe style="border: 0; width: 100%; height: 42px;" src="https://bandcamp.com/EmbeddedPlayer/album=3913808801/size=small/bgcol=ffffff/linkcol=0687f5/track=1157430581/transparent=true/" seamless title="Bandcamp"><a href="https://mitjafelicijan.bandcamp.com/album/that-sound-that-machine-makes-when-struggling">That sound that machine makes when struggling by Mitja Felicijan</a></iframe>
<h2 id="cow-animation">Cow animation</h2>
<p>I also made this little cow animation. Go into full screen to see the effects in
more details.</p>
<p><video src="/assets/posts/microsoundtrack/cow.m4v" controls loop></video></p>


guid: https://mitjafelicijan.com/trying-to-build-a-new-kind-of-terminal-emulator.html
title: Trying to build a New kind of terminal emulator for the modern age
url: https://mitjafelicijan.com/trying-to-build-a-new-kind-of-terminal-emulator.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Over the past few weeks, I have been really thinking about terminal emulators,
how we interact with computers, the separation of text-based programs and GUI
ones. To be perfectly honest, I got pissed off one evening when I was cleaning
up files on my computer. Normally, I go into console and do <code>ncdu</code> and check
where the junk is. Then I start deleting stuff. Without any discrimination,
usually. But when it comes to screenshots, I have learned that it's good to keep
them somewhere near if I need to refer to something that I was doing. I am an
avid screenshot taker. So at that point I checked Pictures folder and also did a
basic search <code>find . -type f -name &quot;*.jpg&quot;</code> for all the JPEG files in my home
directory and immediately got pissed off. Why can’t I see thumbnails in my
terminal? I know why, but why in the year of 2022 this is still a problem. I am
used to traversing my disk via terminal. I am faster, and I am more comfortable
this way. But when it comes to visualization, I then need to revert to GUI
applications and again find the same file to see it. I know that programs like
<code>feh</code> and <code>sxiv</code> are available, but I would just like to see the preview. Like
<a href="https://jupyter.org/">Jupyter notebook</a> or something similar.  Just having it
inline. Part of a result.</p>
<p>It also didn’t help that I was spending some time with the <a href="https://plan9.io/plan9/">Plan
9</a> Operating system. More specifically
<a href="http://9front.org/">9FRONT</a>. The way that <a href="http://acme.cat-v.org/">ACME editor</a>
handles text editing is just wonderful. Different and fresh somehow, even though
it’s super old.</p>
<p>So, I went on a lookout for an interesting way of visualizing results of some
query. I found these applications to be outstanding examples of how not to be a
captive of a predetermined way of doing things.</p>
<ul>
<li><a href="https://www.wolfram.com/mathematica/">Wolfram Mathematica</a></li>
<li><a href="https://jupyter.org/">Jupyter notebooks</a></li>
<li><a href="http://www.9front.org">Plan 9 / 9FRONT</a></li>
<li><a href="https://templeos.org/">Temple OS</a></li>
<li><a href="https://www.gnu.org/software/emacs/">Emacs</a></li>
</ul>
<p>My idea is not as out there as ACME is, but it is a spin on the terminal
emulators. I like the modes that Vi/Vim provides you with. I like the way the
Emacs does its own <code>M-x</code> <code>M-c</code>.  Furthermore, I really like how Mathematica and
Jupyter present the data in a free flowing form. And I love how Temple OS is
basically a C interpreter on some level.</p>
<blockquote>
<p><strong>Note:</strong> This is part 1 of the journey. Nowhere finished yet. I am just
tinkering with this at the moment. This whole thing can easily spectacularly
fail.</p>
</blockquote>
<p>So I started. I knew that I wanted to have the couple of modes, but I didn’t
like the repetition of keystrokes, so the only option was to have some sort of
toggle and indicate to the user that they are in a special mode. Like Vi does
for Normal and Visual mode.</p>
<p>These modes would for the first version be:</p>
<ul>
<li><em>Preview mode</em> (toggle with Ctrl + P)
<ul>
<li>When this mode would be enabled, the <code>ls</code> command would try to find images
from the results and display thumbnails from them in the terminal itself.
No ASCII art. Proper images. In a grid!</li>
</ul>
</li>
<li><em>Detach mode</em> (toggle with Ctrl + D)
<ul>
<li>When this mode would be enabled, every command would open a new window
and execute that command in it. This would be useful for starting <code>htop</code>
in a separate window.</li>
</ul>
</li>
</ul>
<p>The reason for having these modes togglable is to not ask for previews every
time. You enable a mode and until you disable it, it behaves that way.  Purely
out of ergonomic reasons.</p>
<p>I would like to treat every terminal I open as a session mentally. When I start
using the terminal, I start digging deeper into the issue I am trying to
resolve.  And while I am doing this, I would like to open detached windows
etc. A lot of these things can be done easily with something like
<a href="https://i3wm.org/">i3</a>, but also that pull you out of the context of what you
were doing. I would like to orchestrate everything from one single point.</p>
<p>In planning for this project, I knew that I would need to use a language like C
and a library such as <a href="https://www.libsdl.org/">SDL2</a> in order to achieve the
desired results. I had considered other options, but ultimately determined that
<a href="https://www.libsdl.org/">SDL2</a> was the best fit based on its capabilities and
reputation in the programming community.</p>
<p>At first, I thought the idea of a hardware accelerated terminal was a bit of a
joke. It seemed like such a niche and unnecessary feature, especially given the
fact that terminal emulators have been around for decades and have always relied
on software rendering. But to be fair, <a href="https://alacritty.org/">Alacritty</a> is
doing the same thing. Well, they are doing a remarkable job at it.</p>
<p>So, I embarked on a journey. Everything has to start somewhere. For me, it
started with creating a window! It has to start somewhere. 🙂</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000">// Oh, Hi Mark!
</span></span></span><span style="display:flex;"><span><span style="color:#008000">// Create the window, obviously.
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span>SDL_Window *window = SDL_CreateWindow(
</span></span><span style="display:flex;"><span>  WINDOW_TITLE, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
</span></span><span style="display:flex;"><span>  WINDOW_WIDTH, WINDOW_HEIGHT,
</span></span><span style="display:flex;"><span>  SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
</span></span></code></pre><p>I continued like this to get some text displayed on the screen.</p>
<p>I noted that
<a href="https://wiki.libsdl.org/SDL_ttf/TTF_RenderText_Solid"><code>TTF_RenderText_Solid</code></a>
rendered text really poorly. There were no antialiasing at all. In my wisdom, I
never checked the documentation. Well, that was a fail. To uneducated like me:
<code>TTF_RenderText_Solid</code> renders Latin1 text at fast quality to a new 8-bit
surface. So, that's why the texts looked like shit. No wonder.</p>
<p>Remarks on <code>TTF_RenderText_Solid</code>: This function will allocate a new 8-bit,
palettized surface. The surface's 0 pixel will be the colorkey, giving a
transparent background. The 1 pixel will be set to the text color.</p>
<p>After I replaced it with
<a href="https://wiki.libsdl.org/SDL_ttf/TTF_RenderText_LCD"><code>TTF_RenderText_LCD</code></a> which
renders Latin1 text at LCD subpixel quality to a new ARGB surface, the text
started looking good. Really make sure you read the documentation. It’s actually
good. As a side note, you can find all the documentation regarding <a href="https://wiki.libsdl.org/">SDL2 on
their Wiki</a>.</p>
<p>After that was done, I started working on displaying other things like <code>Preview</code>
and <code>Detach</code> modes. This wasn’t really that hard. In SDL2 you can check all the
available events with <code>while (SDL_PollEvent(&amp;event) &gt; 0)</code> and have a bunch of
switch statements to determine which key is currently being pressed. More about
keys, <a href="https://documentation.help/SDL/sdlkey.html">SDLKey</a> and mroe about
pooling the events on
<a href="https://documentation.help/SDL/sdlpollevent.html">SDL_PollEvent</a>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">while</span> (SDL_PollEvent(&amp;event) &gt; 0)
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#00f">switch</span> (event.type)
</span></span><span style="display:flex;"><span>  {
</span></span><span style="display:flex;"><span>  <span style="color:#00f">case</span> SDL_QUIT:
</span></span><span style="display:flex;"><span>    running = false;
</span></span><span style="display:flex;"><span>    <span style="color:#00f">break</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">case</span> SDL_TEXTINPUT:
</span></span><span style="display:flex;"><span>    <span style="color:#00f">if</span> (!meta_key_pressed)
</span></span><span style="display:flex;"><span>    {
</span></span><span style="display:flex;"><span>      strncat(input_prompt_text, event.text.text, 1);
</span></span><span style="display:flex;"><span>      update_input_prompt = true;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#00f">break</span>;
</span></span><span style="display:flex;"><span>	}
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>After that was somewhat working correctly, I started creating a struct that
would hold all the commands and results and I call them Cells. Yes, I stole that
naming idea from Jupyter.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">typedef</span> <span style="color:#00f">struct</span>
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#2b91af">char</span> *command;
</span></span><span style="display:flex;"><span>  <span style="color:#2b91af">char</span> *result;
</span></span><span style="display:flex;"><span>  SDL_Surface *surface;
</span></span><span style="display:flex;"><span>  SDL_Texture *texture;
</span></span><span style="display:flex;"><span>  SDL_Rect rect;
</span></span><span style="display:flex;"><span>} Cell;
</span></span></code></pre><p>I am at a place now where I am starting to implement scrolling. This will for
sure be fun to code. Memory management in C is super easy. 😂</p>
<p>I have also added a simple <a href="https://en.wikipedia.org/wiki/INI_file">INI file like
configuration</a> support. It is done in an
<a href="https://github.com/nothings/stb/blob/master/docs/stb_howto.txt">STB style of
header</a> and maps
to specific options supported by the terminal. It is not universal, and the code
below demonstrates how I will use it in the future.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">#ifndef CONFIG_H
</span></span></span><span style="display:flex;"><span><span style="color:#00f">#define CONFIG_H
</span></span></span><span style="display:flex;"><span><span style="color:#00f"></span>
</span></span><span style="display:flex;"><span><span style="color:#008000">/*
</span></span></span><span style="display:flex;"><span><span style="color:#008000"># This is a comment
</span></span></span><span style="display:flex;"><span><span style="color:#008000">
</span></span></span><span style="display:flex;"><span><span style="color:#008000"># This is the first configuration option
</span></span></span><span style="display:flex;"><span><span style="color:#008000">dettach=value11111
</span></span></span><span style="display:flex;"><span><span style="color:#008000">
</span></span></span><span style="display:flex;"><span><span style="color:#008000"># This is the second configuration option
</span></span></span><span style="display:flex;"><span><span style="color:#008000">preview=value22222
</span></span></span><span style="display:flex;"><span><span style="color:#008000">
</span></span></span><span style="display:flex;"><span><span style="color:#008000"># This is the third configuration option
</span></span></span><span style="display:flex;"><span><span style="color:#008000">debug=value33333
</span></span></span><span style="display:flex;"><span><span style="color:#008000">*/</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000">// Define a struct to hold the configuration options
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span><span style="color:#00f">typedef</span> <span style="color:#00f">struct</span>
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>    <span style="color:#2b91af">char</span> dettach[256];
</span></span><span style="display:flex;"><span>    <span style="color:#2b91af">char</span> preview[256];
</span></span><span style="display:flex;"><span>    <span style="color:#2b91af">char</span> debug[256];
</span></span><span style="display:flex;"><span>} Config;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000">// Read the configuration file and return the options as a struct
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span><span style="color:#00f">extern</span> Config read_config_file(<span style="color:#00f">const</span> <span style="color:#2b91af">char</span> *filename)
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#008000">// Create a struct to hold the configuration options
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span>  Config config = {0};
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#008000">// Open the configuration file
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span>  FILE *file = fopen(filename, <span style="color:#a31515">&#34;r&#34;</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#008000">// Read each line from the file
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span>  <span style="color:#2b91af">char</span> line[256];
</span></span><span style="display:flex;"><span>  <span style="color:#00f">while</span> (fgets(line, <span style="color:#00f">sizeof</span>(line), file))
</span></span><span style="display:flex;"><span>  {
</span></span><span style="display:flex;"><span>    <span style="color:#008000">// Check if this line is a comment or empty
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span>    <span style="color:#00f">if</span> (line[0] == <span style="color:#a31515">&#39;#&#39;</span> || line[0] == <span style="color:#a31515">&#39;\n&#39;</span>)
</span></span><span style="display:flex;"><span>      <span style="color:#00f">continue</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#008000">// Parse the line to get the option and value
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span>    <span style="color:#2b91af">char</span> option[128], value[128];
</span></span><span style="display:flex;"><span>    <span style="color:#00f">if</span> (sscanf(line, <span style="color:#a31515">&#34;%[^=]=%s&#34;</span>, option, value) != 2)
</span></span><span style="display:flex;"><span>      <span style="color:#00f">continue</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#008000">// Set the value of the appropriate option in the config struct
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span>    <span style="color:#00f">if</span> (strcmp(option, <span style="color:#a31515">&#34;dettach&#34;</span>) == 0)
</span></span><span style="display:flex;"><span>    {
</span></span><span style="display:flex;"><span>      strncpy(config.option1, value, <span style="color:#00f">sizeof</span>(config.option1));
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#00f">else</span> <span style="color:#00f">if</span> (strcmp(option, <span style="color:#a31515">&#34;preview&#34;</span>) == 0)
</span></span><span style="display:flex;"><span>    {
</span></span><span style="display:flex;"><span>      strncpy(config.option2, value, <span style="color:#00f">sizeof</span>(config.option2));
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#00f">else</span> <span style="color:#00f">if</span> (strcmp(option, <span style="color:#a31515">&#34;debug&#34;</span>) == 0)
</span></span><span style="display:flex;"><span>    {
</span></span><span style="display:flex;"><span>      strncpy(config.option3, value, <span style="color:#00f">sizeof</span>(config.option3));
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#008000">// Close the configuration file
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span>  fclose(file);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#008000">// Return the configuration options
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span>  <span style="color:#00f">return</span> config;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">#endif
</span></span></span></code></pre><p>This is as far as I managed to get for now. I have a daily job and this
prohibits me to work on these things full time. But I should probably get back
and finish this. At least have a simple version working out, so I can start
testing it on my machines. Fingers crossed. 🕵️‍♂️</p>


guid: https://mitjafelicijan.com/cachebusting-in-hugo.html
title: Cache busting in Hugo
url: https://mitjafelicijan.com/cachebusting-in-hugo.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>\{\{ $cachebuster := delimit (shuffle (split (md5 &#34;6fab11c6669976d759d2992eff1dd5be&#34;) &#34;&#34; )) &#34;&#34; \}\}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>&lt;link rel=<span style="color:#a31515">&#34;stylesheet&#34;</span> href=<span style="color:#a31515">&#34;/style.css?v=\{\{ $cachebuster \}\}&#34;</span>&gt;
</span></span></code></pre><p>This <code>6fab11c6669976d759d2992eff1dd5be</code> can be random string you generate use.
You can use whatever you want.</p>


guid: https://mitjafelicijan.com/run-9front-in-qemu.html
title: Run 9front in Qemu
url: https://mitjafelicijan.com/run-9front-in-qemu.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Run 9front in Qemu. This applies to <a href="https://9p.io/plan9/">Plan9</a> and
<a href="https://9front.org/">9front</a>.</p>
<p>Download from here <a href="http://9front.org/iso/">http://9front.org/iso/</a>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># Create a qcow2 image.</span>
</span></span><span style="display:flex;"><span>qemu-img create -f qcow2 $HOME/VM/9front.qcow2.img 30G
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Run the VM.</span>
</span></span><span style="display:flex;"><span>qemu-system-x86_64 -cpu host -enable-kvm -m 1024 <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>    -net nic,model=virtio,macaddr=52:54:00:00:EE:03 -net user <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>    -device virtio-scsi-pci,id=scsi <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>    -drive <span style="color:#00f">if</span>=none,id=vd0,file=$HOME/VM/9front.qcow2.img <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>    -device scsi-hd,drive=vd0 <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>    -drive <span style="color:#00f">if</span>=none,id=vd1,file=$HOME/VM/ISO/9front.386.iso <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>    -device scsi-cd,drive=vd1,bootindex=0
</span></span></code></pre>


guid: https://mitjafelicijan.com/git-push-multiple-origins.html
title: Push to multiple origins at once in Git
url: https://mitjafelicijan.com/git-push-multiple-origins.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Sometimes you want to push to multiple origins at once. This is useful if you
have a mirror of your repository on another server. You can do this by adding
multiple push urls to your git config. This is a shorthand for command above.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>git config --global alias.pushall <span style="color:#a31515">&#39;!sh -c &#34;git remote | xargs -L1 git push --all&#34;&#39;</span>
</span></span></code></pre>


guid: https://mitjafelicijan.com/mount-plan9-over-network.html
title: Mount Plan9 over network
url: https://mitjafelicijan.com/mount-plan9-over-network.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<ul>
<li>First install libfuse with sudo apt install libfuse-dev.</li>
<li>Then clone <a href="https://github.com/ftrvxmtrx/9pfs">https://github.com/ftrvxmtrx/9pfs</a> and compile it with make.</li>
<li>Copy 9pfs to your path.</li>
</ul>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># On Plan9 side</span>
</span></span><span style="display:flex;"><span>ip/ipconfig <span style="color:#008000"># enables network</span>
</span></span><span style="display:flex;"><span>aux/listen1 -tv tcp!*!9999 /bin/exportfs -r tmp <span style="color:#008000"># export tmp folder</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># On Linux side</span>
</span></span><span style="display:flex;"><span>9pfs 172.18.0.1 -p 9999 local_folder <span style="color:#008000"># mount</span>
</span></span><span style="display:flex;"><span>umount local_folder <span style="color:#008000"># unmount</span>
</span></span></code></pre>


guid: https://mitjafelicijan.com/write-iso-usb.html
title: Write ISO to USB Key
url: https://mitjafelicijan.com/write-iso-usb.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Write ISO to USB key. Nothing fancy here.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo dd <span style="color:#00f">if</span>=iso_file.iso of=/dev/sdX bs=4M status=progress conv=fdatasync
</span></span></code></pre>


guid: https://mitjafelicijan.com/catv-weechat-config.html
title: #cat-v on weechat configuration
url: https://mitjafelicijan.com/catv-weechat-config.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Set up weechat to connect to #cat-v on oftc. This applies to
<a href="https://weechat.org/">weechat</a> but should be similar for other irc clients.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># Install weechat and launch it and execute the following commands.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>/server add oftc irc.oftc.net -tls
</span></span><span style="display:flex;"><span>/set irc.server.oftc.autoconnect on
</span></span><span style="display:flex;"><span>/set irc.server.oftc.autojoin <span style="color:#a31515">&#34;#cat-v&#34;</span>
</span></span><span style="display:flex;"><span>/set irc.server.oftc.nicks <span style="color:#a31515">&#34;nick1,nick2,nick3&#34;</span>
</span></span></code></pre>


guid: https://mitjafelicijan.com/plan9-screenshot.html
title: Take a screenshot in Plan9
url: https://mitjafelicijan.com/plan9-screenshot.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Take a screenshot in Plan9. This applies to <a href="https://9p.io/plan9/">Plan9</a> and
<a href="https://9front.org/">9front</a>. This will take a screenshot of the screen and
output it to <code>/dev/screen</code>. You can then use <code>topng</code> to convert it to a png
image.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># Instant screenshot.</span>
</span></span><span style="display:flex;"><span>cat /dev/screen | topng &gt; screen.png
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Delayed screenshot (5 seconds).</span>
</span></span><span style="display:flex;"><span>sleep 5; cat /dev/screen | topng &gt; screen.png
</span></span></code></pre>


guid: https://mitjafelicijan.com/fix-plan9-bootloader.html
title: Fix bootloader not being written in Plan9
url: https://mitjafelicijan.com/fix-plan9-bootloader.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>If the bootloader is not being written to a disk when installing 9front on real
harware try clearing first sector of the disk with the following command.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>dd <span style="color:#00f">if</span>=/dev/zero of=/dev/sdX bs=512 count=1
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># If command above doesn&#39;t work try this one, wait couple of seconds and</span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># press delete key to stop the command.</span>
</span></span><span style="display:flex;"><span>cat &lt;/dev/zero &gt;/dev/sd*/data
</span></span></code></pre>


guid: https://mitjafelicijan.com/install-plan9port-linux.html
title: Install Plan9port on Linux
url: https://mitjafelicijan.com/install-plan9port-linux.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Install Plan9port on Linux. This applies to
<a href="https://9fans.github.io/plan9port/">Plan9port</a>. This is a port of many Plan 9
programs to Unix-like operating systems. Useful for programs like <code>9term</code> and
<code>rc</code>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo apt-get install gcc libx11-dev libxt-dev libxext-dev libfontconfig1-dev
</span></span><span style="display:flex;"><span>git clone https://github.com/9fans/plan9port $HOME/plan9
</span></span><span style="display:flex;"><span>cd $HOME/plan9/plan9port
</span></span><span style="display:flex;"><span>./INSTALL -r $HOME/plan9
</span></span></code></pre>


guid: https://mitjafelicijan.com/download-youtube-videos.html
title: Download list of YouTube files
url: https://mitjafelicijan.com/download-youtube-videos.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>If you need to download a list of YouTube videos and don't want to download the
actual YouTube list (which <code>yt-dlp</code> supports), you can use the following method.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000">// Used to get list of raw URL&#39;s from YouTube&#39;s video tab&#39;.
</span></span></span><span style="display:flex;"><span><span style="color:#008000">// Copy them into videos.txt.
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span>document.querySelectorAll(<span style="color:#a31515">&#39;#contents a.ytd-thumbnail.style-scope.ytd-thumbnail&#39;</span>).forEach(el =&gt; console.log(el.href))
</span></span></code></pre><p>Download and install <a href="https://github.com/yt-dlp/yt-dlp">https://github.com/yt-dlp/yt-dlp</a>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># This will download all videos in videos.txt.</span>
</span></span><span style="display:flex;"><span>yt-dlp --batch-file videos.txt -N <span style="color:#a31515">`</span>nproc<span style="color:#a31515">`</span> -f webm
</span></span></code></pre>


guid: https://mitjafelicijan.com/convert-mkv.html
title: Convert all MKV files into other formats
url: https://mitjafelicijan.com/convert-mkv.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>You will need <code>ffmpeg</code> installed on your system. This will convert all MKV files
into WebM format.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># Convert all MKV files into WebM format.</span>
</span></span><span style="display:flex;"><span>find ./ -name <span style="color:#a31515">&#39;*.mkv&#39;</span> -exec bash -c <span style="color:#a31515">&#39;ffmpeg -i &#34;$0&#34; -vcodec libvpx -acodec libvorbis -cpu-used 5 -threads 8 &#34;${0%%.mp4}.webm&#34;&#39;</span> {} <span style="color:#a31515">\;</span>
</span></span></code></pre><pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># Convert all MKV files into MP4 format.</span>
</span></span><span style="display:flex;"><span>find ./ -name <span style="color:#a31515">&#39;*.mkv&#39;</span> -exec bash -c <span style="color:#a31515">&#39;ffmpeg -i &#34;$0&#34; c:a copy -c:v copy -cpu-used 5 -threads 8 &#34;${0%%.mp4}.mp4&#34;&#39;</span> {} <span style="color:#a31515">\;</span>
</span></span></code></pre>


guid: https://mitjafelicijan.com/preview-troff-man-pages.html
title: Previews how man page written in Troff will look like
url: https://mitjafelicijan.com/preview-troff-man-pages.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Troff is used to write man pages and it is difficult to read it so this will
preview how it will look like when it is rendered.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># On Linux system.</span>
</span></span><span style="display:flex;"><span>groff -man -Tascii filename
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># On Plan9 system.</span>
</span></span><span style="display:flex;"><span>man 1 filename
</span></span></code></pre>


guid: https://mitjafelicijan.com/rekindling-my-love-for-programming.html
title: Rekindling my love for programming and enjoying the act of creating
url: https://mitjafelicijan.com/rekindling-my-love-for-programming.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Programming can be a challenging and rewarding experience, but sometimes it's
easy to feel burnt out or disinterested. I have lost the passion for coding over
the past couple of months and it looked like I will never enjoy the coding as
much as I did.</p>
<p>I was feeling burnt out with programming. I thought taking a break from it and
focusing on other activities that I enjoy might be helpful. This way, I could
come back to programming with a fresh perspective and renewed energy.  I also
thought about learning a new programming language or technology to keep things
interesting and challenging.</p>
<p>However, what I didn't realize was that learning a new language or technology
wasn't going to solve the underlying issue. I needed to take a step back and
re-evaluate why I had lost my passion for programming in the first place.  This
involved taking a deep look into what I was doing that resulted in this rut.</p>
<p>Sometimes, it's easy to get caught up in the hype of new technologies or
languages, and we can feel like we're missing out if we're not constantly
learning and experimenting. However, it's important to remember that the latest
and greatest isn't always the best fit for our projects or our
interests. Instead of constantly chasing the next big thing, it can be helpful
to focus on what truly interests us and what we're passionate about. This can
help us stay motivated and engaged with our work, rather than feeling like we're
just going through the motions.</p>
<p>I expressed that I had lost my passion for coding over the past couple of
months, and I realized that the reason behind it was my tendency to spread
myself too thin and not focus on completing interesting projects. In order to
regain my passion for coding, I need to focus on projects that truly interest me
and give me a sense of purpose and motivation.</p>
<p>Recently, I have been playing World of Warcraft more frequently and have become
interested in developing addons for the game.</p>
<p>This quickly resulted in me creating three addons that improve the quality of
life, and I subsequently developed a more useful add-on that encapsulates all
the others I made.</p>
<p>I found it interesting that this action sparked a new interest in me.
Additionally, I discovered the Lua language, which reminded me that coding
should be fun rather than just a struggle with a language. It should be pure,
unadulterated fun.</p>
<p>I wasn't fighting the syntax, nor was I focused on finding the most optimal
solution. I simply created things without the pressure of making them the best
they could possibly be.</p>
<p>This made me realize that I actually adore simple languages that get out of the
way and let you express what you want to do. It forced me to rethink a lot about
what I use and what I actually enjoy.</p>
<p>I have decided to stick to the basics. For a scripting language, I will use
Lua. For networking, I will use Golang. And for any special needs, I will rely
on C. I do not require Rust, Nim, or Zig. This selection is more than sufficient
for my needs. I have to stay true to this simplicity. There is something to the
Occam's Razor.</p>
<p>I've been struggling with a lack of creativity lately, but now I'm experiencing
a real change. I realized I needed to take a step back and stop actively trying
to address the issue. I needed to stop worrying and overthinking it. I simply
needed some time. Looking back, I don't think I've taken any significant time
off in the last 10 years.</p>
<p>Suddenly, I find myself with the energy and passion to complete multiple small
projects. It doesn't feel like a chore at all. Who knew I needed WoW to
kickstart everything. Inspiration really does come from the strangest places.</p>


guid: https://mitjafelicijan.com/mass-set-permission.html
title: Change permissions of matching files recursively
url: https://mitjafelicijan.com/mass-set-permission.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Replace <code>*.xml</code> with your pattern. This will remove executable bit from all
files matching the pattern. Change <code>+</code> to <code>-</code> to add executable bit.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>find . -type f -name <span style="color:#a31515">&#34;*.xml&#34;</span> -exec chmod -x {} +
</span></span></code></pre>


guid: https://mitjafelicijan.com/non-blocking-shell-exec-csharp.html
title: Execute not blocking async shell command in C#
url: https://mitjafelicijan.com/non-blocking-shell-exec-csharp.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Execute a shell command in async in C# while not blocking the UI thread.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">private</span> <span style="color:#00f">async</span> Task executeCopyCommand()
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#00f">await</span> Task.Run(() =&gt;
</span></span><span style="display:flex;"><span>  {
</span></span><span style="display:flex;"><span>    <span style="color:#2b91af">var</span> processStartInfo = <span style="color:#00f">new</span> ProcessStartInfo(<span style="color:#a31515">&#34;cmd&#34;</span>, <span style="color:#a31515">&#34;/c dir&#34;</span>)
</span></span><span style="display:flex;"><span>    {
</span></span><span style="display:flex;"><span>      RedirectStandardOutput = <span style="color:#00f">true</span>,
</span></span><span style="display:flex;"><span>      UseShellExecute = <span style="color:#00f">false</span>,
</span></span><span style="display:flex;"><span>      CreateNoWindow = <span style="color:#00f">true</span>
</span></span><span style="display:flex;"><span>    };
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#2b91af">var</span> process = <span style="color:#00f">new</span> Process
</span></span><span style="display:flex;"><span>    {
</span></span><span style="display:flex;"><span>      StartInfo = processStartInfo
</span></span><span style="display:flex;"><span>    };
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    process.Start();
</span></span><span style="display:flex;"><span>    process.WaitForExit();
</span></span><span style="display:flex;"><span>  });
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>Make sure that <code>async</code> is present in the function definition and <code>await</code> is used
in the method that calls <code>executeCopyCommand()</code>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">private</span> <span style="color:#00f">async</span> <span style="color:#00f">void</span> button_Click(<span style="color:#2b91af">object</span> sender, EventArgs e)
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#00f">await</span> executeCopyCommand();
</span></span><span style="display:flex;"><span>}
</span></span></code></pre>


guid: https://mitjafelicijan.com/i-was-wrong-about-git-workflows.html
title: I think I was completely wrong about Git workflows
url: https://mitjafelicijan.com/i-was-wrong-about-git-workflows.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I have been using some approximation of <a href="https://jeffkreeftmeijer.com/git-flow/">Git
Flow</a> for years now and never really
questioned it to be honest. When I create a repo I create develop branch and set
it as default one and then merge to master from there. Seems reasonable enough.</p>
<p>One thing that I have learned is that long living branches are the devil.  They
always end up making a huge mess when they need to be merged eventually into
master. So by that reason, what is the develop branch if not the longest living
feature branch. And from my personal experience there was never a situation
where I wasn’t sweating bullets when I had to merge develop back to master.</p>
<p>This realisation started to give me pause. So why the hell am I doing this, and
is there a better way. Well the solution was always there. And it comes in a
form of <a href="https://git-scm.com/book/en/v2/Git-Basics-Tagging">git tags</a>.</p>
<p>So what are git tags? Git tags are references to specific points in a Git
repository's history. They are used to mark important milestones, such as
releases or significant commits, making it easier to identify and access
specific versions of a project.</p>
<p>Somehow we have all hijacked the meaning of the master branch that it has to be
the most releasable version of code. And this is also where the confusing about
versioning the software kicks in. Because master branch implicitly says that we
are dealing with the rolling release type of a software. And by having a develop
branch we are hacking around this confusion. With a separation of develop and
master we lock functionalities into place and forcing a stable vs development
version of the software.</p>
<p>But if that is true and the long living branches are the devil then why have
develop at all. I think that most of this comes to how continuous integration is
being done. There usually is no granular access to tags and CD software deploys
what is present on a specific branch, may that be master for production and
develop for staging. This is a gross simplification and by having this in place
we have completely removed tagging as a viable option to create a fix point in
software cycle that says, this is the production ready code.</p>
<p>One cool thing about tags are that you can checkout a specific tag. So they
behave very similarly as branches in that regard. And you don’t have the
overhead of having two mainstream branches.</p>
<p>So what is the solution? One approach is to use development workflow, where all
changes are made on the smaller branches and continuously merged into
master. Where the software is ready to be pushed to production you tag the
master branch. This approach eliminates the need for long-lived branches and
simplifies the development process. It also encourages developers to make small,
incremental changes that can be tested and deployed quickly. However, this
approach may not be suitable for all projects or teams that heavily rely on
automated deployment based on branch names only.</p>
<p>This also requires that developers always keep production in mind. No more
living on an island of the develop branch. All your actions and code need to be
ready to meet production standards on a much smaller timescale.</p>
<p>I think that we have complicated the workflow in an honest attempt to make
things more streamlined but in the process of doing this, we have inadvertently
made our lives much more complicated.</p>
<p>In conclusion, it's important to re-evaluate our workflows from time to time to
see if they still make sense and if there are better alternatives available.
Long-living branches can be problematic, and using tags to mark important
milestones can simplify the development process.</p>


guid: https://mitjafelicijan.com/extend-lua-with-custom-c.html
title: Extend Lua with custom C functions using Clang
url: https://mitjafelicijan.com/extend-lua-with-custom-c.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Here is a boilerplate for extending Lua with custom C functions. This requires
Clang and Lua 5.1 to be installed. GCC can be used instead of Clang, but the
Makefile will need to be modified.</p>
<ul>
<li>
<p>nativefunc.c</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">#include</span> <span style="color:#00f">&lt;lua.h&gt;</span><span style="color:#00f">
</span></span></span><span style="display:flex;"><span><span style="color:#00f">#include</span> <span style="color:#00f">&lt;lauxlib.h&gt;</span><span style="color:#00f">
</span></span></span><span style="display:flex;"><span><span style="color:#00f"></span>
</span></span><span style="display:flex;"><span><span style="color:#00f">static</span> <span style="color:#2b91af">int</span> l_mult50(lua_State *L) {
</span></span><span style="display:flex;"><span>  <span style="color:#2b91af">double</span> number = luaL_checknumber(L, 1);
</span></span><span style="display:flex;"><span>  lua_pushnumber(L, number * 50);
</span></span><span style="display:flex;"><span>  <span style="color:#00f">return</span> 1;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#2b91af">int</span> luaopen_nativefunc(lua_State *L) {
</span></span><span style="display:flex;"><span>  <span style="color:#00f">static</span> <span style="color:#00f">const</span> <span style="color:#00f">struct</span> luaL_Reg nativeFuncLib[] = { {<span style="color:#a31515">&#34;mult50&#34;</span>, l_mult50}, {NULL, NULL} };
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  luaL_register(L, <span style="color:#a31515">&#34;nativelib&#34;</span>, nativeFuncLib);
</span></span><span style="display:flex;"><span>  <span style="color:#00f">return</span> 1;
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></li>
<li>
<p>main.lua</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>require <span style="color:#a31515">&#34;nativefunc&#34;</span>
</span></span><span style="display:flex;"><span>print(nativelib.mult50(50))
</span></span></code></pre></li>
<li>
<p>Makefile</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>CC       = clang
</span></span><span style="display:flex;"><span>CFLAGS   =
</span></span><span style="display:flex;"><span>INCLUDES = <span style="color:#a31515">`</span>pkg-config lua5.1 --cflags-only-I<span style="color:#a31515">`</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>all:
</span></span><span style="display:flex;"><span>  <span style="color:#00f">$(</span>CC<span style="color:#00f">)</span> -shared -o nativefunc.so -fPIC nativefunc.c <span style="color:#00f">$(</span>CFLAGS<span style="color:#00f">)</span> <span style="color:#00f">$(</span>INCLUDES<span style="color:#00f">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>clean:
</span></span><span style="display:flex;"><span>  rm *.so
</span></span></code></pre></li>
</ul>


guid: https://mitjafelicijan.com/parse-rss-with-lua.html
title: Parse RSS feeds with Lua
url: https://mitjafelicijan.com/parse-rss-with-lua.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Example of parsing RSS feeds with Lua. Before running the script install:</p>
<ul>
<li>feedparser with <code>luarocks install feedparser</code></li>
<li>luasocket with <code>luarocks install luasocket</code></li>
</ul>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">local</span> http = require(<span style="color:#a31515">&#34;socket.http&#34;</span>)
</span></span><span style="display:flex;"><span><span style="color:#00f">local</span> feedparser = require(<span style="color:#a31515">&#34;feedparser&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">local</span> feed_url = <span style="color:#a31515">&#34;https://mitjafelicijan.com/index.xml&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">local</span> response, status, _ = http.request(feed_url)
</span></span><span style="display:flex;"><span><span style="color:#00f">if</span> status == 200 <span style="color:#00f">then</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">local</span> parsed = feedparser.parse(response)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#008000">-- Print out feed details.</span>
</span></span><span style="display:flex;"><span>  print(<span style="color:#a31515">&#34;&gt; Title   &#34;</span>, parsed.feed.title)
</span></span><span style="display:flex;"><span>  print(<span style="color:#a31515">&#34;&gt; Author  &#34;</span>, parsed.feed.author)
</span></span><span style="display:flex;"><span>  print(<span style="color:#a31515">&#34;&gt; ID      &#34;</span>, parsed.feed.id)
</span></span><span style="display:flex;"><span>  print(<span style="color:#a31515">&#34;&gt; Entries &#34;</span>, #parsed.entries)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">for</span> _, item <span style="color:#00f">in</span> ipairs(parsed.entries) <span style="color:#00f">do</span>
</span></span><span style="display:flex;"><span>    print(<span style="color:#a31515">&#34;GUID    &#34;</span>, item.guid)
</span></span><span style="display:flex;"><span>    print(<span style="color:#a31515">&#34;Title   &#34;</span>, item.title)
</span></span><span style="display:flex;"><span>    print(<span style="color:#a31515">&#34;Link    &#34;</span>, item.link)
</span></span><span style="display:flex;"><span>    print(<span style="color:#a31515">&#34;Summary &#34;</span>, item.summary)
</span></span><span style="display:flex;"><span>  <span style="color:#00f">end</span>
</span></span><span style="display:flex;"><span><span style="color:#00f">else</span>
</span></span><span style="display:flex;"><span>  print(<span style="color:#a31515">&#34;! Request failed. Status:&#34;</span>, status)
</span></span><span style="display:flex;"><span><span style="color:#00f">end</span>
</span></span></code></pre>


guid: https://mitjafelicijan.com/fresh-9front-desktop.html
title: My brand new Plan9/9front desktop
url: https://mitjafelicijan.com/fresh-9front-desktop.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I have been experimenting with Plan9/9front for a week now. Noice! This is how
my desktop looks like.</p>
<figure>
<img src="/assets/notes/9front-desktop.png" alt="9front desktop" />
</figure>


guid: https://mitjafelicijan.com/xterm-color-palette.html
title: Display xterm color palette
url: https://mitjafelicijan.com/xterm-color-palette.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<ul>
<li><code>bash xterm-palette.sh</code> - will show you number of max colors available</li>
<li><code>bash xterm-palette.sh -v</code> - will create a list of all colors with codes</li>
</ul>
<figure>
<img src="/assets/notes/xterm-palette.png" alt="xterm color palette" />
</figure>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">#!/usr/bin/env bash
</span></span></span><span style="display:flex;"><span><span style="color:#00f"></span><span style="color:#008000"># xterm-palette.sh</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>trap <span style="color:#a31515">&#39;tput sgr0&#39;</span> exit		<span style="color:#008000"># Clean up even if user hits ^C</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">function</span> setfg () {
</span></span><span style="display:flex;"><span>    printf <span style="color:#a31515">&#39;\e[38;5;%dm&#39;</span> $1
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">function</span> setbg () {
</span></span><span style="display:flex;"><span>    printf <span style="color:#a31515">&#39;\e[48;5;%dm&#39;</span> $1
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">function</span> showcolors() {
</span></span><span style="display:flex;"><span>    <span style="color:#008000"># Given an integer, display that many colors</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00f">for</span> ((i=0; i&lt;$1; i++))
</span></span><span style="display:flex;"><span>    <span style="color:#00f">do</span>
</span></span><span style="display:flex;"><span>	printf <span style="color:#a31515">&#39;%4d &#39;</span> $i
</span></span><span style="display:flex;"><span>	setbg $i
</span></span><span style="display:flex;"><span>	tput el
</span></span><span style="display:flex;"><span>	tput sgr0
</span></span><span style="display:flex;"><span>	echo
</span></span><span style="display:flex;"><span>    <span style="color:#00f">done</span>
</span></span><span style="display:flex;"><span>    tput sgr0 el
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># First, test if terminal supports OSC 4 at all.</span>
</span></span><span style="display:flex;"><span>printf <span style="color:#a31515">&#39;\e]4;%d;?\a&#39;</span> 0
</span></span><span style="display:flex;"><span>read -d <span style="color:#a31515">$&#39;\a&#39;</span> -s -t 0.1 &lt;/dev/tty
</span></span><span style="display:flex;"><span><span style="color:#00f">if</span> [ -z <span style="color:#a31515">&#34;</span>$REPLY<span style="color:#a31515">&#34;</span> ]
</span></span><span style="display:flex;"><span><span style="color:#00f">then</span>
</span></span><span style="display:flex;"><span>    <span style="color:#008000"># OSC 4 not supported, so we&#39;ll fall back to terminfo</span>
</span></span><span style="display:flex;"><span>    max=<span style="color:#00f">$(</span>tput colors<span style="color:#00f">)</span>
</span></span><span style="display:flex;"><span><span style="color:#00f">else</span>
</span></span><span style="display:flex;"><span>    <span style="color:#008000"># OSC 4 is supported, so use it for a binary search</span>
</span></span><span style="display:flex;"><span>    min=0
</span></span><span style="display:flex;"><span>    max=256
</span></span><span style="display:flex;"><span>    <span style="color:#00f">while</span> [[ <span style="color:#00f">$((</span>min+1<span style="color:#00f">))</span> -lt $max ]]
</span></span><span style="display:flex;"><span>    <span style="color:#00f">do</span>
</span></span><span style="display:flex;"><span>	i=<span style="color:#00f">$((</span> (min+max)/2 <span style="color:#00f">))</span>
</span></span><span style="display:flex;"><span>	printf <span style="color:#a31515">&#39;\e]4;%d;?\a&#39;</span> $i
</span></span><span style="display:flex;"><span>	read -d <span style="color:#a31515">$&#39;\a&#39;</span> -s -t 0.1 &lt;/dev/tty
</span></span><span style="display:flex;"><span>	<span style="color:#00f">if</span> [ -z <span style="color:#a31515">&#34;</span>$REPLY<span style="color:#a31515">&#34;</span> ]
</span></span><span style="display:flex;"><span>	<span style="color:#00f">then</span>
</span></span><span style="display:flex;"><span>            max=$i
</span></span><span style="display:flex;"><span>	<span style="color:#00f">else</span>
</span></span><span style="display:flex;"><span>	    min=$i
</span></span><span style="display:flex;"><span>	<span style="color:#00f">fi</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00f">done</span>
</span></span><span style="display:flex;"><span><span style="color:#00f">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># If -v is given, show all the colors</span>
</span></span><span style="display:flex;"><span><span style="color:#00f">case</span> <span style="color:#a31515">${</span>1-none<span style="color:#a31515">}</span> in
</span></span><span style="display:flex;"><span>    none)
</span></span><span style="display:flex;"><span>	echo $max
</span></span><span style="display:flex;"><span>	;;
</span></span><span style="display:flex;"><span>    -v)
</span></span><span style="display:flex;"><span>	showcolors $max
</span></span><span style="display:flex;"><span>	;;
</span></span><span style="display:flex;"><span>    *)
</span></span><span style="display:flex;"><span>	<span style="color:#00f">if</span> [[ <span style="color:#a31515">&#34;</span>$1<span style="color:#a31515">&#34;</span> -gt 0 ]]; <span style="color:#00f">then</span>
</span></span><span style="display:flex;"><span>	    showcolors $1
</span></span><span style="display:flex;"><span>	<span style="color:#00f">else</span>
</span></span><span style="display:flex;"><span>	    echo $max
</span></span><span style="display:flex;"><span>	<span style="color:#00f">fi</span>
</span></span><span style="display:flex;"><span>	;;
</span></span><span style="display:flex;"><span><span style="color:#00f">esac</span> | less --raw-control-chars --QUIT-AT-EOF --no-init
</span></span></code></pre>


guid: https://mitjafelicijan.com/tmux-sane-defaults.html
title: Sane defaults for tmux with more visible statusbar
url: https://mitjafelicijan.com/tmux-sane-defaults.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<pre><code class="language-conf"># Remap prefix from 'C-b' to 'M-a'.
unbind C-b
set-option -g prefix M-a
bind-key M-a send-prefix

# Split panes using | and -.
bind | split-window -h
bind - split-window -v
unbind '&quot;'
unbind %

# Start counting windows with 1.
set-option -g allow-rename on
set -g base-index 1
setw -g pane-base-index 1

# Statusbar: purple bg and white fg.
set -g status-bg '#480b8e'
set -g status-fg '#ffffff'

# Active window: black bg and white fg. 
set -g window-status-current-format &quot;#[fg=#ffffff]#[bg=#111111]#[fg=#ffffff]#[bg=#111111] #I:#W #[fg=#ffffff]#[bg=#111111]&quot;

# Disable mouse mode (tmux 2.1 and above).
set -g mouse off
</code></pre>


guid: https://mitjafelicijan.com/dcss-new-player-guide.html
title: Dungeon Crawl Stone Soup - New player guide
url: https://mitjafelicijan.com/dcss-new-player-guide.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>An amazing game deserves an amazing guide. All this material can be find in some
form on another on <a href="https://github.com/crawl/crawl">craw's</a> official repository.</p>
<ul>
<li><a href="/assets/notes/dcss-quickstart.pdf">DCSS Quickstart</a> - Very short introduction to the
game</li>
<li><a href="/assets/notes/dcss_manual.pdf">DCSS Manual</a> - Extensive manual about the game</li>
</ul>
<figure>
<img src="/assets/notes/dcss.jpg" alt="Dungeon Crawl Stone Soup" />
</figure>
<p><strong>Movement and Exploration</strong></p>
<ul>
<li>You can move around with the numpad (try numlock on and off), vi-keys, or
clicking with the mouse. Arrow keys work, though you can't move diagonally
with them. Pressing Shift and a direction will move until you see/hit
something.</li>
<li>Pressing <code>&gt;</code> will take you down a staircase, and <code>&lt;</code> to go up a staircase.</li>
<li>You can open doors by walking into them, and close them with <code>C</code>.</li>
<li>You can autoexplore by pressing <code>o</code>.</li>
<li>You can re-view recent messages with <code>Ctrl-p</code>.</li>
</ul>
<p><strong>Monsters and Combat</strong></p>
<ul>
<li>You can pick up items with <code>,</code> or <code>g</code>.</li>
<li>Wield weapons with <code>w</code>. Weapons have different stats.
<ul>
<li>(You may also engage in Unarmed Combat, though it isn't very effective when
untrained).</li>
</ul>
</li>
<li>Attack monsters in melee by walking in their direction (or with
Ctrl-direction).</li>
<li>You can wait with <code>.</code> or <code>s</code>, passing your turn - such as to get monsters into
a corridor with you.</li>
<li>You can rest with <code>5</code>, waiting until you are fully healed, or something
noteworthy happens.</li>
<li>Either mouseover and rightclick, or use <code>x</code> then <code>v</code> on the monster to examine
monsters. Monsters with a red border are 'dangerous' relative to your current
XP level (XL).</li>
<li>Quiver (often ranged) actions for further use with <code>Q</code>.</li>
<li>You can fire ranged weapons manually with <code>f</code>, or auto-target your quiver with
<code>p</code> or <code>Shift-Tab</code>. Throwing weapons can be thrown immediately, while
launchers (like bows) need to be wielded first.</li>
</ul>
<p><strong>Items and Inventory</strong></p>
<ul>
<li>View your inventory by pressing <code>i</code>. Most item related commands can also be
done with this menu.</li>
<li>You can wear amour with <code>W;</code> amour gives <code>AC</code>, while heavier body armour
reduces <code>EV</code>.</li>
<li>Autoexplore will automatically pick up useful items, such as potions and
scrolls, if you aren't in danger.</li>
<li>You can read scrolls with <code>r</code> and drink (&quot;quaff&quot;) potions with <code>q</code>.</li>
<li>Equipment items may have brands, with special properties. Branded equipment is
blue when unidentified.</li>
<li>Equipment items may be artifacts, often with unique properties, and are
unmodifiable. They are written in white.</li>
<li>You can evoke wands with <code>V</code>.</li>
<li>You can put on jewelry with <code>P</code>, and remove it with <code>R</code>.</li>
<li>Gold is used in shops, which can be interacted with by either <code>&gt;</code> or <code>&lt;</code>.</li>
</ul>
<p><strong>Magic and Spellcasting</strong></p>
<ul>
<li>Once you find a spellbook, you can memorize spells with <code>M</code>.</li>
<li>You need to be the same XL as the spell's spell level in order to learn it, in
addition to training magical skill (to lower failure rate).</li>
<li>Cast spells by pressing <code>z</code>, then the letter assigned to the spell. You may
also Quiver a spell and then use it like a ranged weapon (with Shift-Tab).</li>
<li>You can view your memorized spells by pressing <code>I</code> (capital-i) or <code>z</code>.</li>
<li>Like HP, you can recover MP by resting (with 5).</li>
<li>Many spells can be positioned more effectively, or combined with other spells,
in order to get (more effective) use out of them.</li>
<li>Heavier body amour and shields hamper spellcasting.</li>
</ul>
<p><strong>Gods and Divine Abilities</strong></p>
<ul>
<li>You may look at a god's overview by praying at their altar (with <code>&gt;</code> or <code>&lt;</code>).
After praying, you can worship the god by pressing Enter afterwards.</li>
<li>Gods all have unique features about them. Trog, the god of the tutorial, is
also the god of rage and bloodshed, and so despises spellcasting.</li>
<li>Gods like and dislike different things. Most gods either like killing things
(like Trog) or exploring new areas (like Elyvilon), rewarding you piety
(divine favor) for doing so.</li>
<li>You should learn to use and even rely on divine abilities often, as they are
usually very strong. Trog's Berserk gives you 1.5x health, 1.5x speed (to all
valid actions), and a big damage boost. Note that Berserk prevents most
actions other than move and melee attack, and runs out very quickly if you
aren't attacking. And after berserk ends, you are slowed down and can't
berserk again for a short time.</li>
<li>In addition, the vast majority of abilities consume piety in the process.
Regardless, this ability is very cheap, and the benefits are incredible, so
don't hold back!</li>
<li>Pressing <code>^</code> will let you view your current god, abilities, and piety.</li>
</ul>


guid: https://mitjafelicijan.com/cronjobs-github-with-actions.html
title: Cronjobs on Github with Github Actions
url: https://mitjafelicijan.com/cronjobs-github-with-actions.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>In the root of your repository create a folder <code>.github/workflows</code> and in that
folder create a file a file <code>cron.yaml</code>. This file can be named whatever you
wish. But it has to be a <code>yaml</code> file.</p>
<p>File below (<code>.github/workflows/cron.yaml</code>) describes an action that will trigger
every six hours and it will curl example.com.</p>
<p>However. Be sure that you have enough credits. Free account is not that generous
with the minutes they give you for free. Check more about GitHub Actions usage
on their website <a href="https://docs.github.com/en/actions">https://docs.github.com/en/actions</a>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># .github/workflows/cron.yaml</span>
</span></span><span style="display:flex;"><span>name: Do a curl every 6 hours
</span></span><span style="display:flex;"><span>on:
</span></span><span style="display:flex;"><span>  schedule:
</span></span><span style="display:flex;"><span>    - cron: <span style="color:#a31515">&#39;0 */6 * * *&#39;</span>
</span></span><span style="display:flex;"><span>jobs:
</span></span><span style="display:flex;"><span>  cron:
</span></span><span style="display:flex;"><span>    runs-on: ubuntu-latest
</span></span><span style="display:flex;"><span>    steps:
</span></span><span style="display:flex;"><span>      - name: Call some url
</span></span><span style="display:flex;"><span>        run: curl &#39;https://example.com&#39;
</span></span></code></pre>


guid: https://mitjafelicijan.com/drawing-pixels-in-plan9.html
title: Drawing Pixels in Plan9
url: https://mitjafelicijan.com/drawing-pixels-in-plan9.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I have started exploring Plan9's graphics capabilities. This is a hello world
alternative for drawing that draws a yellow square on a blue background.</p>
<p>More information:</p>
<ul>
<li><a href="https://github.com/0intro/plan9/blob/main/sys/include/draw.h">draw.h header file</a>
contains all the drawing functions</li>
<li><a href="https://9fans.github.io/plan9port/man/man3/draw.html">draw man page</a>
has a bit more digestable descriptions of the draw functions</li>
<li><a href="https://9fans.github.io/plan9port/man/man3/graphics.html">graphics man page</a>
has a bit more digestable descriptions of the graphics functions</li>
<li><a href="https://9fans.github.io/plan9port/man/man3/">all man pages</a>
can be a valuable resource for learning about the system</li>
</ul>
<figure>
<img src="/assets/notes/plan9-pixels.png" alt="Plan9 Howdy World!" />
</figure>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000">// main.c
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span><span style="color:#00f">#include</span> <span style="color:#00f">&lt;u.h&gt;</span><span style="color:#00f">
</span></span></span><span style="display:flex;"><span><span style="color:#00f">#include</span> <span style="color:#00f">&lt;libc.h&gt;</span><span style="color:#00f">
</span></span></span><span style="display:flex;"><span><span style="color:#00f">#include</span> <span style="color:#00f">&lt;draw.h&gt;</span><span style="color:#00f">
</span></span></span><span style="display:flex;"><span><span style="color:#00f">#include</span> <span style="color:#00f">&lt;cursor.h&gt;</span><span style="color:#00f">
</span></span></span><span style="display:flex;"><span><span style="color:#00f"></span>
</span></span><span style="display:flex;"><span><span style="color:#2b91af">void</span>
</span></span><span style="display:flex;"><span>main()
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  ulong co;
</span></span><span style="display:flex;"><span>  Image *im, *bg;
</span></span><span style="display:flex;"><span>  co = 0x0000FFFF;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">if</span> (initdraw(nil, nil, argv0) &lt; 0)
</span></span><span style="display:flex;"><span>  {
</span></span><span style="display:flex;"><span>    sysfatal(<span style="color:#a31515">&#34;%s: %r&#34;</span>, argv0);
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  im = allocimage(display, Rect(0, 0, 300, 300), RGB24, 0, DYellow);
</span></span><span style="display:flex;"><span>  bg = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, co);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">if</span> (im == nil || bg == nil)
</span></span><span style="display:flex;"><span>  {
</span></span><span style="display:flex;"><span>    sysfatal(<span style="color:#a31515">&#34;not enough memory&#34;</span>);
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  draw(screen, screen-&gt;r, bg, nil, ZP);
</span></span><span style="display:flex;"><span>  draw(screen, screen-&gt;r, im, nil, Pt(-40, -40));
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  flushimage(display, Refnone);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#008000">// Wait 10 seconds before exiting.
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span>  sleep(10000);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  exits(nil);
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>And then compile with <code>mk</code> (mkfile below):</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># mkfile
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span><span style="">&lt;/$objtype/mkfile</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>RC=/rc/bin
</span></span><span style="display:flex;"><span>BIN=/$objtype/bin
</span></span><span style="display:flex;"><span>MAN=/sys/man
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>main:
</span></span><span style="display:flex;"><span>	$CC $CFLAGS main.c
</span></span><span style="display:flex;"><span>	$LD $LDFLAGS -o main main.$O
</span></span></code></pre><p>And run with <code>./main</code>. To exit the program, press <code>Delete key</code> (strange but this
is the alternative for Ctrl+C).</p>
<p><em>This is <strong>very cool</strong> indeed!</em></p>


guid: https://mitjafelicijan.com/dcss-on-4k-display.html
title: Make DCSS playable on 4k displays
url: https://mitjafelicijan.com/dcss-on-4k-display.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Dungeon Crawl Stone Soup has a a very small font by default. On a 4k display, it
is barely readable. This is how I made it playable.</p>
<p>Make a file <code>~/.crawlrc</code> with the following content:</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># Adjust the sizes to your liking.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>tile_font_crt_size = <span style="color:#a31515">32</span>
</span></span><span style="display:flex;"><span>tile_font_stat_size = <span style="color:#a31515">32</span>
</span></span><span style="display:flex;"><span>tile_font_msg_size = <span style="color:#a31515">32</span>
</span></span><span style="display:flex;"><span>tile_font_tip_size = <span style="color:#a31515">32</span>
</span></span><span style="display:flex;"><span>tile_font_lbl_size = <span style="color:#a31515">32</span>
</span></span><span style="display:flex;"><span>tile_sidebar_pixels = <span style="color:#a31515">64</span>
</span></span></code></pre><p>To zoom in and out in viewport, press <code>Ctrl+</code> and <code>Ctrl-</code> respectively.</p>
<p>All the possible options are documented in the <a href="https://github.com/crawl/crawl/blob/master/crawl-ref/docs/options_guide.txt">Dungeon Crawl Stone Soup Options
Guide</a>
file.</p>


guid: https://mitjafelicijan.com/easy-time-took-in-bash.html
title: Easy measure time took in a bash script
url: https://mitjafelicijan.com/easy-time-took-in-bash.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>In Bash, the <code>$SECONDS</code> variable is a special variable that automatically keeps
track of the number of seconds since the current shell or script started
executing. It starts counting from the moment the script begins running.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#00f"></span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Reset the timer to zero.</span>
</span></span><span style="display:flex;"><span>SECONDS=0
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Do something.</span>
</span></span><span style="display:flex;"><span>sleep 5
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Print the time elapsed.</span>
</span></span><span style="display:flex;"><span>echo <span style="color:#a31515">&#34;Time taken: </span>$SECONDS<span style="color:#a31515"> seconds&#34;</span>
</span></span></code></pre>


guid: https://mitjafelicijan.com/grep-to-less-maintain-colors.html
title: Grep to Less that maintain colors
url: https://mitjafelicijan.com/grep-to-less-maintain-colors.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I often use <code>grep</code> to search for todo's in my code and other people's code and
then pipe them in <code>less</code> and I missed having colors that grep outputs in <code>less</code>.</p>
<ul>
<li>Grep's <code>--color=always</code> use markers to highlight the matching strings.</li>
<li>Less's <code>-R</code> option outputs &quot;raw&quot; control characters.</li>
</ul>
<p>You could use <code>alias grep='grep --color=always'</code> and <code>alias less='less -R'</code> or
create todo function in your <code>.bashrc</code> that accepts first argument as search
string.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># This is where the magic happens.</span>
</span></span><span style="display:flex;"><span>grep --color=always -rni <span style="color:#a31515">&#34;TODO:&#34;</span> | less -R
</span></span></code></pre><figure>
<img src="/assets/notes/grep-less.png" alt="Less and grep" />
</figure>


guid: https://mitjafelicijan.com/extending-dte-editor.html
title: Extending dte editor
url: https://mitjafelicijan.com/extending-dte-editor.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p><a href="https://craigbarnes.gitlab.io/dte/"><code>dte</code></a> is an interesting editor I started
using lately more and more. Since it is using
<a href="https://linux.die.net/man/3/execvp"><code>execvp()</code></a> it can be easily extended. I
needed comment/uncomment feature so I created a small utility that does this for
me. Code lives on repository <a href="https://git.mitjafelicijan.com/dte-extensions.git/about/">dte
extensions</a> but this
utilities can be used for whatever you want. Make sure you have version 1.11 or
above.</p>
<p>Next one will be invoking formatter based on the type of a file.</p>
<p>My config that works for me.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>set show-line-numbers true;
</span></span><span style="display:flex;"><span>set tab-width 4;
</span></span><span style="display:flex;"><span>set <span style="color:#00f">case</span>-sensitive-search false;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Special aliases</span>
</span></span><span style="display:flex;"><span>alias m_comment <span style="color:#a31515">&#39;exec -s -i line -o buffer -e errmsg ~/.dte/bin/comment&#39;</span>
</span></span><span style="display:flex;"><span>alias m_format <span style="color:#a31515">&#39;save; exec go fmt .; reload&#39;</span>
</span></span><span style="display:flex;"><span>alias m_duplicate <span style="color:#a31515">&#39;copy;paste&#39;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Useful aliases.</span>
</span></span><span style="display:flex;"><span>alias m_force_close <span style="color:#a31515">&#39;quit -f&#39;</span>;
</span></span><span style="display:flex;"><span>alias m_reload <span style="color:#a31515">&#39;close; open $FILE&#39;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Key bindings.</span>
</span></span><span style="display:flex;"><span>bind M-s save;
</span></span><span style="display:flex;"><span>bind M-q m_force_close;
</span></span><span style="display:flex;"><span>bind M-z refresh;
</span></span><span style="display:flex;"><span>bind C-down blkdown;
</span></span><span style="display:flex;"><span>bind C-up blkup;
</span></span><span style="display:flex;"><span>bind C-_ m_comment;
</span></span><span style="display:flex;"><span>bind M-. m_format;
</span></span><span style="display:flex;"><span>bind C-d m_duplicate;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Syntax highlighting.</span>
</span></span><span style="display:flex;"><span>hi preproc magenta;
</span></span><span style="display:flex;"><span>hi keyword red;
</span></span><span style="display:flex;"><span>hi linenumber blue;
</span></span><span style="display:flex;"><span>hi comment cyan;
</span></span></code></pre>


guid: https://mitjafelicijan.com/re-inventing-task-runner-that-i-actually-used-daily.html
title: Re-Inventing Task Runner That I Actually Used Daily
url: https://mitjafelicijan.com/re-inventing-task-runner-that-i-actually-used-daily.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Couple of months ago I had this brilliant idea of re-inventing the wheel by
making an alternative for make. And so I went. Boldly into the battle. And to my
big surprise my attempt resulted in not a completely useless piece of software.</p>
<p>My initial requirements were quite simple but soon grow into something more
ambitious. And looking back I should have stuck to the simple version. My
laziness was on my side this time though. Because I haven’t implemented some of
the features I now realise I really didn’t need them and they would bog the
whole program and make it be something it was never meant to be.</p>
<p>My basic requirements were following:</p>
<ul>
<li>Syntax should be a tiny bit inspired by Rake and Rakefiles.</li>
<li>Should borrow the overall feel of a unit test experience.</li>
<li>Using something like Python would be a bit of an overkill.</li>
<li>The program must be statically compiled, so it can run on same architecture
without libc, musl dependencies or things like that.</li>
<li>Install ruby for rake is a bit overkill and can not be done with certain
really lightweight distributions like Alpine Linux. This tool would be usable
on such lightweight systems for remote debugging.</li>
<li>I want to use it for more than just compiling things. I want to use it as an
entry-point into a project, and I want this to help me indirectly document the
project as well.</li>
<li>It should be an abstraction over bash shell or the default system shell.
<ul>
<li>Each task essentially becomes its own shell instance.</li>
</ul>
</li>
<li>Must work on Linux and macOS systems.</li>
<li>By default, running <code>erd</code> list all the available tasks (when I use make, I
usually put a disclaimer that you should check Makefile to see all available
target).</li>
<li>Should support passing arguments when you run it from a shell.</li>
<li>Normal variable as the same as environmental variables. There is no
distinction. Every variable is also essentially an environment variable and
can be used by other programs.</li>
<li>State between tasks is not shared, and this makes this “pure” shell instances.</li>
<li>Should be single-threaded for the start and later expanded with <code>@spawn</code>
command.</li>
<li>Variables behave like macros and are preprocessed before evaluation.</li>
<li>Should support something like <code>assure</code> that would check if programs like C
compiler or Python (whatever the project requires) are installed on a machine.</li>
</ul>
<p>Quite a reasonable list of requirements. I do this things already in my
Makefiles or/and Bash scripts. But I would like to avoid repeating myself every
time I start working on something new.</p>
<p>So I started with the following syntax.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>@env on
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Override the default shell.</span>
</span></span><span style="display:flex;"><span>@shell <span style="color:#a31515">/bin/</span>bash
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Assure that program is installed.</span>
</span></span><span style="display:flex;"><span>@assure docker-compose pip python3
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Load local dotenv files (these are then globally available).</span>
</span></span><span style="display:flex;"><span>@dotenv .env
</span></span><span style="display:flex;"><span>@dotenv .env.sample
</span></span><span style="display:flex;"><span>@dotenv some_other_file
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># This are local variables but still accessible in tasks.</span>
</span></span><span style="display:flex;"><span>@var HI = <span style="color:#a31515">&#34;hey&#34;</span>
</span></span><span style="display:flex;"><span>@var TOKEN = <span style="color:#a31515">&#34;sometoken&#34;</span>
</span></span><span style="display:flex;"><span>@var EMAIL = <span style="color:#a31515">&#34;m@m.com&#34;</span>
</span></span><span style="display:flex;"><span>@var PASSWORD = <span style="color:#a31515">&#34;pass&#34;</span>
</span></span><span style="display:flex;"><span>@var EDITOR = <span style="color:#a31515">&#34;vim&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>@task dev <span style="color:#a31515">&#34;Test chars .:&#39;}{]!//&#34;</span> does
</span></span><span style="display:flex;"><span>  echo <span style="color:#a31515">&#34;...&#34;</span> $HI
</span></span><span style="display:flex;"><span><span style="color:#00f">end</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>@task clean <span style="color:#a31515">&#34;Cleans the obj files&#34;</span> does
</span></span><span style="display:flex;"><span>  rm .obj
</span></span><span style="display:flex;"><span><span style="color:#00f">end</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>@task greet <span style="color:#a31515">&#34;Greets the user&#34;</span> does
</span></span><span style="display:flex;"><span>  echo <span style="color:#a31515">&#34;Hi user $TOKEN or $WINDOWID $EMAIL&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#00f">end</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>@task stack <span style="color:#a31515">&#34;Starts Docker stack&#34;</span> does
</span></span><span style="display:flex;"><span>  docker-compose -f stack.yml up
</span></span><span style="display:flex;"><span><span style="color:#00f">end</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>@task todo <span style="color:#a31515">&#34;Shows all todos in source files and count them&#34;</span> does
</span></span><span style="display:flex;"><span>  grep -ir <span style="color:#a31515">&#34;TODO|FIXME&#34;</span> . | wc -l
</span></span><span style="display:flex;"><span><span style="color:#00f">end</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>@task test1 <span style="color:#a31515">&#34;For testing 1&#34;</span> does
</span></span><span style="display:flex;"><span>  unknown-command
</span></span><span style="display:flex;"><span>  echo <span style="color:#a31515">&#34;test1&#34;</span>
</span></span><span style="display:flex;"><span>  ls -lha
</span></span><span style="display:flex;"><span><span style="color:#00f">end</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>@task test2 <span style="color:#a31515">&#34;For testing 2&#34;</span> does
</span></span><span style="display:flex;"><span>  echo <span style="color:#a31515">&#34;test1&#34;</span>
</span></span><span style="display:flex;"><span>  ls -lha
</span></span><span style="display:flex;"><span>  docker-compose -f samples/stack.yml up
</span></span><span style="display:flex;"><span><span style="color:#00f">end</span>
</span></span></code></pre><p>One thing that I really like about Errand. Yes, this is what it is called. And
it is available at <a href="https://git.mitjafelicijan.com/errand.git/about/">https://git.mitjafelicijan.com/errand.git/about/</a>. Moving
on. One thing that I really like is that a task is a persistent shell. By that I
mean, that the whole task, even if it contains multiple command in one shell.
In make each line in a target is that and you need to combine lines or add <code>\</code>
at the end of the line.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># How you do this things in make.</span>
</span></span><span style="display:flex;"><span>target:
</span></span><span style="display:flex;"><span>	source .venv/bin/activate <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>	python script.py
</span></span></code></pre><p>This solves this problem. Consider each task and what is being executed in that
task a shell that will only close when all the tasks are completed.</p>
<p>By self-documenting I mean that if you are in a directory with <code>Errandfile</code> in,
if you only type <code>erd</code> and press enter it should by default display all the
possible targets. In make i was doing this by having a first target be something
like <code>default</code> that echos the message “Check Makefile for all available target.”
Because all of the tasks in Errand require a message I use that to display let’s
call it table of contents.</p>
<p>Because I don’t use any external dependencies this whole thing can be statically
compiled. So that also checked one of the boxes.</p>
<p>It works on Linux and on a Mac so that’s also a bonus. I don’t believe this
would work on Windows machines because of the way that I use shell instances. By
you could use something like Windows Subsystem for Linux and run it in
there. That is a valid option.</p>
<p>To finish this essay off, how was it to use it in “real life”. I have to be
honest. Some of the missing features still bother me. <code>@dotenv</code> directive is
still missing and I need to implement this ASAP.</p>
<p>Another thing that needs to happen is support for streaming output. Currently
commands like <code>docker-compose</code> that runs in foreground mode is not compatible
with Errand. So commands that stream output are an issue.  I need to revisit how
I initiate shell and how I read stdout and stderr.  But that shouldn’t be a
problem.</p>
<p>I have been very satisfied with this thing. I am pleasantly surprised by how
useful it is. I really wanted to test this in the wild before I commit to it. I
have more abandoned project than Google and it’s bringing a massive shame to my
family at this point. So I wanted to be sure that this is even useful. And it
actually is. Quite surprised at myself.</p>
<p>I really need to package this now and write proper docs. And maybe rewrite
tokeniser. Its atrocious right now. Site to behold! But that is an issue for
another time.</p>


guid: https://mitjafelicijan.com/ewd-manuscripts-ebook.html
title: Edsger W. Dijkstra Manuscripts ebook
url: https://mitjafelicijan.com/ewd-manuscripts-ebook.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I love reading the original manuscripts of Edsger W. Dijkstra. They are
available online at the University of Texas at Austin website, but I also found
MOBI version. I converted it into ePub as well.</p>
<p>Downloads:</p>
<ul>
<li><a href="/assets/posts/ewd/ewd-manuscripts.mobi">MOBI version of all Manuscripts</a></li>
<li><a href="/assets/posts/ewd/ewd-manuscripts.epub">ePub version of all Manuscripts</a></li>
</ul>
<p>Sources and credits:</p>
<ul>
<li><a href="https://www.cs.utexas.edu/users/EWD/index00xx.html">Original manuscripts from University of Texas at Austin</a></li>
<li><a href="https://github.com/evmn/The-Manuscripts-of-Edsger-W.-Dijkstra">Original repository of MOBI version</a></li>
</ul>


guid: https://mitjafelicijan.com/bulk-make-thumbnails.html
title: Bulk thumbnails
url: https://mitjafelicijan.com/bulk-make-thumbnails.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Make bulk thumbnails of JPGs with ImageMagick.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#00f"></span>
</span></span><span style="display:flex;"><span>directory=<span style="color:#a31515">&#34;./images/&#34;</span>
</span></span><span style="display:flex;"><span>dimensions=<span style="color:#a31515">&#34;360x360&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">for</span> file in <span style="color:#a31515">&#34;</span>$directory<span style="color:#a31515">&#34;</span>*.jpg; <span style="color:#00f">do</span>
</span></span><span style="display:flex;"><span>  convert <span style="color:#a31515">&#34;</span>$file<span style="color:#a31515">&#34;</span> -resize $dimensions <span style="color:#a31515">&#34;</span>$file<span style="color:#a31515">&#34;</span> <span style="color:#a31515">&#34;</span><span style="color:#a31515">${</span>file%.*<span style="color:#a31515">}</span><span style="color:#a31515">-thumbnail.jpg&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#00f">done</span>
</span></span></code></pre>


guid: https://mitjafelicijan.com/presentations-with-markdown.html
title: Simple presentations with Markdown
url: https://mitjafelicijan.com/presentations-with-markdown.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>A simple way to make presentations without using desktop apps or using online
services is <a href="https://github.com/remarkjs/remark">https://github.com/remarkjs/remark</a>.</p>
<p>First create <code>index.html</code> and be sure you make changes to <code>config</code> variable.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">&lt;!DOCTYPE html&gt;</span>
</span></span><span style="display:flex;"><span>&lt;html&gt;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>&lt;head&gt;
</span></span><span style="display:flex;"><span>    &lt;title&gt;&lt;/title&gt;
</span></span><span style="display:flex;"><span>    &lt;meta charset=<span style="color:#a31515">&#34;utf-8&#34;</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;style&gt;
</span></span><span style="display:flex;"><span>        body {
</span></span><span style="display:flex;"><span>            <span style="color:#00f">font-family</span>: <span style="color:#a31515">&#39;SF Pro Display&#39;</span>;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        .<span style="color:#2b91af">remark-code</span>,
</span></span><span style="display:flex;"><span>        .<span style="color:#2b91af">remark-inline-code</span> {
</span></span><span style="display:flex;"><span>            <span style="color:#00f">font-family</span>: <span style="color:#a31515">&#39;SF Mono&#39;</span>;
</span></span><span style="display:flex;"><span>            <span style="color:#00f">font-size</span>: <span style="color:#00f">medium</span>;
</span></span><span style="display:flex;"><span>            <span style="color:#00f">background-color</span>: <span style="color:#00f">gainsboro</span>;
</span></span><span style="display:flex;"><span>            <span style="color:#00f">border-radius</span>: 5<span style="color:#2b91af">px</span>;
</span></span><span style="display:flex;"><span>            <span style="color:#00f">padding</span>: 0 5<span style="color:#2b91af">px</span>;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>    &lt;/style&gt;
</span></span><span style="display:flex;"><span>&lt;/head&gt;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>&lt;body&gt;
</span></span><span style="display:flex;"><span>    &lt;textarea id=<span style="color:#a31515">&#34;source&#34;</span>&gt;&lt;/textarea&gt;
</span></span><span style="display:flex;"><span>    &lt;script src=<span style="color:#a31515">&#34;https://remarkjs.com/downloads/remark-latest.min.js&#34;</span>&gt;&lt;/script&gt;
</span></span><span style="display:flex;"><span>    &lt;script&gt;
</span></span><span style="display:flex;"><span>		<span style="color:#00f">const</span> config = {
</span></span><span style="display:flex;"><span>			title: <span style="color:#a31515">&#39;My presentation&#39;</span>,
</span></span><span style="display:flex;"><span>			file: <span style="color:#a31515">&#39;presentation.md&#39;</span>,
</span></span><span style="display:flex;"><span>		};
</span></span><span style="display:flex;"><span>	
</span></span><span style="display:flex;"><span>		document.title = config.title;
</span></span><span style="display:flex;"><span>        remark.create({ sourceUrl: config.file });
</span></span><span style="display:flex;"><span>    &lt;/script&gt;
</span></span><span style="display:flex;"><span>&lt;/body&gt;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>&lt;/html&gt;
</span></span></code></pre><p>Now the markdown file <code>presentation.md</code> with presenetation. <code>---</code> is used to
separate slides. Other stuff is just pure markdown.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>class: center, middle
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="font-weight:bold"># Main title of the presentation
</span></span></span><span style="display:flex;"><span><span style="font-weight:bold"></span>
</span></span><span style="display:flex;"><span>---
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="font-weight:bold"># Fist slide
</span></span></span><span style="display:flex;"><span><span style="font-weight:bold"></span>
</span></span><span style="display:flex;"><span>Eveniet mollitia nemo architecto rerum aut iure iste. Sit nihil nobis libero iusto fugit nam laudantium ut. Dignissimos corrupti laudantium nisi.
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">-</span> Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</span></span><span style="display:flex;"><span><span style="color:#00f">-</span> Integer aliquet mauris a felis fringilla, ut congue massa finibus.
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>---
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="font-weight:bold"># Slide two
</span></span></span><span style="display:flex;"><span><span style="font-weight:bold"></span>
</span></span><span style="display:flex;"><span><span style="color:#00f">-</span> Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</span></span><span style="display:flex;"><span><span style="color:#00f">-</span> Vestibulum eget leo ac dolor venenatis pulvinar.
</span></span></code></pre>


guid: https://mitjafelicijan.com/making-cgit-look-nicer.html
title: Making cgit look nicer
url: https://mitjafelicijan.com/making-cgit-look-nicer.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>For personal use I have a <a href="https://git.mitjafelicijan.com">private Git server</a>
set up and I use GitHub just as a mirror. By default the cgit theme looks a bit
dated so I made the flowing theme.</p>
<ul>
<li><code>/etc/cgitrc</code></li>
</ul>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>css=<span style="color:#a31515">/cgit.css</span>
</span></span><span style="display:flex;"><span>logo=<span style="color:#a31515">/startrek.gif</span>
</span></span><span style="display:flex;"><span>favicon=<span style="color:#a31515">/favicon.png</span>
</span></span><span style="display:flex;"><span>source-filter=<span style="color:#a31515">/usr/lib/cgit/filters/syntax-highlighting-edited.sh</span>
</span></span><span style="display:flex;"><span>about-filter=<span style="color:#a31515">/usr/lib/cgit/filters/about-formatting.sh</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>local-time=<span style="color:#a31515">1</span>
</span></span><span style="display:flex;"><span>snapshots=<span style="color:#a31515">tar.gz</span>
</span></span><span style="display:flex;"><span>repository-sort=<span style="color:#a31515">age</span>
</span></span><span style="display:flex;"><span>cache-size=<span style="color:#a31515">1000</span>
</span></span><span style="display:flex;"><span>branch-sort=<span style="color:#a31515">age</span>
</span></span><span style="display:flex;"><span>summary-log=<span style="color:#a31515">200</span>
</span></span><span style="display:flex;"><span>max-atom-items=<span style="color:#a31515">50</span>
</span></span><span style="display:flex;"><span>max-repo-count=<span style="color:#a31515">100</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>enable-index-owner=<span style="color:#a31515">0</span>
</span></span><span style="display:flex;"><span>enable-follow-links=<span style="color:#a31515">1</span>
</span></span><span style="display:flex;"><span>enable-log-filecount=<span style="color:#a31515">1</span>
</span></span><span style="display:flex;"><span>enable-log-linecount=<span style="color:#a31515">1</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>root-title=<span style="color:#a31515">Place for code, experiments and other bullshit!</span>
</span></span><span style="display:flex;"><span>root-desc=
</span></span><span style="display:flex;"><span>clone-url=<span style="color:#a31515">git@git.mitjafelicijan.com:/home/git/$CGIT_REPO_URL</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>mimetype.gif=<span style="color:#a31515">image/gif</span>
</span></span><span style="display:flex;"><span>mimetype.html=<span style="color:#a31515">text/html</span>
</span></span><span style="display:flex;"><span>mimetype.jpg=<span style="color:#a31515">image/jpeg</span>
</span></span><span style="display:flex;"><span>mimetype.jpeg=<span style="color:#a31515">image/jpeg</span>
</span></span><span style="display:flex;"><span>mimetype.pdf=<span style="color:#a31515">application/pdf</span>
</span></span><span style="display:flex;"><span>mimetype.png=<span style="color:#a31515">image/png</span>
</span></span><span style="display:flex;"><span>mimetype.svg=<span style="color:#a31515">image/svg+xml</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>readme=<span style="color:#a31515">:README.md</span>
</span></span><span style="display:flex;"><span>readme=<span style="color:#a31515">:readme.md</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Must be at the end!</span>
</span></span><span style="display:flex;"><span>virtual-root=<span style="color:#a31515">/</span>
</span></span><span style="display:flex;"><span>scan-path=<span style="color:#a31515">/home/git/</span>
</span></span></code></pre><p>For <code>syntax-highlighting-edited.sh</code> follow instructions on
<a href="https://wiki.archlinux.org/title/Cgit#Using_highlight">https://wiki.archlinux.org/title/Cgit</a>.</p>
<ul>
<li><code>/usr/share/cgit/cgit.css</code></li>
</ul>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>* {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">font-size</span>: 11<span style="color:#2b91af">pt</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>body {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">font-family</span>: <span style="color:#00f">monospace</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#00f">background</span>: <span style="color:#00f">white</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#00f">padding</span>: 1<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>th, td {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">text-align</span>: <span style="color:#00f">left</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000">/* HEADER */</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>#header {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">margin-bottom</span>: 1<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>#header .<span style="color:#2b91af">logo</span> img {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">display</span>: <span style="color:#00f">block</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#00f">height</span>: 3<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#00f">margin-right</span>: 10<span style="color:#2b91af">px</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>#header .<span style="color:#2b91af">sub</span>.<span style="color:#2b91af">right</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">display</span>: <span style="color:#00f">none</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000">/* FOOTER */</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">footer</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">margin-top</span>: 2<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#00f">font-style</span>: <span style="color:#00f">italic</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">footer</span>, .<span style="color:#2b91af">footer</span> a {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">color</span>: <span style="color:#00f">gray</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000">/* TABS */</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">tabs</span> a {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">margin-bottom</span>: 2<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#00f">display</span>: <span style="color:#00f">inline-block</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#00f">margin-right</span>: 1<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">tabs</span> td a:only-child {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">display</span>: <span style="color:#00f">none</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000">/* HIDING ELEMENTS */</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">cgit-panel</span>, .<span style="color:#2b91af">form</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">display</span>: <span style="color:#00f">none</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000">/* LISTS */</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">list</span> td, .<span style="color:#2b91af">list</span> th {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">padding-right</span>: 2<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">list</span> .<span style="color:#2b91af">nohover</span> a {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">color</span>: <span style="color:#00f">black</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">list</span> .<span style="color:#2b91af">button</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">padding-right</span>: 0.5<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000">/* COMMIT */</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">commit-subject</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">padding</span>: 1<span style="color:#2b91af">em</span> 0;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">decoration</span> a {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">padding-left</span>: 0.5<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">commit-info</span> th {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">padding-right</span>: 1<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">commit-subject</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">padding</span>: 2<span style="color:#2b91af">em</span> 0;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>table.<span style="color:#2b91af">diff</span> div.<span style="color:#2b91af">head</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">padding-top</span>: 2<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>table.<span style="color:#2b91af">diffstat</span> td {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">padding-right</span>: 1<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000">/* CONTENT */</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">linenumbers</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">padding-right</span>: 0.5<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">linenumbers</span> a {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">color</span>: <span style="color:#00f">gray</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>.<span style="color:#2b91af">pager</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">display</span>: <span style="color:#00f">flex</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#00f">list-style-type</span>: <span style="color:#00f">none</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#00f">padding</span>: 0;
</span></span><span style="display:flex;"><span>        gap: 0.5<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000">/* DIFF COLORS */</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>table.<span style="color:#2b91af">diff</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">width</span>: 100<span style="color:#2b91af">%</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>table.<span style="color:#2b91af">diff</span> td {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">white-space</span>: <span style="color:#00f">pre</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>table.<span style="color:#2b91af">diff</span> td div.<span style="color:#2b91af">head</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">font-weight</span>: <span style="color:#00f">bold</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#00f">margin-top</span>: 1<span style="color:#2b91af">em</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#00f">color</span>: <span style="color:#00f">black</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>table.<span style="color:#2b91af">diff</span> td div.<span style="color:#2b91af">hunk</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">color</span>: #009;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>table.<span style="color:#2b91af">diff</span> td div.<span style="color:#2b91af">add</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">color</span>: <span style="color:#00f">green</span>;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>table.<span style="color:#2b91af">diff</span> td div.<span style="color:#2b91af">del</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#00f">color</span>: <span style="color:#00f">red</span>;
</span></span><span style="display:flex;"><span>}
</span></span></code></pre>


guid: https://mitjafelicijan.com/development-environments-with-nix.html
title: Development environments with Nix
url: https://mitjafelicijan.com/development-environments-with-nix.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Nix is amazing for making reproducible cross OS development environment.</p>
<p>First you need to <a href="https://nixos.org/download.html">install Nix package
manager</a>.</p>
<ul>
<li>Create a file <code>shell.nix</code> in your project folder.</li>
<li>In the section that has <code>python3</code> etc add programs you want to use. These can
be CLI or GUI applications. It doesn't matter to Nix.</li>
</ul>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>{ pkgs ? <span style="color:#00f">import</span> <span style="color:#a31515">&lt;nixpkgs&gt;</span> {} }:
</span></span><span style="display:flex;"><span>  pkgs.mkShell {
</span></span><span style="display:flex;"><span>    nativeBuildInputs = <span style="color:#00f">with</span> pkgs.buildPackages; [
</span></span><span style="display:flex;"><span>	  python3
</span></span><span style="display:flex;"><span>	  tinycc
</span></span><span style="display:flex;"><span>	];
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>And then run it <code>nix-shell</code>. By default it will look for <code>shell.nix</code> file. If
you want to specify a different file use <code>nix-shell file.nix</code>. That is about it.</p>
<p>When the shell is spawned it could happen that your <code>PS1</code> prompt will be
overwritten and your prompt will look differently. In that case you need to
either do <code>NIX_SHELL_PRESERVE_PROMPT=1 nix shell</code> or add
<code>NIX_SHELL_PRESERVE_PROMPT</code> variable to your <code>bashrc</code> or <code>zshrc</code> file and set it
to <code>1</code>.</p>
<p>I also have a modified <code>PS1</code> prompt for Bash that I use and it also catches the
usage of Nix shell.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>NIX_SHELL_PRESERVE_PROMPT=1
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>parse_git_branch() {
</span></span><span style="display:flex;"><span>	git branch 2&gt; /dev/null | sed -e <span style="color:#a31515">&#39;/^[^*]/d&#39;</span> -e <span style="color:#a31515">&#39;s/* \(.*\)/ (\1)/&#39;</span>
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>is_inside_nix_shell() {
</span></span><span style="display:flex;"><span>	nix_shell_name=<span style="color:#a31515">&#34;</span><span style="color:#00f">$(</span>basename <span style="color:#a31515">&#34;</span>$IN_NIX_SHELL<span style="color:#a31515">&#34;</span> 2&gt;/dev/null<span style="color:#00f">)</span><span style="color:#a31515">&#34;</span>
</span></span><span style="display:flex;"><span>	<span style="color:#00f">if</span> [[ -n <span style="color:#a31515">&#34;</span>$nix_shell_name<span style="color:#a31515">&#34;</span> ]]; <span style="color:#00f">then</span>
</span></span><span style="display:flex;"><span>		echo <span style="color:#a31515">&#34; \e[0;36m(nix-shell)\e[0m&#34;</span>
</span></span><span style="display:flex;"><span>	<span style="color:#00f">fi</span>
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>export PS1=<span style="color:#a31515">&#34;[\033[38;5;9m\]\u@\h\[</span><span style="color:#00f">$(</span>tput sgr0<span style="color:#00f">)</span><span style="color:#a31515">\]]</span><span style="color:#00f">$(</span>is_inside_nix_shell<span style="color:#00f">)</span><span style="color:#a31515">\[\033[33m\]\$(parse_git_branch)\[\033[00m\] \w\[</span><span style="color:#00f">$(</span>tput sgr0<span style="color:#00f">)</span><span style="color:#a31515">\] \n</span>$<span style="color:#a31515"> &#34;</span>
</span></span></code></pre><p>And this is what it looks like when you are in a Nix shell. Otherwise that part
of prompt is omitted</p>
<figure>
<img src="/assets/notes/ps1-prompt.png" alt="PS1 Prompt" />
</figure>
<p>More resources:</p>
<ul>
<li><a href="https://nixos.wiki/wiki/Development_environment_with_nix-shell">https://nixos.wiki/wiki/Development_environment_with_nix-shell</a></li>
<li><a href="https://nixos.wiki/wiki/Main_Page">https://nixos.wiki/wiki/Main_Page</a></li>
<li><a href="https://itsfoss.com/why-use-nixos/">https://itsfoss.com/why-use-nixos/</a></li>
<li><a href="https://mynixos.com/">https://mynixos.com/</a></li>
</ul>


guid: https://mitjafelicijan.com/alacritty-open-links-with-modifier.html
title: Alacritty open links with modifier
url: https://mitjafelicijan.com/alacritty-open-links-with-modifier.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Alacritty by default makes all links in the terminal output clickable and this
gets annoying rather quickly. I liked the default behavior of Gnome terminal
where you needed to hold Control key and then you could click and open links.</p>
<p>To achieve this in Alacritty you need to provide a <code>hint</code> in the configuration
file. Config file is located at <code>~/.config/alacritty/alacritty.yml</code>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>hints:
</span></span><span style="display:flex;"><span>  enabled:
</span></span><span style="display:flex;"><span>  - regex: <span style="color:#a31515">&#34;(mailto:|gemini:|gopher:|https:|http:|news:|file:|git:|ssh:|ftp:)\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515">            [^\u0000-\u001F\u007F-\u009F&lt;&gt;\&#34;\\s{-}\\^⟨⟩`]+&#34;</span>
</span></span><span style="display:flex;"><span>    command: xdg-open
</span></span><span style="display:flex;"><span>    post_processing: <span style="color:#00f">true</span>
</span></span><span style="display:flex;"><span>    mouse:
</span></span><span style="display:flex;"><span>      enabled: <span style="color:#00f">true</span>
</span></span><span style="display:flex;"><span>      mods: Control
</span></span></code></pre><p>The following should work under any Linux system. For macOS, you will need to
change <code>command: xdg-open</code> to something else.</p>
<p>Now the links will be visible and clickable only when Control key is being
pressed.</p>
<p>Source: <a href="https://github.com/alacritty/alacritty/issues/5246">https://github.com/alacritty/alacritty/issues/5246</a></p>


guid: https://mitjafelicijan.com/10gui-10-finger-multitouch-user-interface.html
title: 10/GUI 10 Finger Multitouch User Interface
url: https://mitjafelicijan.com/10gui-10-finger-multitouch-user-interface.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Message from 10/GUI team (page 10gui.com does not exist anymore):</p>
<p><em>Over a quarter-century ago, Xerox introduced the modern graphical user
interface paradigm we today take for granted.</em></p>
<p><em>That it has endured is a testament to the genius of its design. But the
industry is now at a crossroads: New technologies promise higher-bandwidth
interaction, but have yet to find a truly viable implementation.</em></p>
<p><em>10/GUI aims to bridge this gap by rethinking the desktop to leverage technology
in an intuitive and powerful way.</em></p>
<p><video
poster="/assets/notes/10gui-10-finger-multitouch-user-interface.jpg"
src="/assets/notes/10gui-10-finger-multitouch-user-interface.mp4"
controls></video></p>


guid: https://mitjafelicijan.com/60s-ibm-computers-commercial.html
title: 60's IBM Computers Commercial
url: https://mitjafelicijan.com/60s-ibm-computers-commercial.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Likely aired during an hour-long program during the 1960s, long commercials such
as this typically aired during hour-long programs. They would <em>not</em> have aired
during a half-hour program.</p>
<p><video
poster="/assets/notes/60s-ibm-computers-commercial.jpg"
src="/assets/notes/60s-ibm-computers-commercial.mp4"
controls></video></p>


guid: https://mitjafelicijan.com/bringing-all-of-my-projects-together-under-one-umbrella.html
title: Bringing all of my projects together under one umbrella
url: https://mitjafelicijan.com/bringing-all-of-my-projects-together-under-one-umbrella.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<h2 id="what-is-the-issue-anyway">What is the issue anyway?</h2>
<p>Over the years, I have accumulated a bunch of virtual servers on my
<a href="https://www.digitalocean.com/">DigitalOcean</a> account for small experimental
projects I dabble in. And this has resulted in quite a bill. I mean, I wouldn't
care if these projects were actually being used. But there were just being there
unused and wasting resources. Which makes this an unnecessary burden for me.</p>
<p>Most of them are just small HTML pages that have an endpoint or two to read data
from or to, and for that reason I wrote servers left and right. To be honest,
all of those things could have been done with <a href="https://en.wikipedia.org/wiki/Common_Gateway_Interface">CGI
scripts</a> and that would
have been more than enough.</p>
<p>Recently, I decided to stop language hopping and focus on a simpler stack which
includes C, Go and Lua. And I can accomplish all the things I am interested in.</p>
<h2 id="finding-a-web-server-replacement">Finding a web server replacement</h2>
<p>Usually I had <a href="https://nginx.org/en/">Nginx</a> in front of these small web servers
and I had to manage SSL certificates and all that jazz. I am bored with these
things. I don't want to manage any of this bullshit anymore.</p>
<p>So the logical move forward was to find a solid alternative for this. I have
ended up on <a href="https://caddyserver.com/">Caddy server</a>. I've used it in the past
but kind of forgotten about it. What I really like about it is an ease of use
and a bunch of out of the box functionalities that come with it.</p>
<p>These are the <em>pitch</em> points from their website:</p>
<ul>
<li><strong>Secure by Default</strong>: Caddy is the only web server that uses HTTPS by
default. A hardened TLS stack with modern protocols preserves privacy and
exposes MITM attacks.</li>
<li><strong>Config API</strong>: As its primary mode of configuration, Caddy's REST API makes
it easy to automate and integrate with your apps.</li>
<li><strong>No Dependencies</strong>: Because Caddy is written in Go, its binaries are entirely
self-contained and run on every platform, including containers without libc.</li>
<li><strong>Modular Stack</strong>: Take back control over your compute edge. Caddy can be
extended with everything you need using plugins.</li>
</ul>
<p>I had just a few requirements:</p>
<ul>
<li>Automatic SSL</li>
<li>Static file server</li>
<li>Basic authentication</li>
<li>CGI script support</li>
</ul>
<p>And the vanilla version does all of it, but CGI scripts. But that can easily be
fixed with their modular approach. You can do this on their website and build a
custom version of the server, or do it with Docker.</p>
<p>This is a <code>Dockerfile</code> I used to build a custom server.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">FROM</span><span style="color:#a31515"> caddy:builder AS builder</span><span style="">
</span></span></span><span style="display:flex;"><span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span><span style="color:#00f">RUN</span> xcaddy build <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  --with github.com/aksdb/caddy-cgi<span style="">
</span></span></span><span style="display:flex;"><span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span><span style="color:#00f">FROM</span><span style="color:#a31515"> caddy:latest</span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span><span style="color:#00f">RUN</span> apk add --no-cache nano<span style="">
</span></span></span><span style="display:flex;"><span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span><span style="color:#00f">COPY</span> --from=builder /usr/bin/caddy /usr/bin/caddy<span style="">
</span></span></span></code></pre><h2 id="getting-rid-of-all-the-unnecessary-virtual-machines">Getting rid of all the unnecessary virtual machines</h2>
<p>The next step was to get a handle on the number of virtual servers I have all
over the place.</p>
<p>I decided to move all the projects and services into two main VMs:</p>
<ul>
<li>personal server (still Nginx)
<ul>
<li>git server</li>
<li>static file server</li>
<li>personal blog</li>
</ul>
</li>
<li>projects server (Caddy server)
<ul>
<li>personal experiments</li>
<li>other projects</li>
</ul>
</li>
</ul>
<p>I will focus on projects' server in this post since it's more interesting.</p>
<h2 id="testing-cgi-scripts">Testing CGI scripts</h2>
<p>The first thing I tested was how CGI scripts work under Caddy. This is
particularly import to me because almost all of my experiments and mini projects
need this to work.</p>
<p>To configure Caddy server, you must provide the server with a configuration
file. By default, it's called <code>Caaddyfile</code>.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#00f">order</span> <span style="color:#a31515">cgi</span> before <span style="color:#a31515">respond</span>
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="font-weight:bold">examples.mitjafelicijan.com</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#00f">cgi</span> /bash-test <span style="color:#a31515">/opt/projects/examples/bash-test.sh</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">cgi</span> /tcl-test <span style="color:#a31515">/opt/projects/examples/tcl-test.tcl</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">cgi</span> /lua-test <span style="color:#a31515">/opt/projects/examples/lua-test.lua</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">cgi</span> /python-test <span style="color:#a31515">/opt/projects/examples/python-test.py</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">root</span> * <span style="color:#a31515">/opt/projects/examples</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">file_server</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><ul>
<li>The order is very important. Make sure that <code>order cgi before respond</code> is at
the top of the configuration file.</li>
<li>Also, when you run with Caddy v2, make sure you provide <code>adapter</code> argument
like this <code>/usr/bin/caddy run --watch --environ --config /etc/caddy/Caddyfile --adapter caddyfile</code>. Otherwise, Caddy will try to use a different format for
config file.</li>
</ul>
<p>I did a small batch of tests with <a href="https://www.gnu.org/software/bash/">Bash</a>,
<a href="https://www.tcl-lang.org/">Tcl</a>, <a href="https://www.lua.org/">Lua</a> and
<a href="https://www.python.org/">Python</a>. Here is a cheat sheet if you need it.</p>
<p>Let's get Bash out of the way first.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">#!/usr/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#00f"></span>
</span></span><span style="display:flex;"><span>printf <span style="color:#a31515">&#34;Content-type: text/plain\n\n&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>printf <span style="color:#a31515">&#34;Hello from Bash\n\n&#34;</span>
</span></span><span style="display:flex;"><span>printf <span style="color:#a31515">&#34;PATH_INFO     [%s]\n&#34;</span> $PATH_INFO
</span></span><span style="display:flex;"><span>printf <span style="color:#a31515">&#34;QUERY_STRING  [%s]\n&#34;</span> $QUERY_STRING
</span></span><span style="display:flex;"><span>printf <span style="color:#a31515">&#34;\n&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">for</span> i in {0..9..1}; <span style="color:#00f">do</span>
</span></span><span style="display:flex;"><span>  printf <span style="color:#a31515">&#34;&gt; %s\n&#34;</span> $i
</span></span><span style="display:flex;"><span><span style="color:#00f">done</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>exit 0
</span></span></code></pre><p>This one is for Tcl script.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000">#!/usr/bin/tclsh
</span></span></span><span style="display:flex;"><span><span style="color:#008000">
</span></span></span><span style="display:flex;"><span><span style="color:#008000"></span>puts <span style="color:#a31515">&#34;Content-type: text/plain\n&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>puts <span style="color:#a31515">&#34;Hello from Tcl\n&#34;</span>
</span></span><span style="display:flex;"><span>puts <span style="color:#a31515">&#34;PATH_INFO     \[$env(PATH_INFO)\]&#34;</span>
</span></span><span style="display:flex;"><span>puts <span style="color:#a31515">&#34;QUERY_STRING  \[$env(QUERY_STRING)\]&#34;</span>
</span></span><span style="display:flex;"><span>puts <span style="color:#a31515">&#34;&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">for</span> <span style="color:#00f">{set</span> i 0<span style="color:#00f">}</span> <span style="color:#00f">{</span>$i &lt; 10<span style="color:#00f">}</span> <span style="color:#00f">{</span>incr i<span style="color:#00f">}</span> <span style="color:#00f">{</span>
</span></span><span style="display:flex;"><span>  puts <span style="color:#a31515">&#34;&gt; $i&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#00f">}</span>
</span></span></code></pre><p>And for all you Python enjoyers.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000">#!/usr/bin/python3</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">import</span> os
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>print(<span style="color:#a31515">&#34;Content-type: text/plain</span><span style="color:#a31515">\n</span><span style="color:#a31515">&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>print(<span style="color:#a31515">&#34;Hello from Python</span><span style="color:#a31515">\n</span><span style="color:#a31515">&#34;</span>)
</span></span><span style="display:flex;"><span>print(<span style="color:#a31515">&#34;PATH_INFO     [</span><span style="color:#a31515">{}</span><span style="color:#a31515">]&#34;</span>.format(os.environ[<span style="color:#a31515">&#39;PATH_INFO&#39;</span>]))
</span></span><span style="display:flex;"><span>print(<span style="color:#a31515">&#34;QUERY_STRING  [</span><span style="color:#a31515">{}</span><span style="color:#a31515">]&#34;</span>.format(os.environ[<span style="color:#a31515">&#39;QUERY_STRING&#39;</span>]))
</span></span><span style="display:flex;"><span>print(<span style="color:#a31515">&#34;&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">for</span> i <span style="color:#00f">in</span> range(10):
</span></span><span style="display:flex;"><span>  print(<span style="color:#a31515">&#34;&gt; </span><span style="color:#a31515">{}</span><span style="color:#a31515">&#34;</span>.format(i))
</span></span></code></pre><p>And for the final example, Lua.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">#!/usr/bin/lua</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>print(<span style="color:#a31515">&#34;Content-type: text/plain</span><span style="color:#a31515">\n</span><span style="color:#a31515">&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>print(<span style="color:#a31515">&#34;Hello from Lua</span><span style="color:#a31515">\n</span><span style="color:#a31515">&#34;</span>)
</span></span><span style="display:flex;"><span>print(string.format(<span style="color:#a31515">&#34;PATH_INFO     [%s]&#34;</span>, os.getenv(<span style="color:#a31515">&#34;PATH_INFO&#34;</span>)))
</span></span><span style="display:flex;"><span>print(string.format(<span style="color:#a31515">&#34;QUERY_STRING  [%s]&#34;</span>, os.getenv(<span style="color:#a31515">&#34;QUERY_STRING&#34;</span>)))
</span></span><span style="display:flex;"><span>print()
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">for</span> i = 0, 9 <span style="color:#00f">do</span>
</span></span><span style="display:flex;"><span>  print(string.format(<span style="color:#a31515">&#34;&gt; %d&#34;</span>, i))
</span></span><span style="display:flex;"><span><span style="color:#00f">end</span>
</span></span></code></pre><h2 id="basic-authentication">Basic authentication</h2>
<p>One thing was also to have an option for some sort of authentication, and
something like <a href="https://en.wikipedia.org/wiki/Basic_access_authentication">Basic access
authentication</a> would
be more than enough.</p>
<p>Thankfully, Caddy supports this out of the box already. Below is an updated
example.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>    <span style="color:#00f">order</span> <span style="color:#a31515">cgi</span> before <span style="color:#a31515">respond</span>
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="font-weight:bold">examples.mitjafelicijan.com</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#00f">cgi</span> /bash-test <span style="color:#a31515">/opt/projects/examples/bash-test.sh</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">cgi</span> /tcl-test <span style="color:#a31515">/opt/projects/examples/tcl-test.tcl</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">cgi</span> /lua-test <span style="color:#a31515">/opt/projects/examples/lua-test.lua</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">cgi</span> /python-test <span style="color:#a31515">/opt/projects/examples/python-test.py</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">root</span> * <span style="color:#a31515">/opt/projects/examples</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">file_server</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#00f">basicauth</span> * {
</span></span><span style="display:flex;"><span>    <span style="color:#00f">bob</span> <span style="">$</span><span style="color:#a31515">2a</span><span style="">$</span>14<span style="">$</span><span style="color:#a31515">/wCgaf9oMnmQa20txB76u.nI1AldGMBT/1J7fXCfgOiRShwz/JOkK</span>
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p><code>basicauth *</code> matches everything under this domain/sub-domain and protects it
with Basic Authentication.</p>
<ul>
<li><code>bob</code> is the username</li>
<li><code>hash</code> is the password</li>
</ul>
<p>To generate these passwords, execute <code>caddy hash-password</code> and this will prompt
you to insert a password twice and spit out a hashed password that you can put
in your configuration file.</p>
<p>Restart the server and you are ready to go.</p>
<h2 id="making-caddy-a-service-with-systemd">Making Caddy a service with systemd</h2>
<p>After the tests were successful, I copied <code>caddy</code> to <code>/usr/bin/caddy</code> and copied
<code>Caddyfile</code> to <code>/etc/caddy/Caddyfile</code>.</p>
<p>Now off to the systemd. Each systemd service requires you to create a service
file.</p>
<ul>
<li>I created a <code>/etc/systemd/system/caddy.service</code> and put the following content
in the file.</li>
</ul>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">[Unit]</span>
</span></span><span style="display:flex;"><span>Description=<span style="color:#a31515">Caddy</span>
</span></span><span style="display:flex;"><span>Documentation=<span style="color:#a31515">https://caddyserver.com/docs/</span>
</span></span><span style="display:flex;"><span>After=<span style="color:#a31515">network.target network-online.target</span>
</span></span><span style="display:flex;"><span>Requires=<span style="color:#a31515">network-online.target</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">[Service]</span>
</span></span><span style="display:flex;"><span>Type=<span style="color:#a31515">notify</span>
</span></span><span style="display:flex;"><span>User=<span style="color:#a31515">root</span>
</span></span><span style="display:flex;"><span>Group=<span style="color:#a31515">root</span>
</span></span><span style="display:flex;"><span>ExecStart=<span style="color:#a31515">/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile --adapter caddyfile</span>
</span></span><span style="display:flex;"><span>ExecReload=<span style="color:#a31515">/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force --adapter caddyfile</span>
</span></span><span style="display:flex;"><span>TimeoutStopSec=<span style="color:#a31515">5s</span>
</span></span><span style="display:flex;"><span>LimitNOFILE=<span style="color:#a31515">1048576</span>
</span></span><span style="display:flex;"><span>LimitNPROC=<span style="color:#a31515">512</span>
</span></span><span style="display:flex;"><span>PrivateTmp=<span style="color:#a31515">true</span>
</span></span><span style="display:flex;"><span>ProtectSystem=<span style="color:#a31515">full</span>
</span></span><span style="display:flex;"><span>AmbientCapabilities=<span style="color:#a31515">CAP_NET_ADMIN CAP_NET_BIND_SERVICE</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">[Install]</span>
</span></span><span style="display:flex;"><span>WantedBy=<span style="color:#a31515">multi-user.target</span>
</span></span></code></pre><ul>
<li>You might need to reload systemd with <code>systemctl daemon-reload</code>.</li>
<li>Then I enabled the service with <code>systemctl enable caddy.service</code>.</li>
<li>And then I started the service with <code>systemctl start caddy.service</code>.</li>
</ul>
<p>This was about all that I needed to do to get it running. Now I can easily add
new subdomains and domains to the main configuration file and be done with
it. No manual Let's Encrypt shenanigans needed.</p>


guid: https://mitjafelicijan.com/who-knows-what-the-world-will-look-like-tomorrow.html
title: Who knows what the world will look like tomorrow
url: https://mitjafelicijan.com/who-knows-what-the-world-will-look-like-tomorrow.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>This site has gone through a lot of changes over the years. From being written
in Flask and Bottle to moving on to static site generators. I have used and
tested probably 10s of them my now. From homebrew solutions to the biggest and
the baddest. From Bash scripts to Node.js disasters. I've seen some things, no
doubt. Not all bad.</p>
<p>I have been closely observing the web and where the trends are going, and I
don't like what I see. Instead of internet being this weird place where
experimentation is happening, it all became stale and formulized. Boring,
actually. Really boring. And sad. Where is that old, revolutionary FU spirit I
remember? It's still there, I know. But it's being drowned by the voices of
mediocrity and formulaic boredom.</p>
<p>It almost feels like that the internet stopped for 10 years and only now
something has started happening. With all the insanity around the world. People
hating people without actual reasons, just because it's fashionable to hate and
crowd is saying so. Sad state of affairs.</p>
<p>All this is contributing to this overall negativity masked as apathy. Everybody
walking in lockstep. Instead of being creative and bold, we are just
re-inventing the world and making the same mistakes. Maybe, just maybe, some
things are good enough and there is no need to try to be too smart for our own
good. After N-attempts, maybe something should click inside our heads to maybe
say: &quot;This thing, opinion, etc. is actually really good, and even after several
attempts it still holds.&quot;</p>
<p>The older I get, the more careful I am of my own thoughts and why I think the
way I think. More and more, I try to understand people with opposite
opinions. Far from perfect, but closer to bearable. And then I see people
hearing or reading a thing on internet and let's fucking goooooo! Strong
opinions are a sign of a weak and uneducated mind. I am more and more sure of
this.</p>
<p>It's gotten to a point where you can with great certainty deduce a person's
personality based on one or two opinions. How boring have we become. No wonder
people can't talk to each other. These would be very quick conversations anyway.</p>
<p>I just got remembered of a song, <a href="https://www.youtube.com/watch?v=s_nc1IVoMxc">&quot;Hi
Ren&quot;</a>. The ending talks about being
stiff and not being able to dance. Such an amazing metaphor. And we as people
have gone so far, we can't even walk or even crawl normally anymore. We have
forgotten that the most beautiful things in life have a great deal of
uncertainty about them. We want instant gratification. Not only that, but we
want absolute obedience. Complete control over others, because we have zero
control of ourselves. And all the lies we could tell ourselves will not help us
out of this situation.</p>
<p>It is funny how I catch myself from time to time being a complete idiot. It's
like having an outer body experience. I can see myself being an idiot, and
cannot stop myself. It serves as a learning lesson to stop before speaking. To
think before saying. And to crawl before walking.</p>
<p>So there is still time. We can dance once more. All we need to do is stop for a
second. Me and you. Us two is a start. Let's not try to change the world, but
rather nudge ourselves just a tiny bit. And if we only did that?! Just
imagine. Each of us nudged ourselves a small, tiny bit, the world would heal. If
we would just put down the phones and ignored Internet for a day or two. Put
visiting websites that feed on us on hold. Listened to just one sentence and try
to understand it from a person who we completely disagree with. I truly believe
that this is possible.</p>
<p>Life is about suffering and joy. And instead of wishing suffering on others and
excepting joy for yourselves, we should for a brief moment want suffering for
ourselves and wish joy on others. Wouldn't that be an amazing sight to see?</p>
<p>I caught myself hating on Rust. And I deeply thought about it afterward. Why did
I do it? It is obviously not for me. So why the hell was I being so negative
towards it? I think that I know the answer. I was negative because that is
easy. Because it's much easier to hate on things than to say to yourself: &quot;Well,
you know what? This is not for me. I will focus on creation and not
destruction. This is who I want to be. This is what fills me with joy and
purpose.&quot; Where joy is keeping me happy and purpose scares the shit out of me
and keeps me honest. This is who I want to be. Admit to myself when I am wrong
and accept the faults that I have without reservation and with courage march on.</p>
<p>I just realized that this blog post is a sort of therapy for me. It's
cathartic. Going thought the history of this site and remembering all the
decisions and annoyances that came with it. When I was cursing at the tools. And
time moved on, and the site is still here. It serves as a reminder that
perseverance wins at the end. If we just let things go.</p>
<p>This came with a decision that simplifying life and removing all the unnecessary
negativity is key. Rather than worrying about what the internet is saying, what
the world is trying to take from you, you are the only one who can say no. And
create instead of destroy.</p>
<p>I don't have an ending for this post, so I will say this. We live in the most
amazing times in the recorded history, and we should be internally grateful for
it. Create and study, this should be my mantra. Just create and let the world
happen. And when you feel yourself to be too certain, stop and check how deep in the
shit you are already. Strong opinions are a sign of a weak and uneducated
mind. Hate and disdain is for the weak.</p>


guid: https://mitjafelicijan.com/online-radio-streaming-with-mpv-from-terminal.html
title: Online radio streaming with MPV from terminal
url: https://mitjafelicijan.com/online-radio-streaming-with-mpv-from-terminal.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Recently I have been using my Thinkpad x220 more and there are some constraints
I have faced with it. CPU is not as powerful as on my main machine and I really
want to listen to some music while using the machine. Browsers really are bloat.</p>
<p>Check out this site <a href="https://streamurl.link/">https://streamurl.link/</a> and copy the stream url and then do
<code>mpv streamlink</code>.</p>


guid: https://mitjafelicijan.com/fix-screen-tearing-on-debian-12-xorg-and-i3.html
title: Fix screen tearing on Debian 12 Xorg and i3
url: https://mitjafelicijan.com/fix-screen-tearing-on-debian-12-xorg-and-i3.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I have been experiencing some issues with Intel® Integrated HD Graphics 3000
under Debian 12 with Xorg and i3. Using <code>picom</code> compositor didn't help. To fix
this issue create new file <code>/etc/X11/xorg.conf.d/20-intel.conf</code> as root and put
the following in the file.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>Section &#34;Device&#34;
</span></span><span style="display:flex;"><span>  Identifier &#34;Intel Graphics&#34;
</span></span><span style="display:flex;"><span>  Driver &#34;intel&#34;
</span></span><span style="display:flex;"><span>  Option &#34;TearFree&#34; &#34;true&#34;
</span></span><span style="display:flex;"><span>EndSection
</span></span></code></pre><p>Reboot the system and that should be it.</p>


guid: https://mitjafelicijan.com/set-color-temperature-of-displays-on-i3.html
title: Set color temperature of displays on i3
url: https://mitjafelicijan.com/set-color-temperature-of-displays-on-i3.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I have been using Gnome's night shift for a while now and I have been missing
this feature under i3wm. This can be done with
<a href="https://linux.die.net/man/1/redshift">redshift</a>.</p>
<ul>
<li>On Debian install with <code>sudo apt install redshift</code></li>
<li>And then manually set it with <code>redshift -O 3000</code></li>
<li>Reset the current settings with <code>redshift -x</code></li>
</ul>


guid: https://mitjafelicijan.com/make-b-w-svg-charts-with-matplotlib.html
title: Make B/W SVG charts with matplotlib
url: https://mitjafelicijan.com/make-b-w-svg-charts-with-matplotlib.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Install pip requirements.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>pip install matplotlib
</span></span><span style="display:flex;"><span>pip install pandas
</span></span></code></pre><p>Example of data being used.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>Epoch,Connect (NLB),Processing (NLB),Waiting (NLB),Total (NLB),Connect (ALB),Processing (ALB),Waiting (ALB),Total (ALB)
</span></span><span style="display:flex;"><span>1,57.7,315.7,309.4,321.6,9,104.4,98.3,105.7
</span></span><span style="display:flex;"><span>2,121.9,114.4,100.3,176.9,5.8,99.1,97.1,101.1
</span></span><span style="display:flex;"><span>3,5.3,229.4,231.2,231.4,14.2,83,69.4,87.9
</span></span><span style="display:flex;"><span>4,4.2,134.5,112.2,135.3,5.3,132.4,105.5,134.1
</span></span><span style="display:flex;"><span>5,5.8,247.4,246.8,248.1,6,74.3,70.2,75.5
</span></span><span style="display:flex;"><span>6,9.9,122.9,100.6,122.7,7.5,241.1,79.3,242.3
</span></span><span style="display:flex;"><span>7,6.1,170.2,106.4,170.5,7.2,382.4,375.1,383.8
</span></span><span style="display:flex;"><span>8,6.6,194.3,201.4,195.5,7.1,130.9,104.8,132.6
</span></span><span style="display:flex;"><span>9,6.4,146.1,122.3,147.7,9.4,95.6,74,96.4
</span></span></code></pre><p>In the code you can use <code>df</code> as dataframes and use the headers like <code>df[&quot;Epoch&quot;]</code>.
This is how you get a column data with pandas.</p>
<p>The Python code responsible for generating a chart:</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">import</span> csv
</span></span><span style="display:flex;"><span><span style="color:#00f">import</span> sys
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">import</span> matplotlib.pyplot <span style="color:#00f">as</span> plt
</span></span><span style="display:flex;"><span><span style="color:#00f">import</span> pandas <span style="color:#00f">as</span> pd
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Read the data</span>
</span></span><span style="display:flex;"><span>df = pd.read_csv(<span style="color:#a31515">&#34;data.csv&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Settings</span>
</span></span><span style="display:flex;"><span>plt.title(<span style="color:#a31515">&#34;Connect median NLB vs ALB&#34;</span>)
</span></span><span style="display:flex;"><span>plt.tight_layout(pad=2)
</span></span><span style="display:flex;"><span>fig = plt.gcf()
</span></span><span style="display:flex;"><span>fig.set_size_inches(10, 4)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Plotting</span>
</span></span><span style="display:flex;"><span>plt.plot(df[<span style="color:#a31515">&#34;Epoch&#34;</span>], df[<span style="color:#a31515">&#34;Connect (ALB)&#34;</span>], label = <span style="color:#a31515">&#34;ALB&#34;</span>, color=<span style="color:#a31515">&#34;black&#34;</span>, linestyle=<span style="color:#a31515">&#34;-&#34;</span>)
</span></span><span style="display:flex;"><span>plt.plot(df[<span style="color:#a31515">&#34;Epoch&#34;</span>], df[<span style="color:#a31515">&#34;Connect (NLB)&#34;</span>], label = <span style="color:#a31515">&#34;NLB&#34;</span>, color=<span style="color:#a31515">&#34;black&#34;</span>, linestyle=<span style="color:#a31515">&#34;--&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Adding x and y axis labels</span>
</span></span><span style="display:flex;"><span>plt.xlabel(<span style="color:#a31515">&#34;Epoch&#34;</span>, fontstyle=<span style="color:#a31515">&#34;italic&#34;</span>)
</span></span><span style="display:flex;"><span>plt.ylabel(<span style="color:#a31515">&#34;Median value (ms)&#34;</span>, fontstyle=<span style="color:#a31515">&#34;italic&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Legend</span>
</span></span><span style="display:flex;"><span>legend = plt.legend()
</span></span><span style="display:flex;"><span>legend.get_frame().set_linewidth(0)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Export as SVG</span>
</span></span><span style="display:flex;"><span>plt.savefig(<span style="color:#a31515">&#34;plot.svg&#34;</span>, format=<span style="color:#a31515">&#34;svg&#34;</span>)
</span></span></code></pre><figure>
<img src="/assets/notes/plot.svg" alt="SVG Chart" />
</figure>
<p>The image above is SVG and you can zoom in and out and check that the image is vector.</p>


guid: https://mitjafelicijan.com/aws-eb-pyyaml-fix.html
title: AWS EB PyYAML fix
url: https://mitjafelicijan.com/aws-eb-pyyaml-fix.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Recent update of my system completely borked <a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install-advanced.html">EB CLI</a>
on my machine.</p>
<p>I tried installing it with <code>pip install awsebcli --upgrade --user</code> and it failed.</p>
<p>The error was the following.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>Collecting PyYAML&lt;6.1,&gt;=5.3.1 (from awsebcli)
</span></span><span style="display:flex;"><span>  Using cached PyYAML-5.4.1.tar.gz (175 kB)
</span></span><span style="display:flex;"><span>  Installing build dependencies ... done
</span></span><span style="display:flex;"><span>  Getting requirements to build wheel ... error
</span></span><span style="display:flex;"><span>  error: subprocess-exited-with-error
</span></span><span style="display:flex;"><span>  
</span></span><span style="display:flex;"><span>  × Getting requirements to build wheel did not run successfully.
</span></span><span style="display:flex;"><span>  │ exit code: 1
</span></span><span style="display:flex;"><span>  ╰─&gt; [68 lines of output]
</span></span></code></pre><p>To fix this issue with PyYAML you must install PyYAML separately.</p>
<p>Do the following and try installing <code>eb</code> again after.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>echo <span style="color:#a31515">&#39;Cython &lt; 3.0&#39;</span> &gt; /tmp/constraint.txt
</span></span><span style="display:flex;"><span>PIP_CONSTRAINT=/tmp/constraint.txt pip install <span style="color:#a31515">&#39;PyYAML==5.4.1&#39;</span>
</span></span></code></pre>


guid: https://mitjafelicijan.com/compile-drawterm-on-fedora-38.html
title: Compile drawterm on Fedora 38
url: https://mitjafelicijan.com/compile-drawterm-on-fedora-38.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>First install two dependencies:</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo dnf install libX11-devel libXt-devel
</span></span></code></pre><p>Clone the repo and compile it:</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>git clone git://git.9front.org/plan9front/drawterm
</span></span><span style="display:flex;"><span>cd drawterm
</span></span><span style="display:flex;"><span>CONF=unix make
</span></span></code></pre><p>That should produce <code>drawterm</code> binary.</p>


guid: https://mitjafelicijan.com/using-ffmpeg-to-combine-video-side-by-side.html
title: Using ffmpeg to combine videos side by side
url: https://mitjafelicijan.com/using-ffmpeg-to-combine-video-side-by-side.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I had a 4 webm videos (each 492x451) that I wanted to combine to be played side
by side and I tried <a href="https://support.apple.com/imovie">iMovie</a> and
<a href="https://kdenlive.org/">Kdenlive</a> and failed to do it in an easy way. I needed
this for Github readme file so it also needed to be a GIF.</p>
<p>The following is the <a href="https://ffmpeg.org/">ffmpeg</a> version of it.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>ffmpeg -y <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  -i 01.webm <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  -i 02.webm <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  -i 03.webm <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  -i 04.webm <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  -filter_complex <span style="color:#a31515">&#34;\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515">  	[0:v] trim=duration=8, setpts=PTS-STARTPTS, scale=492x451, fps=6 [a0]; \
</span></span></span><span style="display:flex;"><span><span style="color:#a31515">  	[1:v] trim=duration=8, setpts=PTS-STARTPTS, scale=492x451, fps=6 [a1]; \
</span></span></span><span style="display:flex;"><span><span style="color:#a31515">  	[2:v] trim=duration=8, setpts=PTS-STARTPTS, scale=492x451, fps=6 [a2]; \
</span></span></span><span style="display:flex;"><span><span style="color:#a31515">  	[3:v] trim=duration=8, setpts=PTS-STARTPTS, scale=492x451, fps=6 [a3]; \
</span></span></span><span style="display:flex;"><span><span style="color:#a31515">  	[a0][a1][a2][a3] xstack=inputs=4:layout=0_0|w0_0|w0+w1_0|w0+w1+w2_0, scale=1000:-1 [v]&#34;</span> <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  -map <span style="color:#a31515">&#34;[v]&#34;</span> <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  -crf 23 <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  -preset veryfast <span style="color:#a31515">\
</span></span></span><span style="display:flex;"><span><span style="color:#a31515"></span>  trigraphs.gif
</span></span></code></pre><ul>
<li>This will produce <code>trigraphs.gif</code> that is also scaled to max 1000px in width
(refer to <code>scale=1000:-1</code>).</li>
<li>The important part for 4x1 stack is <code>xstack=inputs=4:layout=0_0|w0_0|w0+w1_0|w0+w1+w2_0</code>.</li>
<li>This will also cap frame rate to 6 (refer to <code>fps=6</code>) since that is enough and
this makes playback of GIFs smoother in a browser.</li>
</ul>
<figure>
<img src="./assets/notes/trigraphs.gif" alt="Result" />
</figure>


guid: https://mitjafelicijan.com/elitist-attitudes-are-sapping-all-the-fun-from-programming.html
title: Elitist attitudes are sapping all the fun from programming
url: https://mitjafelicijan.com/elitist-attitudes-are-sapping-all-the-fun-from-programming.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>It's always been like that. Maybe it was even worse before, and I am remembering
it with rose-tinted glasses. But from the best that I can remember, it had at
least some roots in reality. If something was objectively bad, you could point
to it. But what I have started noticing recently is that objectivity is not the
only condition to bash on something. More and more, you can use subjective
opinion to say horrible things about technology, language or just a specific
manufacturer.</p>
<p>And all this has achieved is that I don't really listen to anybody anymore. I
don't care what you think about X or Y. I don't care if you like this language
or that one. I don't care if you prefer Dell to ThinkPad over Macbook. Who gives
a fuck, anyway? If you can do your job on it, why even care about this stuff at
all. And if you can't, buy a different machine.</p>
<p>It's like the politics weren't enough. Now the same tribalism is here as well. C
developers hating on Rust. JavaScript developers laughing at jQuery users. Rust
developers laughing at everybody except Haskell users. And everybody laughing at
JavaScript. It's like this never-ending dream, being stuck in high school. Us
against your team. It's like we are all stuck being 16. Such a sad state of
affair. And it's always been like this. But it's getting worse I think.</p>
<p>Everybody trying to be elitist. Compensating lack of JavaScript features (like
type system, for one) with coming up with this insane terminology to make
JavaScript sound more sophisticated, as it is. Let's invent terminology to hide
flaws and sound more educated and academic. And the same goes for C and all the
other languages. All languages are shitty in some ways. For the love of God,
why? Just let it be. For once, let things just be.</p>
<p>And I, for one, just do not care anymore. Languages are tools and not your
identity. If you need a programming language to fill a void in your life, I
strongly suggest that you re-evaluate where you stand currently. Try something
else. You are not a C developer, or Go developer, or JavaScript developer. You
are a problem solver. That's what you are. And be damn proud of it. You don't
need a label to make that more true or more sophisticated.</p>
<p>I use Linux and macOS. I have fun on both systems. In my personal experience,
Macbooks are better laptops for what I need them to be. They are better fit for
me. Portable machines with an amazing battery life. That's all that I need from
a laptop. I don't need to come up with this insane hypothetical scenarios where
it will fell short. Yes, it can't water the plants when I am sleeping. OMG, are
we really going there. These insane hypotheticals. Who really cares? I don't! I
use it, it does what I need it to do, and that is the end of the story. Not only
that, but I don't push this down other people's throats. Like Tsodings often
says: It is what it is, and it isn't what it isn't. Such wise words. On my main
machine I have Linux and had it for more than 20 years and I love it. I LOVE
it. I am used to it. And I've had some shitty experiences with it, but damn it,
I love it. It does what it needs to do. It fits my needs. And if I needed
Windows, I would find a way to love it too. Why not? There is enough love to go
around where you are not being elitist and a shithead.</p>
<p>Programming should be fun. Not going through a checklist before you even start,
to see if you are using what is considered the “cool” thing. If you are doing
this, you already failed in my opinion.</p>
<p>Oh, you are not using this “insert here” algorithm? Such a pleb. Don't you know
about O(N) complexity? OMG, such a noob. He doesn't know. Uneducated pleb. 2017
called, and they want their stack back.</p>
<p>Yes, there is a place for all of those things. But not everything needs to be
perfect. There is an awesome quote in Uncharted: Sic Parvis Magna. “greatness,
from small beginnings.”</p>
<p>I would laugh if it wasn't sad. And in the end, who cares. Let these people
worry about making the perfect solutions that will never ship or take years to
finish because “Early optimization is the root of all evil.” Everybody has their
definition of fun. I just don't want to listen to people preaching to others how
to do stuff. If people would just shut up and think before they speak 5% of the
time, the world would be a different place. But that will never happen. So the
only solution is to not give a fuck.</p>
<p>This is more a rant than an actual post with some solution, so maybe I am a part
of the problem. Who knows? Just venting. Every so often it helps.</p>
<p>Do your Rust thing. It's not for me, though. But if it works for you, more power
to you. Do your project with vanilla JavaScript. You don't always need
TypeScript, Next.js or who know what else to make a button do a thing. Use VS
Code or Vim or Emacs or even Notepad if you wish. If you are having fun, then
just do it. Don't worry about these elitist pricks. They will never be satisfied
anyway. You will never get their approval. So why even bother. Just go for
it. Use C, Rust, OCaml, whatever floats your boat. If it tickles you, just do
it. To hell with everybody else. And if somebody says O(N) complexity, dude? You
can say, OOOOO, fuck the fuck off.</p>
<p>If this post triggered you, then you are the asshole. Probably. Then you
probably are that guy preaching about O(N) or this language is soo slow
haha. Stop it. Nobody cares! Touch grass.</p>
<p>Anyway, back to having fun. Cheers!</p>


guid: https://mitjafelicijan.com/add-lazy-loading-to-jekyll-posts.html
title: Add lazy loading of images in Jekyll posts
url: https://mitjafelicijan.com/add-lazy-loading-to-jekyll-posts.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Normally you define images with <code>![]()</code> in markdown files. But jekyll also
provides a way to adding custom attributes to tags with <code>{:attr=&quot;value&quot;}</code>.</p>
<p>If you have lots of posts this command will append `` to all
images in all your markdown files.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>![image-title](/path/to/your/image.jpg)
</span></span></code></pre><p>will become</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>![image-title](/path/to/your/image.jpg)
</span></span></code></pre><p>Shell line bellow. Go into the folder where your posts are (probably <code>_posts</code>).</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>find . -type f -name <span style="color:#a31515">&#34;*.md&#34;</span> -exec sed -i -E <span style="color:#a31515">&#39;s/(\!\[.*\]\((.*?)\))$/\1/&#39;</span> {} <span style="color:#a31515">\;</span>
</span></span></code></pre><p>Under the hood this adds <code>loading=&quot;lazy&quot;</code> to HTML <code>img</code> nodes.</p>
<p>That is about it.</p>


guid: https://mitjafelicijan.com/apersonal-sane-vim-defaults.html
title: Personal sane Vim defaults
url: https://mitjafelicijan.com/apersonal-sane-vim-defaults.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I have found many &quot;sane&quot; default configs on the net and this is my favorite
personal list. This is how my <code>.vimrc</code> file looks like.</p>
<p><a href="https://github.com/mitjafelicijan/dotfiles/blob/master/vimrc">Updated version is available on GitHub.</a></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000">&#34; General sane defaults.</span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>syntax enable<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>colorscheme sorbet<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>nnoremap q: &lt;nop&gt;<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set nocompatible<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set relativenumber<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set nohlsearch<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set smartcase<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set ignorecase<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set incsearch<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set autoindent<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set nowrap<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set nobackup<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set noswapfile<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set autoread<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set wildmenu<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set encoding=utf8<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set backspace=2<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set scrolloff=4<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set spelllang=en_us<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span><span style="color:#008000">
</span></span></span><span style="display:flex;"><span><span style="color:#008000">&#34; Status Line enhancements.</span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set laststatus=2<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>set statusline=%f%m%=%y\ %{strlen(&amp;fenc)?&amp;fenc:<span style="color:#a31515">&#39;none&#39;</span>}\ %l:%c\ %L\ %P<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>hi StatusLine cterm=NONE ctermbg=black ctermfg=brown<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>hi StatusLineNC cterm=NONE ctermbg=black ctermfg=darkgray<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span><span style="color:#008000">
</span></span></span><span style="display:flex;"><span><span style="color:#008000">&#34; Commenting blocks of code.</span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>augroup commenting_blocks_of_code<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>  autocmd!<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>  autocmd FileType c,cpp,go,scala   <span style="color:#00f">let</span> b:comment_leader = <span style="color:#a31515">&#39;// &#39;</span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>  autocmd FileType sh,ruby,python   <span style="color:#00f">let</span> b:comment_leader = <span style="color:#a31515">&#39;# &#39;</span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>  autocmd FileType conf,fstab       <span style="color:#00f">let</span> b:comment_leader = <span style="color:#a31515">&#39;# &#39;</span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>  autocmd FileType lua              <span style="color:#00f">let</span> b:comment_leader = <span style="color:#a31515">&#39;-- &#39;</span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>  autocmd FileType vim              <span style="color:#00f">let</span> b:comment_leader = <span style="color:#a31515">&#39;&#34; &#39;</span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>augroup END<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>noremap &lt;silent&gt; ,cc :&lt;C-B&gt;silent &lt;C-E&gt;s<span style="color:#a31515">/^/</span>&lt;C-R&gt;=escape(b:comment_leader,<span style="color:#a31515">&#39;\/&#39;</span>)&lt;CR&gt;/&lt;CR&gt;:nohlsearch&lt;CR&gt;<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>noremap &lt;silent&gt; ,cu :&lt;C-B&gt;silent &lt;C-E&gt;s<span style="color:#a31515">/^\V&lt;C-R&gt;=escape(b:comment_leader,&#39;\/&#39;)&lt;CR&gt;/</span>/e&lt;CR&gt;:nohlsearch&lt;CR&gt;<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span><span style="color:#008000">
</span></span></span><span style="display:flex;"><span><span style="color:#008000">&#34; Language specific indentation.</span><span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>filetype plugin indent on<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>autocmd Filetype make,go,c,cpp setlocal noexpandtab tabstop=4 shiftwidth=4<span style="">
</span></span></span><span style="display:flex;"><span><span style=""></span>autocmd Filetype html,js,css setlocal expandtab tabstop=2 shiftwidth=2<span style="">
</span></span></span></code></pre><p>I keep it pretty vanilla so this is about everything I have in the file.</p>


guid: https://mitjafelicijan.com/extract-lines-from-file-with-sed.html
title: Extract lines from a file with sed
url: https://mitjafelicijan.com/extract-lines-from-file-with-sed.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Easy way to extract line ranges (from line 200 to line 210) with sed.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sed -n <span style="color:#a31515">&#39;200,210p&#39;</span> data/Homo_sapiens.GRCh38.dna.chromosome.18.fa
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># then pipe it to a new file with</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>sed -n <span style="color:#a31515">&#39;200,210p&#39;</span> data/Homo_sapiens.GRCh38.dna.chromosome.18.fa &gt; new.fa
</span></span></code></pre><p><code>head</code> or <code>tail</code> could be used to extract from begining of the end of the file.</p>


guid: https://mitjafelicijan.com/dcss-online-rc-defaults.html
title: Sane default for Dungeon Crawl Stone Soup Online edition
url: https://mitjafelicijan.com/dcss-online-rc-defaults.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I mostly play Dungeon Crawl Stone Soup online on Ohio, USA: cbro.berotato.org server and
when you start playing you can select the version you want to play. Each instance also
has <code>rc</code> file that can customize the way the game behave.</p>
<p>This is my sane defaults config. It zooms in the game without needing to zoom in the
browser and it also adds a bit of delays in exploring and it stops at fight.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>autofight_stop = <span style="color:#a31515">80</span>
</span></span><span style="display:flex;"><span>explore_auto_rest = <span style="color:#a31515">true</span>
</span></span><span style="display:flex;"><span>explore_delay = <span style="color:#a31515">20</span>
</span></span><span style="display:flex;"><span>default_manual_training = <span style="color:#a31515">true</span>
</span></span><span style="display:flex;"><span>travel_open_doors = <span style="color:#a31515">false</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>tile_cell_pixels = <span style="color:#a31515">64</span>
</span></span><span style="display:flex;"><span>tile_font_crt_size = <span style="color:#a31515">32</span>
</span></span><span style="display:flex;"><span>tile_font_stat_size = <span style="color:#a31515">32</span>
</span></span><span style="display:flex;"><span>tile_font_msg_size = <span style="color:#a31515">32</span>
</span></span><span style="display:flex;"><span>tile_font_tip_size = <span style="color:#a31515">32</span>
</span></span><span style="display:flex;"><span>tile_font_lbl_size = <span style="color:#a31515">32</span>
</span></span><span style="display:flex;"><span>tile_map_pixels = <span style="color:#a31515">0</span>
</span></span><span style="display:flex;"><span>tile_filter_scaling = <span style="color:#a31515">false</span>
</span></span></code></pre><p>All the possible options are documented in the <a href="https://github.com/crawl/crawl/blob/master/crawl-ref/docs/options_guide.txt">Dungeon Crawl Stone Soup Options
Guide</a>
file.</p>


guid: https://mitjafelicijan.com/uninstall-ollama-from-a-linux-box.html
title: Uninstall Ollama from a Linux box
url: https://mitjafelicijan.com/uninstall-ollama-from-a-linux-box.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>I have had some issues with Ollama not being up-to-date. If Ollama is installed with a curl command, it adds a systemd service.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>sudo systemctl stop ollama
</span></span><span style="display:flex;"><span>sudo systemctl disable ollama
</span></span><span style="display:flex;"><span>sudo rm /etc/systemd/system/ollama.service
</span></span><span style="display:flex;"><span>sudo systemctl daemon-reload
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>sudo rm /usr/local/bin/ollama
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>sudo userdel ollama
</span></span><span style="display:flex;"><span>sudo groupdel ollama
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>rm -r ~/.ollama
</span></span><span style="display:flex;"><span>sudo rm -rf /usr/share/ollama
</span></span></code></pre><p>That is about it.</p>


guid: https://mitjafelicijan.com/converting-valgrind-callgrinds-to-svg-format.html
title: Converting Valgrind callgrinds to SVG format
url: https://mitjafelicijan.com/converting-valgrind-callgrinds-to-svg-format.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>Lately I have been doing a lot of systems programming and profiling is
the name of the game when it comes to developing good software.</p>
<p>I found <a href="https://valgrind.org">Valgrind</a> indispensable for profiling
and getting callgraphs.</p>
<p>Most of the time there are better alternatives that SVG to drill intro the
callgraphs but if you need to put put a callgraph on a webpage or maybe
send it to somebody that does not have all of the necessary software to
view these things then SVG is the perfect format for this.</p>
<p>Theses are couple of amazing applications to view callgraphs that get
exported by <a href="https://valgrind.org">Valgrind</a>:</p>
<ul>
<li><a href="https://kcachegrind.github.io/html/Home.html">Kcachegrind</a> - Linux</li>
<li><a href="https://ceefour.github.io/wincachegrind/">WinCacheGrind</a> - Windows</li>
<li><a href="https://profilingviewer.com/">Profiling Viewer</a> - macOS</li>
</ul>
<p>This is how Kcachekrind looks with a callgraph loaded in. Not only that,
with Kcachegrind you can also explore assembly produced by the compiler
and get much more insight into the profile of your application.</p>
<figure>
<img src="/assets/posts/valgrind-callgrind-svg/kcachegrind.png" alt="Kcachekrind screenshot" />
</figure>
<p>After this point you will need couple of things installed on your
system. I will show how you do this on Fedora 39.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#008000"># Install valgrind which will do the actual profiling.</span>
</span></span><span style="display:flex;"><span>sudo dnf install valgrind
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Install Kcachegrind for local visualizing.</span>
</span></span><span style="display:flex;"><span>sudo dnf install kcachegrind
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#008000"># Install gprof2dot for conversion from .dot to .svg.</span>
</span></span><span style="display:flex;"><span>pip install gprof2dot  
</span></span></code></pre><p>Let's make a simple C program and test out profiling and the whole shebang.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">#include</span> <span style="color:#00f">&lt;stdio.h&gt;</span><span style="color:#00f">
</span></span></span><span style="display:flex;"><span><span style="color:#00f"></span>
</span></span><span style="display:flex;"><span><span style="color:#2b91af">int</span> main() {
</span></span><span style="display:flex;"><span>  printf(<span style="color:#a31515">&#34;Oh, hi Mark</span><span style="color:#a31515">\n</span><span style="color:#a31515">&#34;</span>);
</span></span><span style="display:flex;"><span>  <span style="color:#00f">return</span> 0;
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>Then let's compile, convert to dot and then SVG file.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>clang hi.c -o c-hi
</span></span><span style="display:flex;"><span>valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes ./c-hi
</span></span><span style="display:flex;"><span>gprof2dot --format=callgrind --output=out.c.dot --colormap=print callgrind.out.546168
</span></span><span style="display:flex;"><span>cat out.c.dot | dot -Tsvg &gt; out.c.svg
</span></span></code></pre><p>This gives us an SVG file like this.</p>
<figure>
<img src="/assets/posts/valgrind-callgrind-svg/out.c.svg" alt="SVG callgrind for C program" />
</figure>
<p>And this also works on other binaries.</p>
<p>Lets give Zig a go.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span><span style="color:#00f">const</span> std = @import(<span style="color:#a31515">&#34;std&#34;</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00f">pub</span> <span style="color:#00f">fn</span> main() !<span style="color:#2b91af">void</span> {
</span></span><span style="display:flex;"><span>  std.debug.print(<span style="color:#a31515">&#34;Oh, hi Mark!</span><span style="color:#a31515">\n</span><span style="color:#a31515">&#34;</span>, .{});
</span></span><span style="display:flex;"><span>}
</span></span></code></pre><p>Now repeat the whole compile, convert cycle.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>zig build-exe hi.zig --name zig-hi
</span></span><span style="display:flex;"><span>valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes ./zig-hi
</span></span><span style="display:flex;"><span>gprof2dot --format=callgrind --output=out.zig.dot --colormap=print callgrind.out.546168
</span></span><span style="display:flex;"><span>cat out.zig.dot | dot -Tsvg &gt; out.zig.svg
</span></span></code></pre><figure>
<img src="/assets/posts/valgrind-callgrind-svg/out.zig.svg" alt="SVG callgrind for Zig program" />
</figure>
<p>Now, to be fair
<a href="https://kcachegrind.github.io/html/Home.html">Kcachegrind</a> is much nicer
for local exploration and digging deep into the callgraphs, but the SVG
format can still provide valid information for documentation and things
of that nature.</p>


guid: https://mitjafelicijan.com/using-custom-software-with-github-actions-to-deploy-a-site.html
title: Using custom software with Github Actions to deploy a site
url: https://mitjafelicijan.com/using-custom-software-with-github-actions-to-deploy-a-site.html
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
content:
<p>By default, GitHub uses Jekyll for their site generator which is fine,
but it has some issues and the complexity is not really worth it for me.</p>
<p>You could argue that Jekyll is simple, which it is to some degree,
but it can become complicated quite quickly if you start adding your
own spin on things.</p>
<p>A while ago I wrote a simple static site generator called &quot;<a href="https://github.com/mitjafelicijan/jbmafp">jbmafp -
Just Build Me A Fucking Page</a>&quot;
which was a protest against <a href="https://gohugo.io">Hugo</a>. Hugo is fine but
again, if you try doing something that conflicts with the dogma they
prescribe you are in trouble.</p>
<p>I also moved this blog from self-hosted virtual machine to just GitHub
Pages. I didn't want to bother myself managing that server anymore. And
this presented a slight problem because I didn't want to use the default
<code>_docs</code> folder GitHub wants you to use, and I also didn't want to upload
<code>public</code> folder that gets generated to GitHub.</p>
<p>Thankfully, there is a way to use custom software to generate your site
like <code>jbmafp</code>.</p>
<p>To achieve this you need to create a file <code>.github/workflows/deploy.yaml</code>
in the root of your repository.</p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>name: Build and Deploy to Pages
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>on:
</span></span><span style="display:flex;"><span>  push:
</span></span><span style="display:flex;"><span>    branches: [<span style="color:#a31515">&#34;master&#34;</span>]
</span></span><span style="display:flex;"><span>  workflow_dispatch:
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>permissions:
</span></span><span style="display:flex;"><span>  contents: read
</span></span><span style="display:flex;"><span>  pages: write
</span></span><span style="display:flex;"><span>  id-token: write
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>concurrency:
</span></span><span style="display:flex;"><span>  group: <span style="color:#a31515">&#34;pages&#34;</span>
</span></span><span style="display:flex;"><span>  cancel-in-progress: <span style="color:#00f">false</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>jobs:
</span></span><span style="display:flex;"><span>  deploy:
</span></span><span style="display:flex;"><span>    environment:
</span></span><span style="display:flex;"><span>      name: github-pages
</span></span><span style="display:flex;"><span>      url: ${{ steps.deployment.outputs.page_url }}
</span></span><span style="display:flex;"><span>    runs-on: ubuntu-latest
</span></span><span style="display:flex;"><span>    steps:
</span></span><span style="display:flex;"><span>      - name: Checkout
</span></span><span style="display:flex;"><span>        uses: actions/checkout@v3
</span></span><span style="display:flex;"><span>      - name: Setup Pages
</span></span><span style="display:flex;"><span>        uses: actions/configure-pages@v3
</span></span><span style="display:flex;"><span>      - name: Run a multi-line script
</span></span><span style="display:flex;"><span>        run: |<span style="color:#a31515">
</span></span></span><span style="display:flex;"><span><span style="color:#a31515">          wget https://github.com/mitjafelicijan/jbmafp/releases/download/v0.1/jbmafp.zip
</span></span></span><span style="display:flex;"><span><span style="color:#a31515">          unzip jbmafp.zip
</span></span></span><span style="display:flex;"><span><span style="color:#a31515">          chmod +x jbmafp
</span></span></span><span style="display:flex;"><span><span style="color:#a31515">          ./jbmafp -b</span>          
</span></span><span style="display:flex;"><span>      - name: Upload artifact
</span></span><span style="display:flex;"><span>        uses: actions/upload-pages-artifact@v2
</span></span><span style="display:flex;"><span>        with:
</span></span><span style="display:flex;"><span>          path: <span style="color:#a31515">&#39;./public&#39;</span>
</span></span><span style="display:flex;"><span>      - name: Deploy to GitHub Pages
</span></span><span style="display:flex;"><span>        id: deployment
</span></span><span style="display:flex;"><span>        uses: actions/deploy-pages@v2
</span></span></code></pre><p>This is an example for <code>jbmafp</code>. When I execute <code>./jbmafp -b</code> the program
creates <code>public</code> folder and puts all content there. And the directive
<code>with: path: './public'</code> tells <code>actions/deploy-pages@v2</code> to look for
<code>public</code> folder instead of <code>docs</code> folder.</p>
<p>This can be used with anything, actually. Hugo, Gatsby, Astro, you
name it.</p>


title: The abysmal state of GNU/Linux and a case against shared object libraries
feedurl: https://mitjafelicijan.com/feed.xml
content_mime_type: text/html
guid:
https://mitjafelicijan.com/the-abysmal-state-of-gnu-linux-and-a-case-against-shared-object-libraries.html

url:
https://mitjafelicijan.com/the-abysmal-state-of-gnu-linux-and-a-case-against-shared-object-libraries.html

content:
<h2 id="personal-critique">Personal critique</h2>
<p>This is in part difficult to write since I have been daily driving
GNU/Linux for 20 years now, but I think it is necessary to be honest
about this.  How come GNU/Linux is worse than it was 10 years ago? This
may very well be a subjective opinion, GNU/Linux being better in the past,
or maybe I am looking at the situation with rose-tinted glasses.</p>
<blockquote>
<p>A full disclaimer, this weekend my system that is pretty vanilla
just decided to die after an update. And this was not a full version
upgrade. Just a normal update that I do many times per week.</p>
</blockquote>
<p>Sure, we now have <a href="https://www.pipewire.org/">PipeWire</a> and
<a href="https://wayland.freedesktop.org/">Wayland</a>. We enjoy many modern
advances and yet, the practical use for me is worse than it was 10 years
ago. Now all of a sudden, I can't rely on the system to be stable like
it was. I don't remember the system bricking after an update, or the
system becoming laggy after 10 days of uptime. This may be the issue with
<a href="https://fedoraproject.org/">Fedora</a>, though.</p>
<p>Over the years, I have daily driven many
distributions. From <a href="https://www.gentoo.org/">Gentoo</a>,
<a href="https://archlinux.org/">Arch</a>, <a href="https://fedoraproject.org/">Fedora</a>
to <a href="https://www.debian.org/">Ubuntu</a>. My best memories were always with
<a href="https://www.debian.org/">Debian</a>. Just pure Debian always proved to be
the most stable system. I never had issue or system breaking after an
update. I can't say the same for Fedora.</p>
<p>From the get-go, I had issues. I have an Nvidia card and even
booting presented issues on occasion. This never happened on
other distributions, though they had their problems. Updating the
system was basically an exercise in gambling. How come an operating
system that boasts with the stability is so unstable? And this was
not isolated to my main machine. This also happened on my <a href="https://www.cnet.com/reviews/lenovo-thinkpad-x220-review/">X220
ThinkPad</a>
with Fedora on.</p>
<p>Shared dependencies were a mistake! There, I said it! I understand
that disk space was limited back then and this was a legitimate
constraint. But this has given me more grief than any other thing. I am
all in for <a href="https://appimage.org/">AppImages</a> or something like that. I
don't care if these images are 10x bigger. Disk space now is plenty, and
they solve the issue with &quot;libFlac.8.so is missing&quot; and I have version
12 installed. Which comes with unnecessary symlinking, downloading of
older versions and hoping that this will resolve the issue.</p>
<p>Now, the biggest apologist of GNU/Linux will never admit this and
even saying something is wrong with this is considered a mortal sin. I,
however, am not concerned with cultist behaviors. This is bullshit! Things
should be better than 10 years ago, not worse. And I don't care how
much lipstick you put on this pig. After more than 20 years of using
Linux as my main system, I think I have earned a badge that gives me
the right to say the truth.</p>
<p>Regardless of all this, I am still a massive fan. I still think GNU/Linux
is probably the most unobtrusive operating system, bar none. But the
complexity has gotten the best of it. It's bloated and too complicated
at this point. Understandably, you can't have a modern operating system
that competes with alternatives without sacrificing simplicity. But I
still think that there is another way.</p>
<p>One of the best aspects of GNU/Linux must be outstanding package manager
support. Nevertheless, they are essentially solving a problem that should
have been solved and done with years ago. The number of gymnastics
that happen in the background for you to install a software is just
mind-boggling. The dependency graphs are insane. And Snaps and Flatpaks
tried to solve some of these things, but until a distribution comes out
that is completely devoid of shared dependencies, we will still live in
this purgatory.</p>
<p>Let's compare these two distributions when it comes to packages sizes
and shared object libraries and see how they fair.</p>
<h2 id="debian">Debian</h2>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>root@debian: cat /etc/os-release
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>PRETTY_NAME=<span style="color:#a31515">&#34;Debian GNU/Linux 12 (bookworm)&#34;</span>
</span></span><span style="display:flex;"><span>NAME=<span style="color:#a31515">&#34;Debian GNU/Linux&#34;</span>
</span></span><span style="display:flex;"><span>VERSION_ID=<span style="color:#a31515">&#34;12&#34;</span>
</span></span><span style="display:flex;"><span>VERSION=<span style="color:#a31515">&#34;12 (bookworm)&#34;</span>
</span></span><span style="display:flex;"><span>VERSION_CODENAME=<span style="color:#a31515">bookworm</span>
</span></span><span style="display:flex;"><span>ID=<span style="color:#a31515">debian</span>
</span></span><span style="display:flex;"><span>HOME_URL=<span style="color:#a31515">&#34;https://www.debian.org/&#34;</span>
</span></span><span style="display:flex;"><span>SUPPORT_URL=<span style="color:#a31515">&#34;https://www.debian.org/support&#34;</span>
</span></span><span style="display:flex;"><span>BUG_REPORT_URL=<span style="color:#a31515">&#34;https://bugs.debian.org/&#34;</span>
</span></span></code></pre><h3 id="top-20-packages-by-size">Top 20 packages by size</h3>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>dpkg-query -W --showformat=<span style="color:#a31515">&#39;${Installed-Size}\t${Package}\n&#39;</span> | sort -nr | head -n 20 | awk <span style="color:#a31515">&#39;{size=$1;unit=&#34;KB&#34;; if (size &gt;= 1024) {size=size/1024; unit=&#34;MB&#34;}; if (size &gt;= 1024) {size=size/1024; unit=&#34;GB&#34;}; printf &#34;%.2f %s\t%s\n&#34;, size, unit, $2}&#39;</span>
</span></span></code></pre><table>
<thead>
<tr>
<th>Size</th>
<th>Package</th>
</tr>
</thead>
<tbody>
<tr>
<td>651.87 MB</td>
<td>libwine</td>
</tr>
<tr>
<td>389.26 MB</td>
<td>linux-image-6.1.0-18-amd64</td>
</tr>
<tr>
<td>345.76 MB</td>
<td>brave-browser</td>
</tr>
<tr>
<td>323.74 MB</td>
<td>google-chrome-stable</td>
</tr>
<tr>
<td>265.31 MB</td>
<td>llvm-14-dev</td>
</tr>
<tr>
<td>225.76 MB</td>
<td>firefox-esr</td>
</tr>
<tr>
<td>141.77 MB</td>
<td>fluid-soundfont-gm</td>
</tr>
<tr>
<td>114.67 MB</td>
<td>libreoffice-core</td>
</tr>
<tr>
<td>113.41 MB</td>
<td>containerd.io</td>
</tr>
<tr>
<td>112.77 MB</td>
<td>libnvidia-rtcore</td>
</tr>
<tr>
<td>111.92 MB</td>
<td>libllvm15</td>
</tr>
<tr>
<td>106.56 MB</td>
<td>ibus-data</td>
</tr>
<tr>
<td>104.92 MB</td>
<td>libllvm14</td>
</tr>
<tr>
<td>99.20 MB</td>
<td>docker-ce</td>
</tr>
<tr>
<td>77.39 MB</td>
<td>docker-buildx-plugin</td>
</tr>
<tr>
<td>72.00 MB</td>
<td>libwebkit2gtk-4.1-0</td>
</tr>
<tr>
<td>71.93 MB</td>
<td>libwebkit2gtk-4.0-37</td>
</tr>
<tr>
<td>70.51 MB</td>
<td>libwebkitgtk-6.0-4</td>
</tr>
<tr>
<td>69.25 MB</td>
<td>nvidia-kernel-dkms</td>
</tr>
<tr>
<td>66.64 MB</td>
<td>gcc-12</td>
</tr>
</tbody>
</table>
<p>This is more or less a fresh system that is being used daily for work.</p>
<h3 id="number-of-packages-installed">Number of packages installed</h3>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>dpkg -l | grep <span style="color:#a31515">&#39;^ii&#39;</span> | wc -l
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>2217
</span></span></code></pre><h3 id="number-of-shared-object-libraries-on-system-so">Number of shared object libraries on system (*.so)</h3>
<p><em>Note: Some of them could be symlinks to each other so take this with
a grain of salt.</em></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>find /lib /lib64 /usr/lib /usr/lib64 -follow -type f -name <span style="color:#a31515">&#34;*.so.*&#34;</span> | wc -l
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>5156
</span></span></code></pre><h3 id="shared-objects-sorted-by-size">Shared objects sorted by size</h3>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>find /lib /lib64 /usr/lib /usr/lib64 -type f -name <span style="color:#a31515">&#34;*.so.*&#34;</span> -exec du -h {} + | sort -rh | head -n 20
</span></span></code></pre><table>
<thead>
<tr>
<th>Size</th>
<th>Package</th>
</tr>
</thead>
<tbody>
<tr>
<td>113M</td>
<td>/usr/lib/x86_64-linux-gnu/libnvidia-rtcore.so.525.147.05</td>
</tr>
<tr>
<td>112M</td>
<td>/usr/lib/x86_64-linux-gnu/libLLVM-15.so.1</td>
</tr>
<tr>
<td>105M</td>
<td>/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1</td>
</tr>
<tr>
<td>70M</td>
<td>/usr/lib/x86_64-linux-gnu/libwebkit2gtk-4.1.so.0.12.8</td>
</tr>
<tr>
<td>70M</td>
<td>/usr/lib/x86_64-linux-gnu/libwebkit2gtk-4.0.so.37.67.8</td>
</tr>
<tr>
<td>69M</td>
<td>/usr/lib/x86_64-linux-gnu/libwebkitgtk-6.0.so.4.4.8</td>
</tr>
<tr>
<td>57M</td>
<td>/usr/lib/llvm-14/lib/libclang-cpp.so.14</td>
</tr>
<tr>
<td>45M</td>
<td>/usr/lib/x86_64-linux-gnu/libnode.so.108</td>
</tr>
<tr>
<td>43M</td>
<td>/usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.525.147.05</td>
</tr>
<tr>
<td>41M</td>
<td>/usr/lib/x86_64-linux-gnu/libnvidia-eglcore.so.525.147.05</td>
</tr>
<tr>
<td>31M</td>
<td>/usr/lib/x86_64-linux-gnu/libmozjs-102.so.102.15.1</td>
</tr>
<tr>
<td>30M</td>
<td>/usr/lib/x86_64-linux-gnu/libicudata.so.72.1</td>
</tr>
<tr>
<td>30M</td>
<td>/usr/lib/x86_64-linux-gnu/libclang-14.so.14.0.6</td>
</tr>
<tr>
<td>29M</td>
<td>/usr/lib/x86_64-linux-gnu/nvidia/current/libcuda.so.525.147.05</td>
</tr>
<tr>
<td>28M</td>
<td>/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-6.0.so.1.1.14</td>
</tr>
<tr>
<td>28M</td>
<td>/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.1.so.0.4.14</td>
</tr>
<tr>
<td>28M</td>
<td>/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.0.so.18.23.14</td>
</tr>
<tr>
<td>24M</td>
<td>/usr/lib/x86_64-linux-gnu/libnvidia-glvkspirv.so.525.147.05</td>
</tr>
<tr>
<td>23M</td>
<td>/usr/lib/x86_64-linux-gnu/libz3.so.4</td>
</tr>
<tr>
<td>22M</td>
<td>/usr/lib/x86_64-linux-gnu/libgs.so.10.00</td>
</tr>
</tbody>
</table>
<h2 id="fedora">Fedora</h2>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>root@fedora: cat /etc/os-release
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>NAME=<span style="color:#a31515">&#34;Fedora Linux&#34;</span>
</span></span><span style="display:flex;"><span>VERSION=<span style="color:#a31515">&#34;36 (Workstation Edition)&#34;</span>
</span></span><span style="display:flex;"><span>ID=<span style="color:#a31515">fedora</span>
</span></span><span style="display:flex;"><span>VERSION_ID=<span style="color:#a31515">36</span>
</span></span><span style="display:flex;"><span>VERSION_CODENAME=<span style="color:#a31515">&#34;&#34;</span>
</span></span><span style="display:flex;"><span>PLATFORM_ID=<span style="color:#a31515">&#34;platform:f36&#34;</span>
</span></span><span style="display:flex;"><span>PRETTY_NAME=<span style="color:#a31515">&#34;Fedora Linux 36 (Workstation Edition)&#34;</span>
</span></span><span style="display:flex;"><span>ANSI_COLOR=<span style="color:#a31515">&#34;0;38;2;60;110;180&#34;</span>
</span></span><span style="display:flex;"><span>LOGO=<span style="color:#a31515">fedora-logo-icon</span>
</span></span><span style="display:flex;"><span>CPE_NAME=<span style="color:#a31515">&#34;cpe:/o:fedoraproject:fedora:36&#34;</span>
</span></span><span style="display:flex;"><span>HOME_URL=<span style="color:#a31515">&#34;https://fedoraproject.org/&#34;</span>
</span></span><span style="display:flex;"><span>DOCUMENTATION_URL=<span style="color:#a31515">&#34;https://docs.fedoraproject.org/en-US/fedora/f36/system-administrators-guide/&#34;</span>
</span></span><span style="display:flex;"><span>SUPPORT_URL=<span style="color:#a31515">&#34;https://ask.fedoraproject.org/&#34;</span>
</span></span><span style="display:flex;"><span>BUG_REPORT_URL=<span style="color:#a31515">&#34;https://bugzilla.redhat.com/&#34;</span>
</span></span><span style="display:flex;"><span>REDHAT_BUGZILLA_PRODUCT=<span style="color:#a31515">&#34;Fedora&#34;</span>
</span></span><span style="display:flex;"><span>REDHAT_BUGZILLA_PRODUCT_VERSION=<span style="color:#a31515">36</span>
</span></span><span style="display:flex;"><span>REDHAT_SUPPORT_PRODUCT=<span style="color:#a31515">&#34;Fedora&#34;</span>
</span></span><span style="display:flex;"><span>REDHAT_SUPPORT_PRODUCT_VERSION=<span style="color:#a31515">36</span>
</span></span><span style="display:flex;"><span>PRIVACY_POLICY_URL=<span style="color:#a31515">&#34;https://fedoraproject.org/wiki/Legal:PrivacyPolicy&#34;</span>
</span></span><span style="display:flex;"><span>SUPPORT_END=<span style="color:#a31515">2023-05-16</span>
</span></span><span style="display:flex;"><span>VARIANT=<span style="color:#a31515">&#34;Workstation Edition&#34;</span>
</span></span><span style="display:flex;"><span>VARIANT_ID=<span style="color:#a31515">workstation</span>
</span></span></code></pre><h3 id="top-20-packages-by-size-1">Top 20 packages by size</h3>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>rpm -qa --queryformat <span style="color:#a31515">&#39;%{SIZE}\t%{NAME}\n&#39;</span> | sort -rn | head -n 20 | awk <span style="color:#a31515">&#39;{size=$1;unit=&#34;B&#34;; if (size &gt;= 1024) {size=size/1024; unit=&#34;KB&#34;}; if (size &gt;= 1024) {size=size/1024; unit=&#34;MB&#34;}; if (size &gt;= 1024) {size=size/1024; unit=&#34;GB&#34;}; printf &#34;%.2f %s\t%s\n&#34;, size, unit, $2}&#39;</span>
</span></span></code></pre><table>
<thead>
<tr>
<th>Size</th>
<th>Package</th>
</tr>
</thead>
<tbody>
<tr>
<td>572.91 MB</td>
<td>google-cloud-sdk</td>
</tr>
<tr>
<td>559.76 MB</td>
<td>wine-core</td>
</tr>
<tr>
<td>530.12 MB</td>
<td>wine-core</td>
</tr>
<tr>
<td>383.76 MB</td>
<td>code</td>
</tr>
<tr>
<td>350.98 MB</td>
<td>golang-bin</td>
</tr>
<tr>
<td>318.04 MB</td>
<td>brave-browser</td>
</tr>
<tr>
<td>302.78 MB</td>
<td>google-chrome-stable</td>
</tr>
<tr>
<td>282.24 MB</td>
<td>libreoffice-core</td>
</tr>
<tr>
<td>273.43 MB</td>
<td>firefox</td>
</tr>
<tr>
<td>253.00 MB</td>
<td>ocaml</td>
</tr>
<tr>
<td>223.60 MB</td>
<td>proj-data-us</td>
</tr>
<tr>
<td>219.46 MB</td>
<td>zoom</td>
</tr>
<tr>
<td>217.81 MB</td>
<td>glibc-all-langpacks</td>
</tr>
<tr>
<td>199.31 MB</td>
<td>qemu-user</td>
</tr>
<tr>
<td>196.79 MB</td>
<td>edk2-aarch64</td>
</tr>
<tr>
<td>194.77 MB</td>
<td>fluid-soundfont-lite-patches</td>
</tr>
<tr>
<td>194.25 MB</td>
<td>java-17-openjdk-headless</td>
</tr>
<tr>
<td>176.75 MB</td>
<td>java-11-openjdk-headless</td>
</tr>
<tr>
<td>156.80 MB</td>
<td>pandoc</td>
</tr>
<tr>
<td>154.82 MB</td>
<td>qt5-qtwebengine</td>
</tr>
</tbody>
</table>
<p>What is interesting that the most of these packages are from a a system
that are daily in use.</p>
<h3 id="number-of-packages-installed-1">Number of packages installed</h3>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>dnf list installed | tail -n +3 | wc -l
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>3484
</span></span></code></pre><h3 id="number-of-shared-object-libraries-on-system-so-1">Number of shared object libraries on system (*.so)</h3>
<p><em>Note: Some of them could be symlinks to each other so take this with
a grain of salt.</em></p>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>find /lib /lib64 /usr/lib /usr/lib64 -follow -type f -name <span style="color:#a31515">&#34;*.so.*&#34;</span> | wc -l
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>8894
</span></span></code></pre><h3 id="shared-objects-sorted-by-size-1">Shared objects sorted by size</h3>
<pre tabindex="0" style="background-color:#fff;"><code><span style="display:flex;"><span>find /lib /lib64 /usr/lib /usr/lib64 -type f -name <span style="color:#a31515">&#34;*.so.*&#34;</span> -exec du -h {} + | sort -rh | head -n 20
</span></span></code></pre><table>
<thead>
<tr>
<th>Size</th>
<th>Package</th>
</tr>
</thead>
<tbody>
<tr>
<td>128M</td>
<td>/usr/lib64/libQt5WebEngineCore.so.5.15.10</td>
</tr>
<tr>
<td>55M</td>
<td>/usr/lib64/llvm13/lib/libclang-cpp.so.13</td>
</tr>
<tr>
<td>53M</td>
<td>/usr/lib64/libclang-cpp.so.14</td>
</tr>
<tr>
<td>50M</td>
<td>/usr/lib64/libwebkit2gtk-4.0.so.37.57.6</td>
</tr>
<tr>
<td>49M</td>
<td>/usr/lib64/libnode.so.93</td>
</tr>
<tr>
<td>45M</td>
<td>/usr/lib64/libOpenImageDenoise.so.1.4.3</td>
</tr>
<tr>
<td>33M</td>
<td>/usr/lib64/llvm13/lib/libclang.so.13.0.1</td>
</tr>
<tr>
<td>30M</td>
<td>/usr/lib64/libclang.so.14.0.5</td>
</tr>
<tr>
<td>29M</td>
<td>/usr/lib64/libopenvdb.so.9.0.0</td>
</tr>
<tr>
<td>28M</td>
<td>/usr/lib/libicudata.so.69.1</td>
</tr>
<tr>
<td>28M</td>
<td>/usr/lib64/libmozjs-78.so.0.0.0</td>
</tr>
<tr>
<td>28M</td>
<td>/usr/lib64/libicudata.so.69.1</td>
</tr>
<tr>
<td>26M</td>
<td>/usr/lib64/libusd_usd_ms.so.0</td>
</tr>
<tr>
<td>26M</td>
<td>/usr/lib64/libgdal.so.30.0.3</td>
</tr>
<tr>
<td>22M</td>
<td>/usr/lib64/libjavascriptcoregtk-4.0.so.18.21.6</td>
</tr>
<tr>
<td>22M</td>
<td>/usr/lib64/libgs.so.9.56</td>
</tr>
<tr>
<td>22M</td>
<td>/usr/lib64/google-cloud-sdk/platform/bundledpythonunix/lib/libpython3.9.so.1.0</td>
</tr>
<tr>
<td>17M</td>
<td>/usr/lib64/libgtkd-3.so.0.9.0</td>
</tr>
<tr>
<td>17M</td>
<td>/usr/lib64/libgeocoding.so.8.12</td>
</tr>
<tr>
<td>14M</td>
<td>/usr/lib64/libmfxhw64.so.1.35</td>
</tr>
</tbody>
</table>
<h2 id="quick-observation">Quick observation</h2>
<pre><code>/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-6.0.so.1.1.14
/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.1.so.0.4.14
/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.0.so.18.23.14
</code></pre>
<p>These three packages are probably used by three different applications,
and nothing else needs them. I could be mistaken, but in any case they
should just be packaged alongside the application that requires them
and be done with it.</p>
<h2 id="so-now-what">So, now what?</h2>
<p>The main point is that, yes these packages can be big, but if we are
honest, what would a couple of additional megabytes that would include
shared object libraries actually do? Probably nothing! And it would make
maintenance an entirely different game.</p>
<p>There is also this big elephant in the room, the users. They aren't
concerned about package dependencies. They don't care if an application
is 20 megabytes bigger. Nobody cares! But they certainly do care about
borked systems and non-working dependencies and hunting for solutions
for why <code>libFlac</code> was not found even though they have it installed
(allthough slightly different version).</p>
<p>Operating systems should abstract these complexities away from the
user. And I am not saying that the Linux kernel is at fault. I mean the
operating system as a whole.</p>
<p>This is why I am a massive proponent of
<a href="https://appimage.org/">AppImages</a>. Flatpaks and Snaps are OK, but they
still have their own package management and the whole dependency problem
because they try to optimize for space, and they sacrifice the simplicity.</p>
<p>It would be an interesting exercise to make a prototype distribution
that does not rely on shared objects, but has everything packed in
AppImages. Probably a foolish endeavor, but maybe worth looking into. I
sense this kind of distribution would be highly unusable. Interesting
how far we have gotten that this kind of distribution is almost not
possible anymore.</p>
<p>The year of the GNU/Linux desktop? I have strong doubts. We are in a
worse state than we were. Not only that, but the sheer amount of choice
is paralyzing at this point. This is very relatable to <a href="https://en.wikipedia.org/wiki/The_Paradox_of_Choice">The Paradox of
Choice</a>. The
more options we have, the worse it
gets. <a href="https://wayland.freedesktop.org/">Wayland</a> competing with
<a href="https://www.x.org/wiki/">X</a>. So many window managers, you just get
lost. So many choices. I have no idea if this is even salvageable,
or something new must be made.</p>
<p>A quick shoutout to <a href="https://www.appimagehub.com/">AppImageHub</a>. If
possible, I continually try to find applications there and take care of
updating them myself. I don't need hand holding or a constant up-to date
system. I just want my system to be stable and when some application has
gotten some significant new features I can download that myself. It's
about the choice and not being forced into this churn that requires
constant updating and keeping up with things. At this point, using
GNU/Linux is more like a second job, and I was so stoked when this was
not a case anymore in the past. This is why I feel like the last 10
years were a regression disguised as progress.</p>
<p>Some interesting talks and videos</p>
<ul>
<li><a href="https://www.youtube.com/watch?v=k0uE_chSnV8">Jonathan Blow on how an operating system should work</a></li>
<li><a href="https://www.youtube.com/watch?v=kZRE7HIO3vk">The Thirty Million Line Problem by Casey Muratori</a></li>
<li><a href="https://www.youtube.com/watch?v=nTCHapo8QFM">GNU is Bloated! by Luke Smith</a></li>
</ul>


