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.
25/04/2020
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
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:
Setup could be a bit more straightforward, but still not a big issue:
- Enable Windows Subsystem for Linux as a Windows feature from Control Panel > Programs and Features > Turn Windows features on or off
- Reboot
- Make sure LxssManager service is running
- 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)
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.
13/03/2020
[Java] Schedule tasks with Quartz and Spring
We saw how to schedule tasks with ScheduledExecutorService, and we now we will see how to achieve the same result using the Quartz framework.
Much like before, we have two key concepts:
Much like before, we have two key concepts:
- job: a job is a runnable class that implements the Job interface
- trigger: a Trigger is a specific schedule for a job. A trigger can only be linked to a job, and a job can be linked to multiple triggers.
12/03/2020
[Java] Schedule tasks with ScheduledExecutorService
Java offers a ScheduledExecutorService that allows developers to create and schedule tasks.
A task is a class that implements ONE method to be executed that performs the desired duties. It is NOT necessary for the task itself to implement the Runnable interface, although the tasks will be run as a Thread.
An important thing to notice is that by default threads are NOT marked as daemons, therefore it might be worth setting such flag according to your needs.
Another important thing to note, is that the scheduler will hold on to references to cancelled tasks, which might lead to memory leaks, so it might be preferable to setRemoveOnCancelPolicy to true.
A task is a class that implements ONE method to be executed that performs the desired duties. It is NOT necessary for the task itself to implement the Runnable interface, although the tasks will be run as a Thread.
An important thing to notice is that by default threads are NOT marked as daemons, therefore it might be worth setting such flag according to your needs.
Another important thing to note, is that the scheduler will hold on to references to cancelled tasks, which might lead to memory leaks, so it might be preferable to setRemoveOnCancelPolicy to true.
Subscribe to:
Posts (Atom)