29/04/2020

[Docker] Move docker directory to different location on NTFS filesystem

The default location of docker files (images, volumes, networks, etc) on most distributions is /var/lib/docker

This can be easily changed with the daemon.json configuration file.

First stop the docker service and make sure it is completely stopped.

You can now edit or create the configuration file under /etc/docker folder. In there, you can specify a new location for the docker files with the graph attribute:

{
   "graph": "/path/to/new/docker_folder"
}



You can then copy ALL the content to the new location or let docker recreate everything from scratch there.

WARNING: if the new location is on a different filesystem you might need to change the storage driver AND existing data might become inaccessible (it will remain on the filesystem though)

To set a new storage driver, set the storage-driver attribute as well (example for NTFS):

{
   "graph": "/path/to/new/docker_folder",
   "storage-driver": "vfs"
}

28/04/2020

[GNOME] Create application shortcut that can be added to favorites

Some applications you install come as archives that you extract in a desired location. However, not all come with an installer that takes care of creating the proper application entries, leaving the task to the user.

You can add a shortcut for any application by creating a file APPLICATION_NAME.desktop under /usr/share/applications and adding this content:

[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Terminal=false
Categories=OPTIONAL_CATEGORY_LIST

GenericName=APPLICATION_NAME
Comment=OPTIONAL_COMMENT
Name=APPLICATION_NAME
Path=FULL_PATH_TO_APPLICATION_FOLDER
Exec=FULL_PATH_TO_APPLICATION_EXECUTABLE

Icon=OPTIONAL_FULL_PATH_TO_ICON

StartupWMClass=APPLICATION_WM_CLASS


[Linux] Find WM_CLASS value for an application

In order to group application windows together, the WMClass and WMInstance attributes have been specified in the Inter-Client Communication Conventions Manual for X server 11.

Long story short, they are two strings that are used to associate application windows to a specific application, they can be set by the application (WMClass) or the user (WMInstance).

They are very useful especially for those applications that are customizations or based on existing tools, which alone would have a different value (eg Java or Eclipse based apps).

Finding the value for a window is as simple as opening a terminal and running:

xprop

Then clicking on the desired window


25/04/2020

[Linux] Custom keyboard layout QWERTZ to QWERTY

We already saw how to customize a keyboard layout on Windows, now it's the turn of Linux, using XKB for Xorg.

Remapping keys is as simple as editing a text file. You will find all available layouts under /usr/share/X11/xkb/symbols, you can use them as basis for a new layout or directly edit them.

Pick the layout you want to change (maybe make a backup first), then invert the VALUES ONLY of the two lines containing the lower and uppercase z and y, then save.

You will need to restart X server and the changes will be in effect.

21/04/2020

[Windows] Share environment variables in Windows Subsystem for Linux

Now that you have your fancy WSL up and running, you want to use it and all your environment variables are NOT available (of course).

Luckily there is a workaround, using the WSLENV variable. Unfortunately, it is not a direct 1:1 translation of your existing variables, rather you will need to craft them manually and convert between the two environments before you run a command or switch environment.

For example, to pass your JAVA_HOME correctly to wsl:

set JAVA_HOME=%JAVA_HOME%
set WSLENV=JAVA_HOME/up
wsl
echo $JAVA_HOME

And the magic is behind that last /up flag which says: set the value when invoking WSL from Windows (u) and translate between Windows and Unix paths (p)

WARNING: spaces are NOT escaped
WARNING2: only ONE variable is shared, so you cannot share both JAVA_HOME and PATH for example at the same time

[Windows] Activate and configure Windows Subsystem for Linux

Windows 10 introduced an update that adds a very cool feature: Windows Subsystem for Linux. If you are a fan of Cygwin, or similar tools, you will greatly like this feature as well.

Setup could be a bit more straightforward, but still not a big issue:

  1. Enable Windows Subsystem for Linux as a Windows feature from Control Panel > Programs and Features > Turn Windows features on or off
  2. Reboot
  3. Make sure LxssManager service is running
  4. Install a Linux distro from Windows store, search for "WSL" and pick the one you prefer, for example Alpine or Ubuntu, if no distro is installed, you get an error instead:
Windows Subsystem for Linux has no installed distributions. Distributions can be installed by visiting the Windows Store: https://aka.ms/wslstore Press any key to continue...

And going to that link brings you nowhere.. so just install it yourself from the store.

After the installation is completed (might ask you to setup a user and password), you can open any command prompt and type wsl to launch it.

Be careful, that command was different in the past: lxrun or bash and there are apparently 2 versions of WSL as well, use whatever makes it run for you

17/04/2020

[Windows] Store command output in variable in batch script

For whatever reason, storing the output of a command into a variable from a batch script is not easy at all:

FOR /F "tokens=*" %%g IN ('your_command ^| with_escaped_pipe_if_you_need_it') do (SET VAR=%%g)

07/04/2020

[Windows] Custom keyboard layout QWERTZ to QWERTY

Some people are unfortunate enough to use a QWERTZ keyboard layout (and then there are the French), not because they need ready access to that specific letter, but maybe just to avoid losing yet another war.

Of course, for us with functioning opposable thumbs, this might introduce some difficulties as years of CTRL+Z trained our muscle memory for ready undo (Z) rather than redo (Y).

Windows provides a tool: Microsoft Keyboard Layout creator, that helps us overcome this by defining a new key map and generate an installable keyboard layout. Cool.

Install it, File - Load existing keyboard, pick your ümläuted keyboard of choice and invert the z and y keys to restore universe order. Done.

Not so fast. What about UPPERCASE Z and Y? You need to change those too. On the left side, check the Shift under Shift states section and perform the binding again, this time for capital Z and Y. Done.

Not so fast, What about the shortcuts that were using Z and Y? They still map to the old layout where the keys were inverted, you need to change those too. Unfortunately, it can't be done from the tool. 

No worries, save your project and open your .klc file with a text editor and search for the line defining your Z and Y keys, they will look like this (example for the y key):

15 Z 1 y Y -1 -1 // LATIN SMALL LETTER Y, LATIN CAPITAL LETTER Y

As you can see, almost all changes were done, but the damn keys are still left in the wrong place in the underlying mapping. Simply change them to reflect the correct mapping (example for the y key):

15 Y 1 y Y -1 -1 // LATIN SMALL LETTER Y, LATIN CAPITAL LETTER Y

Then save and reopen the file with the tool. Now finally: Project - Build DLL and setup package to generate the installer, run it, and we have our new keyboard available to select in the language list for available keyboards.

If the tool fails to build, try to install it in c:\mklc14 folder as it might fail if it is installed in another location or in a directory containing spaces

Of course, you need to restart the system in order for ALL remappings to take effect.