<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://asalle.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://asalle.github.io/" rel="alternate" type="text/html" /><updated>2025-05-07T18:04:12+00:00</updated><id>https://asalle.github.io/feed.xml</id><title type="html">Asalle’s attic</title><subtitle>Little place for my coding ideas/lifehacks/aha-moments.</subtitle><entry><title type="html">Katzen</title><link href="https://asalle.github.io/cats/2025/05/07/cats.html" rel="alternate" type="text/html" title="Katzen" /><published>2025-05-07T17:42:20+00:00</published><updated>2025-05-07T17:42:20+00:00</updated><id>https://asalle.github.io/cats/2025/05/07/cats</id><content type="html" xml:base="https://asalle.github.io/cats/2025/05/07/cats.html"><![CDATA[<h1 id="katzen-bedienungsanleitung-für-7-tage">Katzen Bedienungsanleitung für 7 Tage</h1>

<ul>
  <li>Füttern</li>
</ul>

<p>1 Naßes Futter<br />
Einmal oder zweimal pro Tag eine Portion naßes Futter zwischen beiden teilen (ich füttere sie normalerweise einmal um 9 Uhr Morgens und einmal um 7 Uhr Abends)
Naßes Fütter ist in der Küche.</p>

<p>2 Trockenes Futter<br />
Checken Sie bitte ob der Futterautomat funktioniert. Manchmal stoppt er und zeigt ERR-01, in diesem Fall, aus und einstecken Sie es bitte zum Neustart - normalerweise zeigt es die aktuelle Zeit.</p>

<p>Je 3 Tage checken Sie ob es genugend Trockenfutter im Futterautomat gibt’s. Das Trockenfutter ist neben dem naßen Futter in der Küche.</p>

<ul>
  <li>Wasser</li>
</ul>

<p>Bitte wechseln Sie das Wasser im Wassercontainer je 3 Tage, also wärend diese Woche nur ein Mal, ich mach’s wenn ich wieder da bin.</p>

<ul>
  <li>Klo</li>
</ul>

<p>Je 3 Tage fügen Sie bitte etwa Klumpenstreu ins Klo, folgen Sie diesem Algorithmus:<br />
  1 Schalten Sie das Klo aus (einfach aus der Steckdose, weißer Kabel)<br />
  2 Fügen Sie bitte etwa Klumpenstreu hinzu - wichtig, nicht mehr als die MAX Linie zeigt<br />
  3 Schalten Sie das Klo wieder ein.<br />
  4 (Optional) Drücken Sie die Knopf unter dem Display - dann dreht sich das Klo und man kann checken of alles richtig gegangen ist.</p>

<p>Auch wenn Sie das Klumpenstreu hinzufügen, entleeren Sie bitten den Abfallbeutel (Die Müllsäcke sind oben auf dem Regal, weiße Beutel). Nur ein Mal reicht.</p>

<ul>
  <li>Spielen</li>
</ul>

<p>Bitte spielen Sie so lange und oft wie Sie wollen! Die beiden lieben es! Der graue magt Pinseln und Mäuse und der getiegerte  magt Bälle.</p>]]></content><author><name></name></author><category term="cats" /><category term="cats" /><summary type="html"><![CDATA[Katzen Bedienungsanleitung für 7 Tage]]></summary></entry><entry><title type="html">Atomitc habits, org-habit and… habits!</title><link href="https://asalle.github.io/self-tracking/2020/06/21/org-habits.html" rel="alternate" type="text/html" title="Atomitc habits, org-habit and… habits!" /><published>2020-06-21T17:42:20+00:00</published><updated>2020-06-21T17:42:20+00:00</updated><id>https://asalle.github.io/self-tracking/2020/06/21/org-habits</id><content type="html" xml:base="https://asalle.github.io/self-tracking/2020/06/21/org-habits.html"><![CDATA[<p>After reading an incredible book “<a href="https://jamesclear.com/atomic-habits">Atomic Habits</a>” by James Clear I started to put more attention to my own habits. The analogy of changing the plane’s course 3.5 degrees got to me:</p>

<p><img src="/assets/habits/plane.jpg" alt="3.5-degree course chage landed the plane in Washington instead of NY" /></p>

<p>So, the first rule of consious habits: “Make it visible”. As a happy user of <code class="language-plaintext highlighter-rouge">org-mode</code> I couldn’t imagine a better place to put them, then <code class="language-plaintext highlighter-rouge">org-habit</code>.<br />
To use <code class="language-plaintext highlighter-rouge">org-habit</code> with <code class="language-plaintext highlighter-rouge">spacemacs</code> you need to enable it first as an org-module. Thankfully, there is a handy shortcut to display the contents of the variable, in our case - it’s <code class="language-plaintext highlighter-rouge">org-modules</code>:<br />
<code class="language-plaintext highlighter-rouge">SPC h d v</code> - then type <code class="language-plaintext highlighter-rouge">org-modules</code>
<em>I remember this mnemonic shortcut as <code class="language-plaintext highlighter-rouge">SPC</code> + <code class="language-plaintext highlighter-rouge">Help</code> + <code class="language-plaintext highlighter-rouge">Describe</code> + <code class="language-plaintext highlighter-rouge">Variable</code></em>. <br />
Scroll all the way down to the <code class="language-plaintext highlighter-rouge">Customize variable</code> line and click it.
After you’ve seen the contents of <code class="language-plaintext highlighter-rouge">org-modules</code> variable and actually see that <code class="language-plaintext highlighter-rouge">org-habit</code> is not enabled - put the tick in front of it and save (C-x C-s).</p>

<p><img src="/assets/habits/org-modules.png" alt="list of org-modules" /></p>

<p>Now all is left is to write down your habits. Let’s say I want to wear my posture corrector every day. Let’s look at this example habit:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>     ** TODO 15mins with posture corrector
        SCHEDULED: &lt;2020-06-20 Sat .+1d&gt;
        :PROPERTIES:
        :STYLE:    habit
        :END:  
</code></pre></div></div>
<p>It’s just a regular TODO entry, with a couple of changes:<br />
1) it’s scheduled to the time I want it to repeat (in my case, daily, for more details on scheduling see <a href="https://orgmode.org/manual/Deadlines-and-Scheduling.html">this</a>)
2) it includes a special tag <code class="language-plaintext highlighter-rouge">:STYLE: habit</code></p>

<p>Now, that we’ve created an actual habit, let’s take a look at it in the agenda view:<br />
<code class="language-plaintext highlighter-rouge">, a a</code> - to open agenda</p>

<p><img src="/assets/habits/consistency_graph.png" alt="habits in agenda view" /></p>

<p>This funny blue-yellow-red stripe is called “consistency graph” - at first I didn’t get what it means, but then I understood that it depicts a row of several days in the past and in the future. Green (or blue if it’s a new habit) on the left are days when checking the habit as <code class="language-plaintext highlighter-rouge">DONE</code> meant that you did it on time.<br />
One yellow thingy is likely today (means that habit is risking being late - org has so little faith in me :sigh:).</p>

<p>And the rest of red pieces depic all those days in the future when ticking the habit off would mean that you <del>lost</del> were late.<br />
The amount of days before and after today is changable by chaning the variables <code class="language-plaintext highlighter-rouge">org-habit-presceding-days</code> and <code class="language-plaintext highlighter-rouge">org-habit-following-days</code>.<br />
I guess they are there to make you motivated?.. (Don’t break the chain!..) Anyway, I don’t enjoy seeing so much red in my agenda so I changed the content of <code class="language-plaintext highlighter-rouge">org-habit-following-days</code> to 0.</p>

<p>Alright, now my agenda will bully me into following my habits every day! One pity is that in spacemacs+evil you cannot use K to toggle habits in agenda view,  I have to invoke the command by clicking <code class="language-plaintext highlighter-rouge">M-x org-habit-toggle-habits</code>. Also it is likely not supported by <a href="https://github.com/orgzly/orgzly-android">Orgzly</a> - an outliner that is semi-equal to org-mode on my phone.</p>

<p>What habits do you want to form? What do you want to get rid of? What are your ways to track habits? Letme on know via email.</p>

<p>P.S. I hightly recommend James’ newsletter - it really delivers what it promises.</p>]]></content><author><name></name></author><category term="self-tracking" /><category term="emacs," /><category term="spacemacs," /><category term="habits," /><category term="org-habit," /><category term="atomic" /><category term="habits" /><summary type="html"><![CDATA[After reading an incredible book “Atomic Habits” by James Clear I started to put more attention to my own habits. The analogy of changing the plane’s course 3.5 degrees got to me:]]></summary></entry><entry><title type="html">Improve quality of your photos, in batches</title><link href="https://asalle.github.io/tools/2020/05/10/batch-image-processing-imagemagick.html" rel="alternate" type="text/html" title="Improve quality of your photos, in batches" /><published>2020-05-10T08:06:20+00:00</published><updated>2020-05-10T08:06:20+00:00</updated><id>https://asalle.github.io/tools/2020/05/10/batch-image-processing-imagemagick</id><content type="html" xml:base="https://asalle.github.io/tools/2020/05/10/batch-image-processing-imagemagick.html"><![CDATA[<p>Image magick is an excellent command-line photo editor, it has a lot of features other image editors have, but because of its command-line nature, it can perform them on multiple images at a time.</p>

<p>I had a couple of basic image-improving changes to be performed on 5 of my photos. All of my photos have name of ‘IMG_*.jpg’. I put the processed photos into a separate folder just not to mix them up, folder is called <code class="language-plaintext highlighter-rouge">conv</code>.</p>

<h2 id="improve-brightnesscontrastthreshold">Improve brightness/contrast/threshold:</h2>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>convert ./IMG_*.jpg -level 25%,75%,2.0 ./conv/img.jpg
</code></pre></div></div>
<p>Command explained:</p>
<ul>
  <li><code class="language-plaintext highlighter-rouge">convert</code> is a utility made for converting images, it’s part of the imagemagick.</li>
  <li><code class="language-plaintext highlighter-rouge">./IMG_*.jpg</code> is a regular expression for the input files.</li>
  <li><code class="language-plaintext highlighter-rouge">-level</code> is imagemagick’s option that tells us that we want to change the image’s levels (brighness, contrast, …).</li>
  <li>numbers <code class="language-plaintext highlighter-rouge">25%</code> and <code class="language-plaintext highlighter-rouge">75%</code> stand for <code class="language-plaintext highlighter-rouge">white point</code> and <code class="language-plaintext highlighter-rouge">black point</code>. white point means “take all pixels that are equal to this value or lighter and make them completely white”, and black point means “take all pixels that are equal to this value or darker and make them completely black”. This will increase contrast and brightness of the image.</li>
  <li><code class="language-plaintext highlighter-rouge">2.0</code> stands for <code class="language-plaintext highlighter-rouge">gamma</code>, it’s for making the image lighter or darker in general, see more <a href="http://www.imagemagick.org/Usage/color_mods/#level_gamma">here</a>.</li>
  <li><code class="language-plaintext highlighter-rouge">./conv/img.jpg</code> is the name of the resulting image. We’ll get a bunch of images with the names <code class="language-plaintext highlighter-rouge">img_1.jpg</code> in the folder <code class="language-plaintext highlighter-rouge">conv</code>.</li>
</ul>

<p>See more on image levels <a href="http://www.imagemagick.org/Usage/color_mods/#levels">here</a>.</p>

<h2 id="crop-photos">Crop photos:</h2>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>convert ./IMG_*.jpg -crop 1330x1100+320+0  ./conv/img.png
</code></pre></div></div>
<p>Command explained:</p>
<ul>
  <li><code class="language-plaintext highlighter-rouge">convert</code> - as we already know is the name of the converting utility.</li>
  <li><code class="language-plaintext highlighter-rouge">./IMG_*.jpg</code> are the names on the input files</li>
  <li><code class="language-plaintext highlighter-rouge">-crop</code> is the name of the option</li>
  <li><code class="language-plaintext highlighter-rouge">1330x1100</code> - is the requested size of the cropped image.</li>
  <li><code class="language-plaintext highlighter-rouge">+320+0</code> - is the center of the crop.</li>
</ul>

<p>See more on crop <a href="http://www.imagemagick.org/Usage/crop/#crop">here</a>.</p>]]></content><author><name></name></author><category term="tools" /><category term="image-processing," /><category term="imagemagick," /><category term="handy-commands" /><summary type="html"><![CDATA[Image magick is an excellent command-line photo editor, it has a lot of features other image editors have, but because of its command-line nature, it can perform them on multiple images at a time.]]></summary></entry><entry><title type="html">Android Studio does not see my phone, but adb does!</title><link href="https://asalle.github.io/programming/2020/04/24/android-setup-woes.html" rel="alternate" type="text/html" title="Android Studio does not see my phone, but adb does!" /><published>2020-04-24T08:06:20+00:00</published><updated>2020-04-24T08:06:20+00:00</updated><id>https://asalle.github.io/programming/2020/04/24/android-setup-woes</id><content type="html" xml:base="https://asalle.github.io/programming/2020/04/24/android-setup-woes.html"><![CDATA[<p>So I wanted to fix some things in an open source android project.<br />
I looked it up briefly how to work with android sdk on emacs and decided that it’s going to be
easier to start with Android Studio, so I</p>
<ul>
  <li>installed android <a href="https://developer.android.com/studio/">studio</a> to /mnt/opt (my <code class="language-plaintext highlighter-rouge">/</code> filesystem is almost full :sweat_smile:)</li>
  <li>installed sdk</li>
  <li>installed adb  (<code class="language-plaintext highlighter-rouge">sudo dnf install android-tools</code>)</li>
  <li>created <code class="language-plaintext highlighter-rouge">plugdev</code> group (<code class="language-plaintext highlighter-rouge">sudo groupadd plugdev</code>)</li>
  <li>added myself to <code class="language-plaintext highlighter-rouge">plugdev</code> group (<code class="language-plaintext highlighter-rouge">sudo usermod -aG plugdev $LOGNAME</code>)</li>
</ul>

<p>Connected my phone to my computer, turned on USB debugging and all and there was… nothing.</p>

<p>Then I did <code class="language-plaintext highlighter-rouge">lsusb</code> to see if my phone is even reconizable via usb: no.<br />
Changed usb cable, ran lsusb again -&gt; yes!<br />
Ran <code class="language-plaintext highlighter-rouge">adb devices</code> - my device was not shown.
I have Fedora, so the udev rules are not originally where they should be so I liked them:</p>
<ul>
  <li>copied udev rules: <code class="language-plaintext highlighter-rouge">sudo cp /usr/share/doc/android-tools/51-android.rules /etc/udev/rules.d</code></li>
  <li>restarted udev: <code class="language-plaintext highlighter-rouge">sudo udevadm control --reload-rules</code></li>
  <li>found phone on <code class="language-plaintext highlighter-rouge">adb devices</code> -&gt; yeah!, but android studio still does not see it :thinking_face:</li>
  <li>started android studio with sudo - still does not work</li>
  <li>works only if I start Android studio with root</li>
  <li>works if I do this: <code class="language-plaintext highlighter-rouge">export ANDROID_HOME=&lt;the Android/Sdk folder&gt;</code> in <code class="language-plaintext highlighter-rouge">~/.profile</code> and <code class="language-plaintext highlighter-rouge">source ~/.profile</code> - many thanks to <a href="https://stackoverflow.com/a/51432157/3528539">Yu Shen</a>.
It seems that my “non-standard” path to sdk/android studio (<code class="language-plaintext highlighter-rouge">/mnt/opt</code>) was in the way.
But in the end it worked out 🐱.</li>
</ul>]]></content><author><name></name></author><category term="programming" /><category term="android," /><category term="sdk," /><category term="linux" /><summary type="html"><![CDATA[So I wanted to fix some things in an open source android project. I looked it up briefly how to work with android sdk on emacs and decided that it’s going to be easier to start with Android Studio, so I installed android studio to /mnt/opt (my / filesystem is almost full :sweat_smile:) installed sdk installed adb (sudo dnf install android-tools) created plugdev group (sudo groupadd plugdev) added myself to plugdev group (sudo usermod -aG plugdev $LOGNAME)]]></summary></entry><entry><title type="html">LaTex in spacemacs</title><link href="https://asalle.github.io/file-editing/2020/02/16/writing_latex_in_emacs.html" rel="alternate" type="text/html" title="LaTex in spacemacs" /><published>2020-02-16T18:37:20+00:00</published><updated>2020-02-16T18:37:20+00:00</updated><id>https://asalle.github.io/file-editing/2020/02/16/writing_latex_in_emacs</id><content type="html" xml:base="https://asalle.github.io/file-editing/2020/02/16/writing_latex_in_emacs.html"><![CDATA[<h1 id="steps-in-short">Steps in short</h1>
<ol>
  <li>Install latexmk: <code class="language-plaintext highlighter-rouge">sudo dnf install latexmk</code></li>
  <li>Add <a href="https://develop.spacemacs.org/layers/+lang/latex/README.html">latex</a> layer to spacemacs:
    <ul>
      <li><code class="language-plaintext highlighter-rouge">SPC f e d</code>  to open the <code class="language-plaintext highlighter-rouge">~.spacemacs</code> file;</li>
      <li>add <code class="language-plaintext highlighter-rouge">latex</code> to the <code class="language-plaintext highlighter-rouge">dotspacemacs-configuration-layers variable</code>;</li>
      <li><code class="language-plaintext highlighter-rouge">SPC f e R</code> to download layer and apply changes.</li>
    </ul>
  </li>
  <li>Open a .tex file and compile a pdf with <code class="language-plaintext highlighter-rouge">, b</code> or <code class="language-plaintext highlighter-rouge">latex/build</code></li>
</ol>

<p>If you, like me, enjoy working with 2 windows with code in the first one and the resulting pdf in the second one then do this:</p>
<ol>
  <li>Open a .tex file: <code class="language-plaintext highlighter-rouge">C-x C-f</code></li>
  <li>Divide your window in two: <code class="language-plaintext highlighter-rouge">SPC w /</code></li>
  <li>Go to the second window and open a pdf that you just build there.
If you see pdf as plan text - enable <code class="language-plaintext highlighter-rouge">doc-view-mode</code></li>
  <li>Change the .tex, press <code class="language-plaintext highlighter-rouge">, b</code> to rebuild and see changes applied in the second window.</li>
</ol>

<p><img src="/assets/latex.png" alt="two windows with latex and pdf" /></p>
<p style="text-align: center;"><i>it's a png so zoon in</i></p>

<p>Pro tip: regulate the width of both screens with going into <code class="language-plaintext highlighter-rouge">window-transient-state</code> (<code class="language-plaintext highlighter-rouge">SPC w ,</code>) and pressing <code class="language-plaintext highlighter-rouge">[</code> and <code class="language-plaintext highlighter-rouge">]</code>.</p>

<h1 id="story-behind">Story behind</h1>

<p>I like compiling things and having my documents version-controlled, that’s why I like tex.
I tried TexMaker and TexStudio but they both have funny UI.
I use spacemacs for my day-to-day, so I tried to give it a shot.
Turned out it’s quite decent.</p>]]></content><author><name></name></author><category term="file-editing" /><category term="latex," /><category term="tex," /><category term="emacs," /><category term="spacemacs" /><summary type="html"><![CDATA[Steps in short Install latexmk: sudo dnf install latexmk Add latex layer to spacemacs: SPC f e d to open the ~.spacemacs file; add latex to the dotspacemacs-configuration-layers variable; SPC f e R to download layer and apply changes. Open a .tex file and compile a pdf with , b or latex/build]]></summary></entry><entry><title type="html">Figure out the amount of free space on your disk</title><link href="https://asalle.github.io/tools/2019/11/17/figure-out-free-space-on-yo-dist.html" rel="alternate" type="text/html" title="Figure out the amount of free space on your disk" /><published>2019-11-17T18:37:20+00:00</published><updated>2019-11-17T18:37:20+00:00</updated><id>https://asalle.github.io/tools/2019/11/17/figure-out-free-space-on-yo-dist</id><content type="html" xml:base="https://asalle.github.io/tools/2019/11/17/figure-out-free-space-on-yo-dist.html"><![CDATA[<h1 id="steps-in-short">Steps in short</h1>

<p><code class="language-plaintext highlighter-rouge">df -h</code> will show you disk usage per filesystem.<br />
<code class="language-plaintext highlighter-rouge">du -h &lt;foldername&gt;/*</code> will show you file sizes in the specified folder.<br />
<code class="language-plaintext highlighter-rouge">docker system prune</code> may free astonishing amount of disk space sometimes.</p>]]></content><author><name></name></author><category term="tools" /><category term="du," /><category term="space," /><category term="hdd" /><summary type="html"><![CDATA[Steps in short]]></summary></entry><entry><title type="html">Installing Windows after Linux</title><link href="https://asalle.github.io/system-administration/2019/10/30/windows-fedora-dualboot.html" rel="alternate" type="text/html" title="Installing Windows after Linux" /><published>2019-10-30T18:37:20+00:00</published><updated>2019-10-30T18:37:20+00:00</updated><id>https://asalle.github.io/system-administration/2019/10/30/windows-fedora-dualboot</id><content type="html" xml:base="https://asalle.github.io/system-administration/2019/10/30/windows-fedora-dualboot.html"><![CDATA[<h1 id="steps-in-short">Steps in short</h1>

<ol>
  <li>Unmount the partition you want to cut.</li>
  <li>Cut a part of exising ext4 partition in gparted and make it “Unallocated”.</li>
  <li>Install windows in the “unallocated” space. This will create 2 new partitions: boot partition for windows and the actual windows partition.</li>
  <li>Reboot into linux. Linux will not notice the newly installed windows just yet.</li>
  <li>Update grub - <code class="language-plaintext highlighter-rouge">sudo grub2-mkconfig -o /boot/grub2/grub.cfg </code></li>
  <li>Reboot and you will see windows in grub menu.</li>
</ol>

<h1 id="story-behind">Story behind</h1>

<p>Until this very day I thought that installing windows after linux will make my life a living hell for a good couple of days. Never have I been so wrong. The cutting of my HDD went without any errors, which was probably the most risky part.</p>

<p>The moral of the story is: installing windows after linux is possible and even easy. Try it for yourself before you say it’s not :)</p>]]></content><author><name></name></author><category term="system-administration" /><category term="windows," /><category term="linux," /><category term="fedora," /><category term="dual-boot" /><summary type="html"><![CDATA[Steps in short]]></summary></entry><entry><title type="html">ccze is awesome!</title><link href="https://asalle.github.io/tools/2019/10/30/colorful-journalctl.html" rel="alternate" type="text/html" title="ccze is awesome!" /><published>2019-10-30T18:37:20+00:00</published><updated>2019-10-30T18:37:20+00:00</updated><id>https://asalle.github.io/tools/2019/10/30/colorful-journalctl</id><content type="html" xml:base="https://asalle.github.io/tools/2019/10/30/colorful-journalctl.html"><![CDATA[<p>I was skimming though journalctl logs of my project and I found it unfortunate that journalctl stripped all the colors… So I installed <code class="language-plaintext highlighter-rouge">ccze</code> to colorize them back!</p>

<p><code class="language-plaintext highlighter-rouge">sudo dnf install ccze</code></p>

<p>Using <code class="language-plaintext highlighter-rouge">ccze</code> couldn’t have been easier!</p>

<p><code class="language-plaintext highlighter-rouge">journalctl -u &lt;unitname&gt; -f | ccze</code></p>

<p>You can even colorize files with <code class="language-plaintext highlighter-rouge">tail</code>:</p>

<p><code class="language-plaintext highlighter-rouge">tail -f -n 50 file.txt | ccze</code></p>

<p>The only drawback is that you cannot input the enter lines in log, which was pretty handy in <code class="language-plaintext highlighter-rouge">journalctl</code>… Also, the colors that I have in <code class="language-plaintext highlighter-rouge">ccze</code> are not original colors from my logger, <code class="language-plaintext highlighter-rouge">ccze</code> reparsed by logs and added its own colors.</p>

<p>Still looks better than plain white text :)</p>]]></content><author><name></name></author><category term="tools" /><category term="journalctl," /><category term="colors," /><category term="ccze" /><summary type="html"><![CDATA[I was skimming though journalctl logs of my project and I found it unfortunate that journalctl stripped all the colors… So I installed ccze to colorize them back!]]></summary></entry><entry><title type="html">Lack of generics in go and a way to go around it in one particular case</title><link href="https://asalle.github.io/programming/2019/09/29/lack-of-generics-in-go.html" rel="alternate" type="text/html" title="Lack of generics in go and a way to go around it in one particular case" /><published>2019-09-29T19:37:20+00:00</published><updated>2019-09-29T19:37:20+00:00</updated><id>https://asalle.github.io/programming/2019/09/29/lack-of-generics-in-go</id><content type="html" xml:base="https://asalle.github.io/programming/2019/09/29/lack-of-generics-in-go.html"><![CDATA[<p>Let’s look into this particular case of handling two different things in our db:
we have apples and we have bananas and we want to check if they are in the db and if so – 
remove them. My background is C++, where one could do something like this:</p>

<figure class="highlight"><pre><code class="language-c--" data-lang="c++"><span class="k">class</span> <span class="nc">Apple</span><span class="p">{</span> 
    <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">id</span><span class="p">;</span>
    <span class="nl">public:</span>
    <span class="k">static</span> <span class="k">constexpr</span> <span class="n">std</span><span class="o">::</span><span class="n">string_view</span> <span class="n">table</span> <span class="o">=</span> <span class="s">"apple_tbl"</span><span class="p">;</span>
<span class="p">};</span>
<span class="k">class</span> <span class="nc">Banana</span><span class="p">{</span> 
    <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">id</span><span class="p">;</span>
    <span class="nl">public:</span>
    <span class="k">static</span> <span class="k">constexpr</span> <span class="n">std</span><span class="o">::</span><span class="n">string_view</span> <span class="n">table</span> <span class="o">=</span> <span class="s">"banana_tbl"</span><span class="p">;</span> 
<span class="p">};</span>

<span class="k">class</span> <span class="nc">DBDriver</span> 
<span class="p">{</span>
  <span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="nc">T</span><span class="p">&gt;</span>
  <span class="kt">bool</span> <span class="n">has</span><span class="p">()</span> 
  <span class="p">{</span>
    <span class="k">return</span> <span class="n">db</span><span class="o">-&gt;</span><span class="n">query</span><span class="p">(</span><span class="s">"Do you have %s?"</span><span class="p">,</span> <span class="n">T</span><span class="o">::</span><span class="n">table</span><span class="p">);</span>
  <span class="p">}</span>
  
  <span class="kt">bool</span> <span class="n">remove</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">string_view</span> <span class="n">id</span><span class="p">)</span> 
  <span class="p">{</span>
    <span class="k">return</span> <span class="n">db</span><span class="o">-&gt;</span><span class="n">query</span><span class="p">(</span><span class="s">"Remove %s of type %s then!"</span><span class="p">,</span> <span class="n">id</span><span class="p">,</span> <span class="n">T</span><span class="o">::</span><span class="n">table</span><span class="p">)</span>
  <span class="p">}</span>

  <span class="nl">private:</span>
  <span class="n">mysql</span><span class="o">::</span><span class="n">driver</span> <span class="o">*</span><span class="n">db</span><span class="p">;</span>
<span class="p">};</span></code></pre></figure>

<p>So what is there to do in go? I figured, if we have a function that takes an <code class="language-plaintext highlighter-rouge">apple-</code> or <code class="language-plaintext highlighter-rouge">bananaID</code> we can just partially apply it and pass it into a more general <code class="language-plaintext highlighter-rouge">remove</code> function like so and have minimal repeating code:</p>

<figure class="highlight"><pre><code class="language-go" data-lang="go"><span class="k">package</span> <span class="n">main</span>

<span class="k">type</span> <span class="n">driver</span> <span class="k">struct</span> <span class="p">{}</span>
<span class="k">func</span> <span class="p">(</span><span class="n">d</span> <span class="o">*</span><span class="n">driver</span><span class="p">)</span> <span class="n">hasApple</span><span class="p">(</span><span class="n">appleID</span> <span class="kt">string</span><span class="p">)</span> <span class="kt">bool</span> <span class="p">{</span>
    <span class="c">// some quering</span>
    <span class="k">return</span> <span class="no">false</span>
<span class="p">}</span>
   
<span class="k">func</span> <span class="p">(</span><span class="n">d</span> <span class="o">*</span><span class="n">driver</span><span class="p">)</span> <span class="n">hasBanana</span><span class="p">(</span><span class="n">bananaID</span> <span class="kt">string</span><span class="p">)</span> <span class="kt">bool</span> <span class="p">{</span>
    <span class="c">// some quering</span>
    <span class="k">return</span> <span class="no">false</span>
<span class="p">}</span>
    
<span class="k">func</span> <span class="p">(</span><span class="n">d</span> <span class="o">*</span><span class="n">driver</span><span class="p">)</span> <span class="n">deleteApple</span><span class="p">(</span><span class="n">appleID</span> <span class="kt">string</span><span class="p">)</span> <span class="p">{</span>
    <span class="c">// some deletion</span>
<span class="p">}</span>

<span class="k">func</span> <span class="p">(</span><span class="n">d</span> <span class="o">*</span><span class="n">driver</span><span class="p">)</span> <span class="n">deleteBanana</span><span class="p">(</span><span class="n">bananaID</span> <span class="kt">string</span><span class="p">)</span> <span class="p">{</span>
    <span class="c">// some deletion</span>
<span class="p">}</span>

<span class="k">var</span> <span class="n">db</span> <span class="o">=</span> <span class="n">driver</span><span class="p">{}</span>

<span class="k">func</span> <span class="n">deleteFruit</span><span class="p">(</span><span class="n">get</span> <span class="k">func</span><span class="p">()</span> <span class="kt">bool</span><span class="p">,</span> <span class="n">remove</span> <span class="k">func</span><span class="p">())</span> <span class="p">{</span>
    <span class="k">if</span> <span class="n">get</span><span class="p">()</span> <span class="p">{</span>
        <span class="n">remove</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>


<span class="k">func</span> <span class="n">DeleteApple</span><span class="p">(</span><span class="n">appleID</span> <span class="kt">string</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">get</span> <span class="o">:=</span> <span class="k">func</span><span class="p">()</span> <span class="kt">bool</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">db</span><span class="o">.</span><span class="n">hasApple</span><span class="p">(</span><span class="n">appleID</span><span class="p">)</span>
    <span class="p">}</span>
    <span class="n">remove</span> <span class="o">:=</span> <span class="k">func</span><span class="p">()</span> <span class="p">{</span>
        <span class="n">db</span><span class="o">.</span><span class="n">deleteApple</span><span class="p">(</span><span class="n">appleID</span><span class="p">)</span>
    <span class="p">}</span>
    
    <span class="n">deleteFruit</span><span class="p">(</span><span class="n">get</span><span class="p">,</span> <span class="n">remove</span><span class="p">)</span>
<span class="p">}</span>

<span class="k">func</span> <span class="n">DeleteBananas</span><span class="p">(</span><span class="n">bananaID</span> <span class="kt">string</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">get</span> <span class="o">:=</span> <span class="k">func</span><span class="p">()</span> <span class="kt">bool</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">db</span><span class="o">.</span><span class="n">hasBanana</span><span class="p">(</span><span class="n">bananaID</span><span class="p">)</span>
    <span class="p">}</span>
    <span class="n">remove</span> <span class="o">:=</span> <span class="k">func</span><span class="p">()</span> <span class="p">{</span>
        <span class="n">db</span><span class="o">.</span><span class="n">deleteApple</span><span class="p">(</span><span class="n">bananaID</span><span class="p">)</span>
    <span class="p">}</span> 
    <span class="n">deleteFruit</span><span class="p">(</span><span class="n">get</span><span class="p">,</span> <span class="n">remove</span><span class="p">)</span>
<span class="p">}</span></code></pre></figure>

<p>Does it work? Yes! Is it a good practice/idea? You tell me!</p>]]></content><author><name></name></author><category term="programming" /><category term="go," /><category term="generics," /><category term="clojure" /><summary type="html"><![CDATA[Let’s look into this particular case of handling two different things in our db: we have apples and we have bananas and we want to check if they are in the db and if so – remove them. My background is C++, where one could do something like this:]]></summary></entry><entry><title type="html">fedora and msi GS43VR</title><link href="https://asalle.github.io/programming/2019/07/13/Fedora-on-msi-gs43vr.html" rel="alternate" type="text/html" title="fedora and msi GS43VR" /><published>2019-07-13T20:14:20+00:00</published><updated>2019-07-13T20:14:20+00:00</updated><id>https://asalle.github.io/programming/2019/07/13/Fedora-on-msi-gs43vr</id><content type="html" xml:base="https://asalle.github.io/programming/2019/07/13/Fedora-on-msi-gs43vr.html"><![CDATA[<p>I’ve been using <a href="https://getfedora.org/">fedora</a> for half a year now and it’s great. The most amazing difference between fedora and debian-based distros I’ve been using so far are:</p>
<ul>
  <li>a concise and quick installation process</li>
  <li>newest versions of software already available for download with <code class="language-plaintext highlighter-rouge">dnf</code></li>
  <li>git, make and etc already pre-installed</li>
</ul>

<p>My other laptop, dell xps 13 (2018) works with it perfectly, including the graphics/sound card, so I decided to try it out with my msi gs43vr (2017).</p>

<p>Hardware: <a href="https://www.amazon.de/MSI-7RE-064DE-Phantom-Gaming-Laptop-i7-7700HQ/dp/B01MT5BOFS">msi gs43vr</a><br />
Software: <a href="https://getfedora.org/en/workstation/download/">Fedora 30-1.2</a></p>

<h1 id="aaand-here-goes-the-list-of-issues-ive-encountered">Aaand here goes the list of issues I’ve encountered.</h1>
<ol>
  <li>Graphical install hangs on <code class="language-plaintext highlighter-rouge">Started GNOME Display Manager.</code>.<br />
You will need to start the fedora installer in basic graphics mode with <code class="language-plaintext highlighter-rouge">Troubleshooting</code> -&gt; <code class="language-plaintext highlighter-rouge">Start fedora in basic graphics mode</code>.</li>
  <li>After installation, <code class="language-plaintext highlighter-rouge">gnome-initial-setup</code> pop ups every time after reboot.<br />
Just <code class="language-plaintext highlighter-rouge">touch ~/.config/gnome-initial-setup-done</code>. This will apply to current user only.</li>
  <li>When rebooted or shut down and then turned on, fedora froze with blank screen and only a blinking cursor for 2mins.<br />
At first I thouthg it’s graphics driver’s problem. Installation of a proper NVIDIA driver didn’t work though (I followed <a href="https://www.if-not-true-then-false.com/2015/fedora-nvidia-guide/">this</a> guide).<br />
What worked for me is removing <code class="language-plaintext highlighter-rouge">rhbs quiet</code> from <code class="language-plaintext highlighter-rouge">/etc/default/grub</code>. Don’t forget to run <code class="language-plaintext highlighter-rouge">grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg</code> to update grub.</li>
  <li>Super button not working<br />
Install <code class="language-plaintext highlighter-rouge">gnome-tweaks</code> and go to <code class="language-plaintext highlighter-rouge">Keyboard &amp; Mouse</code> -&gt; <code class="language-plaintext highlighter-rouge">Overview Shortcut</code> and toggle it.</li>
</ol>

<h1 id="lessons-learned">Lessons Learned</h1>
<ul>
  <li><a href="https://rpmfusion.org/Howto/NVIDIA#Determining_your_card_model">rpmfusion</a> drivers completely smashed my setup.</li>
</ul>

<h1 id="persisting-issues-id-like-to-have-some-help-with">Persisting issues I’d like to have some help with:</h1>
<ol>
  <li><del>Same blinking cursor + blank screen on shutdown.</del></li>
  <li><del>Screen brightness regulation buttons (f4&amp;f5) do not work, although volume regulation, keyboard lights and sleep buttons work.</del></li>
  <li><del>Suspend does not work(stuck forever on saving pages), however hibernate does.</del><br />
All of the above stopped when I installed the NVIDIA drivers according to this <a href="https://medium.com/@gokdeniz91/how-to-install-nvidia-drivers-on-fedora-29-8dd0485aba68">guide</a>.</li>
</ol>

<p>Still worth it!</p>]]></content><author><name></name></author><category term="programming" /><category term="fedora," /><category term="msi," /><category term="compatibility" /><summary type="html"><![CDATA[I’ve been using fedora for half a year now and it’s great. The most amazing difference between fedora and debian-based distros I’ve been using so far are: a concise and quick installation process newest versions of software already available for download with dnf git, make and etc already pre-installed My other laptop, dell xps 13 (2018) works with it perfectly, including the graphics/sound card, so I decided to try it out with my msi gs43vr (2017).]]></summary></entry></feed>