Author Archives: stz184

How to use bootstrap icons in React project

There are a few ways to go about it but I found this way to be the easiest and simple. First of all, download the package and add it to your dependencies.

npm i bootstrap-icons --save

Then add this line to your styles.css file at the top of your index.js file

import 'bootstrap-icons/font/bootstrap-icons.css';

Now, whenever you write an HTML with i tag with the bi code like below, you’ll see the icon appear!

<i class="bi bi-house"></i>

For example, go to https://icons.getbootstrap.com/icons/house/ we can see the code to the right that the code snippet is indeed “bi bi-house” for the house icon.

PHP Warning: PHP Startup: mcrypt: Unable to initialize module

If you have installed multiple PHP versions using PPA maintained by Ondrej Surý you may end up with the following error message:

PHP Warning: PHP Startup: mcrypt: Unable to initialize module
Module compiled with module API=20190902
PHP compiled with module API=20170718

This is caused by a misconfiguration: the php.ini file is pointing to the latest version of mcrypt instead of the one compiled for PHP 7.2. To fix that you have to correct the path to the extension. Open the file for editing:


sudo vi /etc/php/7.2/cli/conf.d/mcrypt.ini

and replace extension=/usr/lib/php/20190902/mcrypt.so with extension=/usr/lib/php/20170718/mcrypt.so. Do the same for /etc/php/7.2/fpm/conf.d/mcrypt.ini file.

If you have the module mcrypt.so listed in /etc/php/7.2/cli/php.ini or /etc/php/7.2/fpm/php.ini – delete it to avoid “PHP Warning: Module ‘mcrypt’ already loaded in Unknown on line 0” error

Install the latest versions of Vagrant and VirtualBox on Linux Mint 19.2

I use Linux Mint 19.2 as daily driver on my ThinkPad L480. This step by step tutorial will guide you through the process of getting the latest versions of VirtualBox and Vagrant instead of the outdated versions available in the official Ubuntu repositories.

VirtualBox and Vagrant receive updates on Linux much often than the repositories update. If you want to consistently get these updates when they become available, you’ll want to add VirtualBox and Vagrant repository to your system. This will allow you to get notified for new versions and update trough Linux Mint Update Manager and apt.

Continue reading

Mask email address for GDPR reasons with JavaScript

This is a simple JavaScript function that will mask your email address following this pattern:

  • If it’s not an email, the input string will be returned without modification.
  • If the first part of the email is shorter than 4 characters, the entire username will be masked (me@example.com => *@e*****e.com)
  • If the domain part of the email is shorter than 4 symbols, the entire domain will be masked
    (username@abc.com => u******e@***.com
  • The TLD part (.com/.net/.org and etc) is never masked
  • If the input string contains multiple emails (for example the whole log message from the server), all email addresses found in the string will be processed.
/**
 * Mask email address with asterisks to comply GDPR
 * john.doe@example.com => j******e@e****e.com
 * @param {string} emailAddress email address
 * @returns {string} masked email address
 */
function maskEmailAddress (emailAddress) {
	function mask(str) {
		var strLen = str.length;
		if (strLen > 4) {
			return str.substr(0, 1) + str.substr(1, strLen - 1).replace(/\w/g, '*') + str.substr(-1,1);
		} 
		return str.replace(/\w/g, '*');
	}
	return emailAddress.replace(/([\w.]+)@([\w.]+)(\.[\w.]+)/g, function (m, p1, p2, p3) {		
		return mask(p1) + '@' + mask(p2) + p3;
	});
	
	return emailAddress;
}

return maskEmailAddress('random string username@example.com test');

10 things to to after installing WordPress blog

This guide provides a list of 7 things that you should do after installing a new WordPress site. Some of the steps are optional, but many others are essential if you want to comply with GDPR and Google AdSense policy, to have at least basic on-site SEO and manage the updates easier.

This guide provides links to other articles that will aid in your learning of WordPress content management system. Many of the steps refer to 3rd party sites where you can find more information on a particular topic.

After you have finished this guide, you will have easy to maintain SEO optimized website that complies to GDPR and Google AdSense policy. Continue reading

Batch rename files with Cyrillic filenames to Latin ones (transliterate file names)

If you have a bunch of files with Cyrillic file names, there is a chance that some old devices such as TV embedded players, car audio systems, mp3 players may not recognize them or fail to read. The quick and dirty solution is to rename these files to Latin only characters. In order to save some time I use this handy bash script. It works flawlessly on both Windows (Git Bash) and native Linux systems. Continue reading

This machine ID is already enabled with a different key or is non-unique

I have purchased new VPS and I wanted to enable Ubuntu live patch service for it. Unfortunately, the command canonical-livepatch enable [TOKEN] failed with this ugly error message:

This machine ID is already enabled with a different key or is non-unique.
Either “sudo canonical-livepatch disable” on the other machine, or regenerate a
unique /etc/machine-id on this machine with
“sudo rm /etc/machine-id /var/lib/dbus/machine-id && sudo systemd-machine-id-setup” :
{“error”: “Conflicting machine-id”}

I thought to myself “Ok, let’s try the suggested solution”. What I did was to backup the file /etc/machine-id, than delete it and run suggested systemd command. I was surprised to see the newly generated UUID was the same! Consulting with man page of systemd-machine-id-setup command revealed that “If run inside a KVM virtual machine and a UUID is configured (via the -uuid option), this UUID is used to initialize the machine ID. The caller must ensure that the UUID passed is sufficiently unique and is different for every booted instance of the VM.”. Obviously, my new VPS provider did not ensure that and somebody else has the same machine ID on his/her VPS and enabled Ubuntu live patch for it.

Continue reading

Vagrant: Authentication failure. Retrying…

I recently bought a newer laptop. It had Windows 8 preinstalled which I wiped immediately in order to install Linux Mint 19.1 and started to migrate data from my old machine. I packaged my vagrant box and transferred it to the new machine. Once imported the box back and issued vagrant up command I was surprised by the following errors:

Continue reading

Control screen backlight brightness from the command line

I have a Dell Latitude E5430 running Linux Mint 19 Tara. In Cinnamon, my function keys for brightness work correctly, but that was not the case with i3wm session. My first bet was to bind shortcuts executing xbacklight command but it doesn’t work because of this bug. So, I started to research for workaround and I found brightlight – “a program that can get and
set the screen backlight brightness on Linux systems using the kernel sysfs
interface.”. Sounds perfect but there are no prebuild binaries so you need to do it by yourself. The following steps are short guide how to build and install brightlight on Ubuntu and Ubuntu derivatives.

Continue reading

Putting HTML in inline JavaScript

A tag inside inline JavaScript string literal is interpreted by the HTML parser as a closing tag, causing syntax errors.
According to w3.org

Although the STYLE and SCRIPT elements use CDATA for their data model, for these elements, CDATA must be handled differently by user agents. Markup and entities must be treated as raw text and passed to the application as is. The first occurrence of the character sequence “</” (end-tag open delimiter) is treated as terminating the end of the element’s content. In valid documents, this would be the end tag for the element.

In real world scenario web browsers only end parsing a CDATA script block on an actual close-tag.
Unfortunately, there is no such special handling for script blocks in XHTML, causing < (or &) character to generate syntax errors if it is not properly escaped (i.e. HTML entity encoded).
There are different approaches to avoid such problems:

1) Encode the HTML string in base64 and decode it when reading
2) Split the <script> tag like that

var str = '</' + 'script' + '>';

3) Use CDATA

<script type="text/javascript">
//<![CDATA[
...code...
//]]>
</script>