<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Sr Izan's Blog</title>
        <link>https://srizan.dev/blog</link>
        <description>My little donowall place on the net</description>
        <lastBuildDate>Wed, 08 May 2024 19:45:59 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <image>
            <title>Sr Izan's Blog</title>
            <url>https://srizan.dev/pfp.png</url>
            <link>https://srizan.dev/blog</link>
        </image>
        <copyright>Copyleft 2023, Sr Izan</copyright>
        <atom:link href="https://srizan.dev/blog/rss.xml" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[My tales of MongoDB migration]]></title>
            <link>https://srizan.dev/blog/2</link>
            <guid>https://srizan.dev/blog/2</guid>
            <pubDate>Sun, 12 Nov 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[Here I ramble about the last service migration I did, MongoDB, and all the difficulties that came with it.]]></description>
            <content:encoded><![CDATA[<h2>Introduction</h2>
<p>So, the last few months I&#39;ve been migrating services from my good old Raspberry Pi into my new HP server and the last service I migrated was MongoDB.</p>
<p>I&#39;ve been using MongoDB for a while now and I&#39;ve been using it for a few things, like my discord bots, <a href="https://github.com/SrIzan10/webhooks-ui">webhooks-ui</a> and probably other projects I don&#39;t remember right now.</p>
<p>So, let&#39;s get started!</p>
<h2>Testing the plan</h2>
<p>My database instance is on Docker with a replica set of 1 node (itself) so <a href="https://www.prisma.io/">Prisma</a> works.</p>
<p>My idea is to add the HP server as a secondary replica and then promote it to be the primary one, but I don&#39;t know if that will work, so we need to test some stuff.</p>
<p>I first created 2 docker containers on my <a href="https://gist.github.com/SrIzan10/50bc2ba689a4cc43bcbac2799cc733c9">main Ryzen machine</a>&#39;s WSL Ubuntu instance.</p>
<p>I created a <code>docker-compose.yml</code> file with the following content:</p>
<pre><code class="language-yml">version: &quot;3.8&quot;
services:
  mongo1:
    image: mongo:4.4.17-rc0-focal
    container_name: mongo1
    restart: always
    ports:
      - 27017:27017
    volumes:
      - ./mongo1:/data/db
    command: mongod --replSet mongoset
    networks:
      - mongo
  mongo2:
    image: mongo:4.4.17-rc0-focal
    container_name: mongo2
    restart: always
    ports:
      - 27018:27017
    volumes:
      - ./mongo2:/data/db
    command: mongod --replSet mongoset
    networks:
      - mongo
networks:
  mongo:
</code></pre>
<p>and ran it with <code>docker compose up -d</code>.</p>
<p>I went to connect with MongoDB Compass and it didn&#39;t work for some reason. I asked GPT and nothing. It looks like it accepted the connection but it won&#39;t connect, so I installed <code>mongosh</code> and tried to connect with that.</p>
<pre><code class="language-bash">$ mongosh mongodb://localhost:27017
</code></pre>
<p>...and it worked! That didn&#39;t make any sense, but okay, we can work with it.</p>
<p>I then connected to the <code>mongo1</code> instance and ran the following commands:</p>
<pre><code class="language-bash">&gt; rs.initiate()
</code></pre>
<p>and it worked, but only that same database connected. Before adding the second database to the replica, I went ahead and pinged it from the first container (just to check if the network configuration worked):</p>
<pre><code class="language-bash">docker exec mongo1 sh -c &quot;rm /bin/ping;apt update;apt install inetutils-ping -y;ping mongo2&quot;
</code></pre>
<p>I removed /bin/ping because I tried to transfer the binary from WSL to the container but it still needed some libraries and I didn&#39;t want to bother, so I just installed the package.</p>
<p>It worked, so I went ahead and added the second database to the replica set:</p>
<pre><code class="language-bash">&gt; rs.add(&quot;mongo2&quot;)
</code></pre>
<p>After waiting for it, the second database connected and everything was working fine. Let&#39;s create a collection and some documents on the primary replica (mongo1):</p>
<pre><code class="language-bash">&gt; use test
&gt; db.createCollection(&quot;test&quot;)
&gt; db.test.insertOne({ name: &quot;test&quot; })
</code></pre>
<p>and then, let&#39;s check if it&#39;s on the second replica (mongo2):</p>
<pre><code class="language-bash">$ mongosh mongodb://localhost:27017
</code></pre>
<pre><code class="language-bash">&gt; use test
&gt; db.getMongo().setReadPref(&quot;secondaryPreferred&quot;)
&gt; db.test.find()
</code></pre>
<p>and, yeah, that worked.</p>
<p>I don&#39;t really know if ORMs will read when connecting to the second replica, but for now it&#39;s fine as the main plan is on track.<br>So, to promote I connected to the primary replica (mongo1) and ran the following command:</p>
<pre><code class="language-bash">&gt; rs.stepDown()
</code></pre>
<p>And that worked! Woo! The second replica is now the primary one. We can now start <em>drum rolls please</em>:</p>
<h2>The migration</h2>
<p>This is it. We&#39;re doing it.</p>
<p>I went ahead and created a new docker-compose file on my server with the following content:</p>
<pre><code class="language-yml">version: &quot;3.8&quot;
services:
    mongo:
        image: mongo:4.4.17-rc0-focal
        container_name: mongodb
        restart: unless-stopped
        ports:
            - 27017:27017
        volumes:
            - ./mongo:/data/db
        command: mongod --replSet rs0
</code></pre>
<p>After deploying the stack, I connected using mongosh to the primary db and ran the following command:</p>
<pre><code class="language-bash">&gt; rs.add(&quot;ip&quot;)
</code></pre>
<p>and after waiting for a while it looked like it worked. I then connected to the new database and ran the following command to check if the replica cloned fine:</p>
<pre><code class="language-bash">&gt; db.getMongo().setReadPref(&quot;secondaryPreferred&quot;)
</code></pre>
<p>and let&#39;s just let the results speak for themselves:</p>
<pre><code class="language-bash">rs0 [direct: secondary] test&gt; show dbs
# author&#39;s note: some dbs are redacted for privacy reasons 
admin         80.00 KiB
api           80.00 KiB
ava           40.00 KiB
bask         168.00 KiB
config       144.00 KiB
local        348.00 KiB
vinci        428.00 KiB
rs0 [direct: secondary] test&gt; use vinci
switched to db vinci
rs0 [direct: secondary] vinci&gt; show tables
afk
birthdays
chatgpt
giveaways-enters
giveaways-message
padyama
suggestions
twitter
warns
youtube
rs0 [direct: secondary] vinci&gt; db.afk.find()
[
  {
    _id: ObjectId(&quot;sadfsad fsadfsdf&quot;),
    id: &#39;redacted&#39;,
    reason: &#39;redacted&#39;,
    __v: 0
  },
  {
    _id: ObjectId(&quot;asdfsadfadf&quot;),
    id: &#39;redacted&#39;,
    reason: &#39;readacted&#39;,
    __v: 0
  }
]
rs0 [direct: secondary] vinci&gt;
</code></pre>
<p>Nice. let&#39;s now try to write something to the database from Vinci:<br><img src="https://img.srizan.dev/Discord_a2iXkWYxwn.png" alt=""><br>That just worked and we can see it on the secondary replica:</p>
<pre><code class="language-bash">rs0 [direct: secondary] vinci&gt; db.afk.find({ id: &#39;703974042700611634&#39; })
[
  {
    _id: ObjectId(&quot;6550eccc6154a8c9030fe76a&quot;),
    id: &#39;703974042700611634&#39;,
    reason: &#39;test&#39;,
    __v: 0
  }
]
</code></pre>
<p>Let&#39;s now edit all .envs and change the database url to the new secondary one. For this I checked all dbs that I have and then go from top to bottom editing the secrets.</p>
<p>After that was done I needed to deploy all changes. I went ahead and created too many tabs on my terminal and ran the all deployment commands on each tab. At the same time.<br>I really hope that doesn&#39;t make my server run out of ram, because I&#39;m really short on that.</p>
<p>After executing all the commands I <code>rs.stepDown()</code>&#39;ed the primary Raspberry Pi replica and, as expected, the HP Server took over.</p>
<p>The last command of the day:</p>
<pre><code class="language-bash">&gt; rs.remove(&quot;ip&quot;)
</code></pre>
<p>...SIKE! I needed to check the logs of the containers to see if everything was working fine. The <code>api</code> and <code>vinci</code> to be exact.<br>This is because <code>api</code> runs Prisma and <code>vinci</code> runs the now defunct in my stack, <a href="https://mongoosejs.com/">mongoose</a>.</p>
<p>Luckily enough, both were fine, so I was free. Yay!</p>
<h2>Conclusion</h2>
<p>Welp, that was a lot of work. I&#39;m glad it&#39;s over. I got my HP server on July and it&#39;s now November and I just finished migrating.<br>Could I have done it in less time? Yes.<br>Was I lazy? Also yes.</p>
<p>So that answers all your questions.</p>
<p>I hope you enjoyed this my first blog post, and thankfully it was a big one.<br>This took 3 hours in total, but at the end of the day, it was worth it.</p>
<p>I&#39;ll see you in the next one!</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install osu! on Endeavour OS]]></title>
            <link>https://srizan.dev/blog/4</link>
            <guid>https://srizan.dev/blog/4</guid>
            <pubDate>Sun, 17 Dec 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[A guide on how to install osu! on Endeavour OS]]></description>
            <content:encoded><![CDATA[<p>Alright, so you want to install osu! on Endeavour OS. I just reinstalled my system. Two birds with one stone!<br>Based on <a href="https://wiki.archlinux.org/title/User:Katoumegumi">https://wiki.archlinux.org/title/User:Katoumegumi</a></p>
<h1>Backstory</h1>
<p>My Windows installation has been unstable since year 1 of my computer, and it even went to the point that when I open osu! sometimes it would just not work, black out my screen and play the last sound it was playing (see audio when a BSOD happens)<br>Yesterday I went to install <a href="https://osu.ppy.sh/home/changelog/stable40/20231217.1">the latest update</a>, click on restart, yadiyadiyada and unfortunately my computer CRASHED. I didn&#39;t feel nervous until I opened up the game to play a bit and find out that my skin was the default one.</p>
<p>Okay, strange, lemme open up the game...</p>
<p>It starts importing all beatmaps.</p>
<p>Okay then, a bit understandable because the update is all about difficulty calculator.</p>
<p>When it finishes, I go to my most recent plays.<br>Nothing.<br>Never played.<br>What?</p>
<p>I go into my collections.<br>They&#39;re still there.<br>Okay, but are the scores there?<br>NO!</p>
<p>Thus, after recovering my replays using a batch scripts that opens all <code>.osr</code> files in my <code>Data\r</code> folder, I just moved to linux, and this is a writeup on how I&#39;ve been installing the game since my first time in April.</p>
<p>Enjoy!</p>
<h1>Installation</h1>
<h2>Installing Wine</h2>
<p>We first need to install wine and winetricks, to do so run:</p>
<pre><code class="language-sh">sudo pacman -S wine
wget https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks
chmod +x winetricks
sudo mv ./winetricks /usr/local/bin/winetricks
</code></pre>
<h2>Preparing wineprefix</h2>
<p>We now need to install dependencies like fonts or dotnet to make osu! run correctly</p>
<pre><code class="language-sh">WINEARCH=win32 WINEPREFIX=~/.wineosu winetricks dotnet40 dotnet45 cjkfonts gdiplus
</code></pre>
<p><strong>(update 12/19/2023)</strong>: added <code>dotnet45</code> to make it work with <a href="https://github.com/l3lackShark/gosumemory/issues/140#issuecomment-1179663744">gosumemory</a></p>
<h2>Installing osu!</h2>
<p>Skipping this part, but basically download the installer and run it.<br>I already have my own 3-year-old installation with all my everything on it, so I&#39;m bind-mounting it.</p>
<p>Create a directory:</p>
<pre><code class="language-sh">mkdir ~/.wineosu/osu
</code></pre>
<p>And then I added the following fstab line:</p>
<pre><code class="language-sh">/mnt/HDD/osu! /home/srizan/.wineosu/osu none defaults,bind 0 0
</code></pre>
<h2>Trying to open it up</h2>
<p>Running <code>WINEARCH=win32 WINEPREFIX=~/.wineosu wine ~/.wineosu/osu/osu\!.exe</code> twice leads us in the osu! installer with no network connection found.</p>
<p>This is a bit easy to fix, as Wine itself yields this error if you scroll up a bit:</p>
<pre><code class="language-sh">01b0:err:winediag:process_attach Failed to load libgnutls, secure connections will not be available.
</code></pre>
<p>Looking the package up in the <a href="https://archlinux.org/packages/?q=libgnutls">Arch Linux repos</a>, a package called <code>lib32-gnutls</code> shows up which looks to be exactly what we want.</p>
<p>After installing it, the SSL connection worked and the game is going to sta- too bad!
<img src="/blog/img/osu-eOS/graphicsContext.png" alt=""><br>You thought that was gonna be IT!</p>
<p>It wants a GL context, which we don&#39;t have, so installing <a href="https://archlinux.org/packages/multilib-testing/x86_64/lib32-mesa/"><code>lib32-mesa</code></a> fixes it. Easy!</p>
<p>Now, the window is... dark? WHEN ARE WE DONE MAN?<br>Welp, when going to almost the top of the file, we can see this:</p>
<pre><code class="language-sh">0024:err:winediag:create_gl_drawable XComposite is not available, using GLXPixmap hack.
</code></pre>
<p>&quot;GLXPixmap hack&quot;?<br>The game is, according to peppy, held with duct tape, so no hacks are really going to work.</p>
<p>Here we go, <a href="https://archlinux.org/packages/multilib/x86_64/lib32-libxcomposite/">yet ANOTHER lib32 package</a> should fix it.</p>
<p>It opens up!<br><img src="/blog/img/osu-eOS/noaudio.mp4" alt=""></p>
<p>Yeah. Nice. No audio.<br>Browsing through the Arch forums I found <img src="https://bbs.archlinux.org/viewtopic.php?id=135032" alt="this post">, and I installed the three <code>lib32-alsa-plugins lib32-libpulse lib32-openal</code> packages.</p>
<p>And it started up! (too lazy to screenshot)</p>
<h2>Setting up the start script</h2>
<p>edit a file in <code>~/.wineosu/osu/start.sh</code> with the following contents:</p>
<pre><code class="language-sh">#!/usr/bin/env bash

# props to Katoumegumi for the original script, this is exactly the same one and it works wonders.
#export PATH=&quot;$HOME/.wineosu/osuwine/bin:$PATH&quot; #Use custom WINE version to run osu!
export WINEARCH=win32
export WINEPREFIX=&quot;$HOME/.wineosu&quot;
#export WINEFSYNC=1

#VSync. For some reason, some people had been getting input latency issues and for some reason, the fix is to set VSync to off.
export vblank_mode=0 #For AMD, Intel and others
export __GL_SYNC_TO_VBLANK=0 #For NVIDIA proprietary and open source &gt;=500

#export STAGING_AUDIO_PERIOD=10000

#start osu!
wine osu\!.exe
</code></pre>
<h2>Setting up the freedesktop entry</h2>
<p>Download the osu! logo:</p>
<pre><code class="language-sh">wget --output-document ~/.wineosu/osu/icon.png https://github.com/ppy/osu-wiki/raw/master/wiki/Brand_identity_guidelines/img/usage-full-colour.png
</code></pre>
<p>and finally edit a new file in the path <code>~/.local/share/applications/osu.desktop</code></p>
<pre><code>[Desktop Entry]
Type=Application
Comment=A free-to-play rhythm game inspired in Osu! Tataekae! Ouendan!
Icon=/home/&lt;username&gt;/.wineosu/osu/icon.png
Exec=/home/&lt;username&gt;/.wineosu/osu/start.sh
Path=/home/&lt;username&gt;/.wineosu/osu
GenericName=osu!
Name=osu!
StartupNotify=true
</code></pre>
<h1>that&#39;s it</h1>
<p>Way harder than I thought. If you want the command with all dependencies, type in:</p>
<pre><code class="language-sh">sudo pacman -S lib32-gnutls lib32-mesa lib32-alsa-plugins lib32-libpulse lib32-openal
</code></pre>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to change the user password in Arch if you forgot it]]></title>
            <link>https://srizan.dev/blog/3</link>
            <guid>https://srizan.dev/blog/3</guid>
            <pubDate>Thu, 23 Nov 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[This post was made for a certain person who loves to lose passwords]]></description>
            <content:encoded><![CDATA[<p>Alright, let&#39;s do this. Fast.<br>Disclaimer: this only works when the /home directory is on the same partition, which is the default option if you don&#39;t specify.</p>
<h1>Step 1: Boot up a live environment.</h1>
<p>For the sake of simplicity, I&#39;ll be using the Endeavour OS Galileo installation media, but <a href="https://command-not-found.com/arch-chroot">any linux distro should work</a></p>
<p>When you&#39;re in, open the terminal:<br><img src="https://img.srizan.dev/vmware_zCwt9ac9KE.png" alt=""></p>
<h1>Step 2: Mounting the linux distro</h1>
<p>Type in <code>lsblk</code>. This will show all mounted drives.<br><img src="https://img.srizan.dev/vmware_LPBNlTo9BI.png" alt=""></p>
<p>Locate the drive and partition where your installation is.<br>It&#39;s usually the partition with the most space. The space is on the size row (duh)<br>If you have multiple drives with the same size and want more info about the volumes, type in <code>fdisk -l</code>.</p>
<p>In my case it&#39;s <code>/dev/sda1</code>.</p>
<p>So let&#39;s mount the partition to the <code>/mnt</code> directory with <code>sudo mount /dev/sda1 /mnt</code>.  </p>
<h1>Step 3: Chrootin&#39;</h1>
<p>Chroot is a linux tool which basically changes the root directory to whatever directory you specify. This will be used to run the <code>passwd</code> command inside your installation&#39;s context.</p>
<p>Arch Linux has it&#39;s own chroot command which does some magic in the background to make it useable on this distro&#39;s environments.</p>
<pre><code class="language-sh">sudo arch-chroot /mnt
</code></pre>
<p>should chroot into your installation and after a few seconds a shell will show up!<br><img src="https://img.srizan.dev/vmware_nyyqOA9ELo.png" alt=""></p>
<p>And now one last command, the one that actually changes the password:</p>
<pre><code class="language-sh">passwd yourusername
</code></pre>
<p>and boom! that&#39;s it! impressive, right? <code>exit</code> off the console and then reboot.</p>
<h1>The end</h1>
<p>That was quick.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Welcome to my new blog!]]></title>
            <link>https://srizan.dev/blog/1</link>
            <guid>https://srizan.dev/blog/1</guid>
            <pubDate>Thu, 08 Aug 2024 00:00:00 GMT</pubDate>
            <description><![CDATA[This post welcomes you to my new blog]]></description>
            <content:encoded><![CDATA[<h1>Hey!</h1>
<p>This is probably the last time I&#39;m going to make a blog. I&#39;ve made a few in the past, but I&#39;ve never really stuck to them. I&#39;m hoping that this time will be different.<br>This one was made entirely from scratch using React and Markdown, initially trying to use MDX, but it was a pain to set up, and it didn&#39;t end up working in the end.<br>I&#39;m hoping to post about my projects, and maybe some other stuff too. I&#39;m not sure yet, but I&#39;ll figure it out as I go along.<br>Anyways, thank you for reading. I hope you enjoyed my UX/UI for this one!</p>
<p>PD: I need some help for making the blog text look good and readable, so hit me up on my Discord if you have any ideas.</p>
]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Releasing sern Automata v2]]></title>
            <link>https://srizan.dev/blog/5</link>
            <guid>https://srizan.dev/blog/5</guid>
            <pubDate>Wed, 08 May 2024 18:46:01 GMT</pubDate>
            <content:encoded><![CDATA[<p>As once our lord and savior Terry A. Davis said, <a href="https://www.goodreads.com/quotes/10480697-an-idiot-admires-complexity-a-genius-admires-simplicity-a-physicist">&quot;An idiot admires complexity, a genius admires simplicity.&quot;</a><br>And, welp, that&#39;s what I just did with my github bot Automata.</p>
<h1>v1</h1>
<p>Automata v1 was a real mess. We were supposed to publish a next.js website, a jobs system to make our lives easier, and a large etc.</p>
<p>Now, I&#39;ve been working on this for quite a while (about a year) and I felt like I wasn&#39;t going anywhere. So I just thought about it we could run the automation scripts on Github Actions, right?</p>
<h1>So I got to work</h1>
<p>And in 4 days I got the whole thing working. I&#39;m really proud of it.</p>
<p>We send API requests to Github whenever we want to trigger a workflow, on demand, by using the webhook system and handling everything from there.<br>As a bonus I also added a command, so we could merge on a more controlled way, specially on larger PRs.</p>
<h2>Unexpected bugs on prod just after the PR merge</h2>
<p>There were some bugs on launch.</p>
<ul>
<li>I didn&#39;t have a start script nor a license <a href="https://github.com/sern-handler/automata/commit/05c6ac3b81740ab9dcf86155b16afc84e7c850c8">(commit)</a></li>
<li>I forgot to change some environment variable names on index.ts <a href="https://github.com/sern-handler/automata/commit/6e5d21ce548db04e9926ef7dfc3c1a5945d61aed">(commit)</a></li>
<li>A day later, forgot to listen on the <code>PORT</code> environment variable <a href="https://github.com/sern-handler/automata/commit/622d6e72ded4330e06e802432677855a5397cedc">(commit)</a></li>
<li>Squash and merge by default (ended up regretting it, see below) <a href="https://github.com/sern-handler/automata/commit/65ccede477f509c2e2de27be40a78281b79cda18">(commit)</a></li>
<li>I FORGOT TO CHECK IF THE COMMAND MENTIONED @SERNBOT <a href="https://github.com/sern-handler/automata/commit/a5e58a415423eace3a8b0d6fbc4fe43e050c0624">(commit)</a></li>
</ul>
<p>That last one was a real pain, as I detected the bug in production, on the most important PR of the week, if not the month: the website&#39;s move to starlight docs.
<img src="/blog/img/sernAutomataV2/prMerge1.png" alt=""><br><img src="/blog/img/sernAutomataV2/prMerge2.png" alt=""></p>
<h1>Conclusion</h1>
<p>Wow, a project with good DevEx? SIGN ME UP!</p>
<p>PD: I created a next.js template with my preferred tech stack, make sure to check it out! <a href="https://stack.srizan.dev">link</a></p>
]]></content:encoded>
        </item>
    </channel>
</rss>