Show complete URL in Brave browser

I’m currently playing around with the Brave browser and so far I like it a lot. However I’m not fond of the trend of hiding parts of the URL which some browsers do. I prefer simply reading the URL scheme myself instead of depending on some vague SSL lock icons or whatever. Here’s a quick tutorial for showing the complete URL bar in Brave.

Open a new tab and enter brave://flags or chrome://flags (doesn’t matter which, both work since both are based on the Chromium project).

In the filter/search bar, enter “hide”, this will bring up the relevant flags you need to edit.

Change the following flags to Disabled

Omnibox UI Hide Steady-State URL Scheme
Omnibox UI Steady-State URL Trivial Subdomains
Omnibox UI Hide Steady-State URL Path, Query and Ref

You can also use the following link shortcuts:

brave://flags/#omnibox-ui-hide-steady-state-url-scheme

brave://flags/#omnibox-ui-hide-steady-state-url-trivial-subdomains

brave://flags/#omnibox-ui-hide-steady-state-url-path-query-and-ref

See image below for your reference:

Argument list too long

Apparantly this stems from a limitation in the kernel regarding the size of command arguments. The Argument list is too long error message is typically shown if you try to run a command on a large filelist (for instance targeting files in a huge directory using wildcards), because the Linux kernel will split every target file found as separate arguments.

Say you have a directory containing three files; file1.txt, file2.txt, file3.txt. Running the command rm * in this directory will actually be interpreted as rm file1.txt file2.txt file3.txt by the kernel.

Two quick solutions comes to mind.

Using a for loop:

for f in /home/itdb/deleteme/*; do rm "$f"; done

Using the find command:

find /home/itdb/deleteme -name "*" -delete

For more information, check out this stackoverflow question:
https://stackoverflow.com/questions/11289551/argument-list-too-long-error-for-rm-cp-mv-commands

Simple trick for remembering tar parameters

You have probably looked up the parameters for tar more than you’ve changed socks. And what if the scenario from xkcd ever became real? Could you really run a valid tar command without googling first?

XKCD: “I don’t know what’s worse–the fact that after 15 years of using tar I still can’t keep the flags straight, or that after 15 years of technological advancement I’m still mucking with tar flags that were 15 years old when I started.”

Here’s a few tricks to help you remember how to use tar if you want to extract files from an archive, either .tar , .gz or tar.bz2

-xextract
-ffile

That’s it! All you need is tar -xf <filename>

Many guides will use -xvfz (or -xfzv or -xfvz or whatever), but -v and -z are not actually necessary.

-z is only used to tell tar it’s a .gz file, but for the last 15 years or so tar have been able to automatically detect this itself.

The other parameter, -v, is not necessary either, but it can be quite useful as it simply means verbose (extended/detailed) output in the terminal window.

So you if you want to see the progress of the file operation, include -v as well, so the final command becomes:

tar -xvf <filename>

Remember it by saying out loud: tar eXtract Verbose File <filename>

Or, as mentioned, simply use: tar -xf <filename> (tar eXtract File <filename>)

How to restart KDE Plasma shell if it freezes

If your KDE Plasma environment is hanging or freezing you don’t necessarily have to logout and login. Open the Search/Run prompt by pressing ALT+F2 and enter konsole to open your terminal.



Then simply issue the necessary command to restart plasma shell.

For KDE4:

killall plasma-desktop
kstart plasma-desktop


KDE5:

killall plasmashell
kstart plasmashell


KDE5.10 and above:

kquitapp5 plasmashell
kstart5 plasmashell

Credits goes out to Korcia at this AskUbuntu thread.

Get the current weather (with graphics!) in your terminal

Developer @igor_chubin has created a new awesome tool for displaying the current weather in beautiful graphs right inside your terminal.

All you have to do is curl the website, wttr.in

If your distro don’t include cURL already, install it (for Debian/Ubuntu-based distros) by running

sudo apt install curl

Then you can simply run

curl wttr.in

to see the weather come to life!

Add text color to Linux bash scripts

Bash supports coloring text, but I never remember the syntax, so here’s a little cheat sheet. During my little research it also seems you can enter the color codes in two ways as illustrated below:

echo -e "\033[0;32m Hello world!"
echo -e "\e[32m Hello world!"

Some more examples:

Difficult syntax:
\033[0;xxm (where xx is color code)
Easier syntax:
\e[xxm (where xx is color code)

I’m not sure if there’s any reason to choose one or the other, but the latter example is arguably easier to remember.

All color codes:

Reset color   0
Black 0;30
Blue 0;34
Green 0;32
Cyan 0;36
Red 0;31
Purple 0;35
Brown/Orange 0;33
Light Gray 0;37
Dark Gray 1;30
Light Blue 1;34
Light Green 1;32
Light Cyan 1;36
Light Red 1;31
Light Purple 1;35
Yellow 1;33
White 1;37

You can also do lots of other things in bash, such as blinking text, bold, etc. Take a look at this site for more examples.

If you like to create CLI tools, adding some colors will make it a lot more immersive and easier to read output, like this example:

SEO friendly URLs with htaccess and PHP include script

Creating fancy SEO friendly URLs like yoursite.com/contact is actually pretty easy and looks much better than yoursite.com/index.php?page=contact. In addition to looking more professionally, it might give you a small boost for your search engine visibility. This article is meant for PHP novices and will be pretty basic.

What you’ll need:

Before we begin, we will utilize PHP include() so we end up with 1 file as the template (index.php). All other sub pages will simply store the content and not the surrounding html/head/footer code.

So for the purpose of keeping things simple, I’ll paste all the code every step of the way so you can copy & paste it.

Step 1: Creating the template

Assuming your index.php looks like this:

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SEO Friendly URLs by IT-DB</title>
<link rel="icon" type="image/x-icon" href="res/favicon.ico">
</head>

<body>

<header>
<nav>
<ul>
<li><a href="index.php?page=home">Home</a></li>
<li><a href="index.php?page=portfolio">Portfolio</a></li>
<li><a href="index.php?page=about">About</a></li>
<li><a href="index.php?page=contact">Contact</a></li>
</ul>
</nav>
</header>

<main>
Welcome to our website!
</main>

<footer>
Copyright © it-db.com <?php echo date('Y'); ?>
</footer>

</body>

</html>

We have to implement our PHP include function. Replace Welcome to our website! between the <main></main> tags with the following PHP script:

<?php
$page = !empty($_GET['page']) ? $_GET['page'] : '';
$page = substr(strtolower(preg_replace('([^a-zA-Z0-9-/])', '', $page)), 0, 20);
$def = "home"; // change to your default page
$dir = "inc"; // directory name containing all sub pages
$ext = "php"; // file extension if using anything else than php
if(!empty($page)) {
if(file_exists("$dir/$page.$ext") && is_readable("$dir/$page.$ext") && $page != "index") {
include("$dir/$page.$ext");
}
else {
header("HTTP/1.0 404 Not Found");
echo "Error 404 - File not found";
}
}
else {
include("$dir/$def.$ext");
}
?>

It might look intimidating but it’s very simple. It checks if the URL contains ?page=x, and if so, it tries to show that page (file). It also does some input sanitizing as you can see in the second line (substr(strtolower(preg_replace('([^a-zA-Z0-9-/])', '', $page)), 0, 20);) to avoid hacking exploits. If the page (file) is not found, it will send error message 404.

Keep in mind that index should be saved as .php extension. If you save it as index.html the PHP code will simply not run.

Step 2: Setup URL rewrite using htaccess and mod_rewrite

Create a new file and save it as .htaccess. That’s right, no filename, only the extension. If using Notepad in Windows it might throw a fit because of a lacking filename. In that case, use another editor such as VSCode.

To keep things simple we’ll only use two lines to setup our URL rewrite. Copy and paste the following into your .htaccess file:

RewriteEngine On
RewriteRule ^([^/.]+)/?$ /index.php?page=$1

What this means is that any argument after / will be redirected to index.php?page=. Example: yoursite.com/hi will redirect to yoursite.com/index.php?page=hi (but your browser address bar will ofcourse only show yoursite.com/hi)

Step 3: Create the sub pages

Remember from last step, our PHP script defined “inc” as the name of our directory containing all sub pages. So, go ahead and create a directory called “inc” and then create a new file for every sub page by calling them subpage.php (i.e: Home -> home.php, About -> about.php).

Your file structure should look something like this

Keep in mind that these files should only contain the content related to that sub page. But they’re not limited to just text, you can use HTML and even PHP scripts inside them. Point is, you don’t have to declare the whole <html><head><meta> etc in every file, because that’s already saved in the template file and reused for every sub page.

Step 4: Change the URLs in index.php

While creating our template in the first step, we made a navigation menu like this:

<li><a href="index.php?page=home">Home</a></li>
<li><a href="index.php?page=portfolio">Portfolio</a></li>
<li><a href="index.php?page=about">About</a></li>
<li><a href="index.php?page=contact">Contact</a></li>

Although this will still work, we should change the URLs to use our new SEO friendly URLs. Change them to:

<li><a href="home">Home</a></li>
<li><a href="portfolio">Portfolio</a></li>
<li><a href="about">About</a></li>
<li><a href="contact">Contact</a></li>

That’s it, we’re done! Please let me know in the comments below if you encounter any issues or consult the troubleshooting tips.

Troubleshooting tips

Error “Object not found” or 404 error

Make sure you have mod_rewrite activated. If you recently installed mod_rewrite you may get away by just restarting the apache service. If not, check the guide I mentioned earlier:
https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite

I’m being redirected to the wrong page

This can happen if your project directory is in another subfolder. Please remove the / from the route in .htaccess:
Change
RewriteRule ^([^/.]+)/?$ /index.php?page=$1
to:
RewriteRule ^([^/.]+)/?$ index.php?page=$1

Thanks for reading!

How to brutally kill a process in Windows environment

Today we’ll go over the various methods to kill a process. Can be useful especially if the process is stuck somehow and you’re having trouble closing/killing it.

Kill process with WMI queries

Open cmd.exe and run command:

wmic process where name='myprocessname.exe' delete

Batch kill in command prompt

Open cmd.exe and run command:

taskkill /IM "myprocessname" /T /F

/IM is required to pick process, but the extra parameters /T and /F are optional. They’re quite useful though:

/T = also kills child processes
/F = force termination of your process

Kill it the powerful way

Indeed. You can also kill it using Powershell, but you need to find the process ID first. Open Powershell prompt and simply type

Get-Process myprocessname | Select -expand id
# use the id returned in the next command:
kill -id id

Kill process using graphical user interface

You’re probably familiar with Task Manager. Open it by right-clicking on the taskbar and click on “Task Manager”. If that fails, or if you need to run it as another user, you can browse to %windir%\system32\ and run the executable file, taskmgr.exe.

If you’re lucky you can just kill the process and get on with your life. But, if you want to figure out what’s wrong, then a great tip is to open the Resource Monitor and Filter by process. This will show you all disk I/O file handles related to your process so you might actually see what exactly is hanging.

Linux terminal command equivalents in Windows

LinuxWindowsDescription
sudo <cmd>runas /user:admin <cmd>
This will run the command with admin-privileges on Linux, while on Windows it’ll simply run as the user provided (so you need to run as a user who has local administrator rights)
cat src1.js src2.js > compiled.jstype src1.js src2.js > compiled.js
Combine two or more files into one
ifconfigipconfigShows network information
traceroutetracertTrace an address and show routes
uptimenet stats server or net stats workstationWindows don’t have a builtin command to show uptime in days, but this command will show you when the machine was last booted (do the math)
lsdirShow directory contents
freememShow available RAM

I started on this article a couple years ago but was quickly forgotten in the drafts bin. Now I actually don’t have any Windows computers available anymore and can’t be arsed to look up more commands so this’ll have to work for now.

Some simple commands such as cd, mkdir, rm, rmdir has been ignored for now as they’re equal in both operating systems.

Please post a comment below if you know of any useful commands available on both operating systems.