megacolorboy

Abdush Shakoor's Weblog

Writings, experiments & ideas.

I switched to Fedora 35

Switched from Void Linux to Fedora 35

Yes, I distro-hopped again but I guess it's a meaningful decision.

I was using Void Linux with an i3wm tiling manager setup to see if it would improve my programming productivity.

I've got to say that i3wm is an amazing tiling manager and if you are into tiling windows, this should be something worth of your time.

On the other hand, I thought of trying out Void Linux because I was tired of Ubuntu and it's bloat, whereas Void Linux is quite minimal and lightweight.

Then, why leave it?

It has a good package manager that is similar to Arch's AUR repository but the lack of documentation and updates made me feel that there's barely contributions for it.

I had issues using docker and virtualbox in it, often giving me compatibility issues at times, which left me frustrated.

Hello, Fedora!

When I decided to distro-hop, I had to give myself some time and research as to which distro would really suit me as a programmer and that would just work out of the box.

I wanted something that:

  • is developer-oriented.
  • stable but bleeding-edge.
  • just works out-of-the-box.
  • has a minimal and clean looking interface.

That's when Fedora came into the picture and according to what I have researched especially on forums like Reddit, it's directed towards programmers and sysadmins.

Another sellout point for me was RedHat because I use CentOS at my workplace to configure and deploy web applications.

RedHat developers are really dedicated and ensure that they push the stable yet bleeding-edge releases.

The installation process was smooth and the new Gnome 41 is a bliss.

I didn't want to use i3wm this time because I felt that I always tiled multiple terminal windows, so I thought I would replace that with tmux instead. And besides, I don't really want to spend a lot of time tinkering each and every part of my UI, I'd rather spend that time writing code that solves problems instead.

Let's see how long Fedora would last!

Until next time, then!

Count the number of matches of a pattern in VIM

You can the count the number of matches of a pattern by using the n flag while using the substitute command. Try the following command:

:%s/something//gn

If you want to know on how many lines it matches, just omit the g flag:

:%s/something//n

Hope this tip helped you out!

Count the number of word occurences in a text file using grep

If you are using a GUI based application like Microsoft Word of Google Docs, it would be easier for you to know the number of word occurences in a file. But what if you are in a terminal? That's where both grep and wc comes handy tools.

Let's say you have the following text:

The European languages are members of the same family. Their separate existence is a myth. For science, music, sport, etc, Europe uses the same vocabulary.

Now, you can use the grep and wc tool to count the number of times "the" appears in the file:

grep -o -i "the" file.txt | wc -l

Hope this helps you out!

Install MariaDB 10.3 on Void Linux

I tried to find a proper guide on how to install MySQL 8.0 on Void Linux but I couldn't really find any. So, I thought of installing MariaDB 10.3 on my laptop instead.

Don't worry about using MariaDB as it meets the same standard enterprised requirements as MySQL. The only difference is that MySQL belongs to Oracle and MariaDB is for people who wanted to get out of Oracle's hands.

Anyway, let's get started.

Prerequisites

  • Need to have root privileges in order to install packages.
  • Basic know-how of Void Linux and it's xbps package manager.

Alright, go ahead and follow these steps one-by-one:

1. Install MariaDB

Type the following command to install the package:

sudo xbps-install -S mariadb

2. Initialize MySQL data directory

The following command will initialize a MariaDB data directory and create system tables in the MySQL database, if they are not present.

mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

The options used:

  • --user: The login user name to use for running the mysqld process.
  • --basedir The path to the MariaDB installation directory.
  • --datadir: The path to the MariaDB directory.

To know more about it, you can refer to MariaDB's documentation.

3. Enable MySQL service

If you are used to Ubuntu or CentOS, enabling services in Void Linux is a bit different but quite simple. Once a process is symlinked, it will start on boot and restarts if it stops unless you stop the service deliberately.

Type the following command to enable the mysqld service:

sudo ln -s /etc/sv/mysqld /var/service/mysqld

4. Start MySQL service

Type the following command to start the mysqld service:

sudo sv start mysqld

To confirm, if the service is running, type the following:

sudo sv status mysqld

And you'll see something like this:

run: mysqld: (pid 15136) 1116s; run: log: (pid 15025) 1172s

5. Secure MySQL installation

It's recommended to secure your installation, so type the following command:

sudo mysql_secure_installation

Once the command is executed, you'll be prompted with a few questions, respond according to your needs and you're done!

6. Test MariaDB connection

Now, all you have to do is, try to log in to your database by typing the following:

mysql -u root -p

Once executed, it would prompt you for your password (which you must have set in the previous step and if you are able to log in, you are good to go!

Hope this guide helps you out!

Is SELinux complicated?

If you turn off SELinux for a living, try this.

This might look a rant post but hear me out, okay?

Ever deployed an application on CentOS and tried to figure out why it isn't working when it's caused due to some permission issue by SELinux enabled?

Yeah, I know how annoying that is. So, whenever I go on StackOverflow, many people suggest to completely turn it off.

Well, it might be tempting to type sudo setenforce 0 (which sets SELinux to Permissive mode), I wouldn't really recommend you to edit the SELinux config and disable it completely.

I recently read a blog post on CentOS's official blog and I'd like to quote them for asking this:

But why do articles feel the need to outright deactivate SELinux rather than help readers work through any problems they might have? Is SELinux that hard?

Good question. Is it really that hard or is it because we don't really understand it? I think it's the latter.

But why so?

I guess, as users, we really need some sort of user interface to receive feedback because not everyone is really good at the terminal and most importantly, not good at memorizing options and flag combinations.

Here's a sample error that I would face sometimes while deploying a Laravel web application on CentOS 7:

[Mon May 16 11:39:32.996441 2016] [:error] [pid 2434] [client XXX.XXX.XXX.XXX:8080] PHP Fatal error:  Uncaught UnexpectedValueException: The stream or file "/var/www/html/MYSITE/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/html/MYSITE/bootstrap/cache/compiled.php:13701
Stack trace:
#0 /var/www/html/MYSITE/bootstrap/cache/compiled.php(13635): Monolog\\Handler\\StreamHandler->write(Array)
#1 /var/www/html/MYSITE/bootstrap/cache/compiled.php(13396): Monolog\\Handler\\AbstractProcessingHandler->handle(Array)
#2 /var/www/html/MYSITE/bootstrap/cache/compiled.php(13494): Monolog\\Logger->addRecord(400, Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)
#3 /var/www/html/MYSITE/bootstrap/cache/compiled.php(13189): Monolog\\Logger->error(Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)
#4 /var/www/html/MYSITE/bootstrap/cache/compiled.php(13160): Illuminate\\Log\\Writer->writeLog('error', Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)
# in /var/www/html/MYSITE/bootstrap/cache/compiled.php on line 13701

By looking at this error, you do understand it's permission-related but it doesn't really indicate that it's an SELinux problem because there could be thousands of reasons why there could be such an error. And of course, when I look it up on Google, I do find many people facing the same issue due to SELinux being enabled.

Instead of disabling it completely, I would try doing this:

chcon -R -t httpd_sys_rw_content_t storage

And off goes the error and the application didn't give any permission-related issues again.

Is it worth disabling SELinux? No.

But does SELinux have an issue of being user friendly? I guess, yes.

I'm just like you, sometimes, I do switch off SELinux at times when it's critical to deploy the application so that I can leave home early but that's not really a good practice.

Conclusion

I do wish that the open source developers of SELinux could do something to make much more friendlier to use? Or maybe, some way that let's the user know what to do instead of letting the user chmod-ing and chown-ing files and directories endlessly. Or worse, completely disabling SELinux!

Hope you found this article interesting!

Stay tuned for more.

On learning new technologies

Sharing my tips on how I learn new technologies at work and home nowadays.

If you're a programmer, you already know that it's quite a daunting task to keep up with the latest stream of technologies:

  • Frameworks
  • Libraries
  • Programming Languages
  • Programming Paradigms

And there's never an end to it, it's just an ever-growing thing.

So, whenever I'm walking or commuting, sometimes, these questions pop up in my head:

  1. How can I learn something new without wasting my free-time?
  2. How can I learn all of the existing technologies out there? Is it possible?

Well, it's technically impossible for me to know about everything — in and out. Computer Science is such a broad field and has a lot of branches and sub-branches.

However, you can learn a piece of technology just enough to know that it exists and know when to learn more about it when the time arises.

Don't try to learn everything out there

In my years of developing web applications, I have seen two types of programmers:

  1. One who has deep knowledge of a particular technology
  2. An all-rounder but also not-so-deep knowledge about multiple technologies

Where do I fall ? Personally, I feel that I belong to the latter kind because I believe that spending a lot of time trying to specialize or being an expert in one technology is just too time-consuming and given the fact that everyday there's a new framework or programming language released out there, it's better to put yourself in the middle ground.

Why you ask? Here's why:

  1. Technology dies fast. For example, there was a time when jQuery used to be really popular amongst the Front End Developers but today, most of them move towards libraries like ReactJS, VueJS and NextJS to build their projects and sooner or later, another framework will come out to replace ReactJS and become the next thing.
  2. I don't think most of the technologies out there are relevant to the problem that you are trying to solve. Like why do I need to look into an API about geospatial analytics unless I'm trying to build an application that needs such a requirement, you get it right?

Basically, trying to learn every single piece of technology out there, it's just basically wasting time.

Ways and source of learning new stuff

Whenever I wanted to learn a new programming language, I would often go to Project Euler to flex my skills and that would help me learn more about it's features. Recently, I started LeetCode and Advent of Code - 2021. It's quite interesting solving these challenges as it helps you to learn more about the technology and feels good after solving a problem.

The next thing I would recommend is following a tech news feed like Hacker News but it can get quite addicting and distracting at times. Another good source of information are weekly newsletters. If you don't really know which one to follow, here's a repository filled with Awesome Newsletters that spans various areas like DevOps, Front end, Back end and Data Science. Try signing up on one of them and see how it goes.

Time is costly, use it wisely

The brain can only do so much in about 9 to 10 hours a day and in order for you to be efficient and productive in learning new stuff, try the following:

  1. Spend an hour learning, reading or practicing a new tool.
  2. Interesting stuff but not needed yet? Try bookmarking or make a note of it, so that you can revisit it again.
  3. If it fits your needs and project requirements, then go ahead and learn it!

If you found this article useful, please share it with your friends and colleagues.

Stay tuned for more!

How to create an ISO image from CDs/DVDs?

I used to create ISO images using DAEMON Tools but I wanted to try something different and see if there's a way to create it using the Linux CLI.

Turns out, you can do in just a single line using the dd utility like so:

dd if=/dev/cdrom of=/path/to/your/directory/image.iso

The if stands for input file and of stands for output file.

Looks like, I don't have to use DAEMON Tools for stuff like this, I guess.

Hope you found this tip useful!

Truncate a file using redirection in Linux

Simply put, sometimes, there are situations in where you just want to clear the contents of a file without deleting it.

This could be for many reasons like to avoid permission related issues, or maybe the file could be having useless logs that amasses to a size that measures in GBs.

So, the easiest solution is to clear it away from a terminal is by shell redirection like so:

:> filename

Let me break down the command here:

  • The : symbol means true and doesn't produce any output.
  • The '>' symbol is used for redirecting the output of the preceding command (in this case, it's empty!)
  • filename is the file that you want to truncate. If it doesn't exist, the file will be created.

Alternatively, you can do the same by using the cat command to output the contents of the /dev/null device (which only contains a EOL character) to empty a file:

cat /dev/null > filename

Hope this comes in handy!