Friday, August 13, 2021

Java: set command line parameters via environment variable

Instead of:

> java -Xmx256M ...


We can:


> java ...

JAVA_TOOL_OPTIONS may not work with jvm.dll. For that we can try _JAVA_OPTIONS. e.g.

> set _JAVA_OPTIONS=-Xmx256M

Tuesday, June 29, 2021

Java ldd

For a C++ library, we can use command ldd to list the dependencies. There isn't such a official tool for the Java. However, if the source code is available, we can build the JAR using javac with the verbose mode turned on. The location of all the dependent JARs will be listed during the build.

Wednesday, June 16, 2021

Android 10: Enable the built-in screen recorder


Note: This may NOT be supported by all phones.


1. Turn on the Developer Options on the phone. (Google it to see how to...)

2. Connection the phone to the computer.

3. On the computer, install the "adb" application.

4. On the computer, open a terminal, run command "adb devices" to verify that the phone is connected correctly.

5. On the computer, run command "adb shell settings put global settings_screenrecord_long_press true" to enable the screen recorder on the phone.

6. On the phone, long press the power butter to bring up the menu: Power off/Restart/Screenshot

7. Long press the "Screenshot" item in the above menu. A "Start Recording" dialog is popped up.

8. Click on the "Start Recording" button to start.

Friday, May 7, 2021

MySQL DB: mixed charset problem

The problem:

Client application A writes character ¢ into MySQL DB.

Client application B reads it from DB and gets ¢.

If we look inside the DB to see how it is stored using function hex() -- select hex(fieldname) from tablename, we can see it is stored as \xC2\xA2 in hex form.


The reason:

The MySQL DB server is using ISO-8859-1 (latin1).

Client A writes characters to MySQL DB server in UTF-8. But the server incorrectly thinks the connection is using latin1. So one character \xA2 is stored as \xC2\xA2 (UTF-encoding).

Client B reads characters from the server in UTF-8. And the server correctly identifies the connection is using UTF-8. So the sever will encode the 2 hex characters into \xC3\x82\xC2\xA2 and send back 4 characters as the UTF-2 encoding for the 2 characters stored in the table.


To fix:

Make sure the charset settings of the connection and the client match the what the client actually uses.

The SQL command to check the charsets is:

SHOW SESSION VARIABLES LIKE 'character\_set\_%';

The SQL command to change the charsets to UTF-8 is:


Wednesday, May 5, 2021

Spring Boot: escape HTML and non-ASCII characters in Json response

Create an ObjectMapper object and let Spring Boot use our ObjectMapper object with the @Bean and @Primary annotations.

In our configuration bean:

public class MyConfiguration {
  public ObjectMapper objectMapper() {
    // create our own ObjectMapper object.
    ObjectMapper objMapper = new ObjectMapper();
    // escape all non-ASCII characters

    // definition of the HTML characters to escape
    final class HtmlCharsToEscape extends CharacterEscapes
      private final int[] asciiEscapes;
        // get the set of default escaped characters (double-quote, backslash etc)
        int[] esc = CharacterEscapes.standardAsciiEscapesForJSON();
        // and force escaping of HTML special characters:
        esc['<'] = CharacterEscapes.ESCAPE_STANDARD;
        esc['>'] = CharacterEscapes.ESCAPE_STANDARD;
        esc['&'] = CharacterEscapes.ESCAPE_STANDARD;
        esc['\''] = CharacterEscapes.ESCAPE_STANDARD;
        asciiEscapes = esc;

      @Override public int[] getEscapeCodesForAscii() {
        return asciiEscapes;

      @Override public SerializableString getEscapeSequence(int ch) {
        // no CUSTOM escaping needed:
        return null;

    // Escape the HTML special characters.
    // This will be picked up the Spring Boot.
    return objMapper; 

Tuesday, May 4, 2021

Windows 10 shortcut: move a window to another monitor

If the computer connects to multiple monitors, use this shortcut combination to move the selected window to the left or right monitor:

Windows-Key + Shift + Left/Right-Arrow

Monday, May 3, 2021

Elipse: debug Maven project with JUnit

1. Set the breakpoints.

2. Right click on the JUnit test Java class. On the popup menu, select Debug as... -> JUnit.

Sunday, May 2, 2021

Linux boot into Busybox - Gave up waiting for root device

One possible fix is to add the rootwait to the boot parameters.


1. Add parameter rootwait to GRUB_CMDLINE_LINUX_DEFAULT in file /etc/default/grub:

 GRUB_CMDLINE_LINUX_DEFAULT="quiet splash rootwait"


2. Run command to update grub:

$ sudo update-grub


(Note: Another related parameter is rootdelay.)



Wednesday, April 28, 2021

Windows: install msi as non Administrator user

 Run command:

> msiexec /a ThePackage.msi

When the installation program asks for the destination location, pick a fold you can write into.

Thursday, April 22, 2021

HTML dialog Tag




<button onclick="openDialog()">Open Dialog</button>

<dialog id="myDialog"><iframe src="dialogbox.html"></iframe></dialog>


function openDialog() {









<button onclick="parent.document.getElementById('myDialog').close()">

Click to close





Get This <