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





Wednesday, March 24, 2021

Docker commands and Dockerfile examples

To install docker on fedora

$ sudo dnf config-manager --add-repo

$ sudo dnf install docker-ce docker-ce-cli 

$ sudo systemctl start docker

$ sudo docker run hello-world

To build and run an image

First, create a Dockerfile under the current directory (see below).

$ sudo docker build -t myimagename:myimageversion .

$ sudo docker  run -p 8888:8080 myimagename:myimageversion


$ sudo docker run --net=host myimagename:myimageversion

Other commands

$ sudo docker image ls

$ sudo docker rmi image-hash

$ sudo docker ps -as

$ sudo docker rm container-hash

$ sudo docker run -it myimagename:myimageversion bash

Dockerfile of adding self CA and Bouncy Castle jar

FROM tomcat:9.0.44-jdk8

# Add myCA certificate

ADD myCA.crt /usr/local/share/ca-certificates/

RUN chmod 644 /usr/local/share/ca-certificates/myCA.crt && update-ca-certificates

# Add Bouncy Castle provider

RUN echo '' >> "/usr/local/openjdk-8/jre/lib/security/"

RUN echo 'security.provider.10=org.bouncycastle.jce.provider.BouncyCastleProvider' >> "/usr/local/openjdk-8/jre/lib/security/"

ADD bcprov-jdk15on.jar /usr/local/openjdk-8/jre/lib/ext/

# Add web app

ADD myapp.war  /usr/local/tomcat/webapps/


CMD ["", "run"]

Tuesday, March 16, 2021

Eclipse cannot connect to a server due to certification error

If "Install New Software" fails in Eclipse and it complains that the server's certificate is not trusted, that may be because the Java instance that Eclipse uses does not have the needed CA in its keystore.

Another symptom is that when you try to access Eclipse Marketplace in Eclipse (Help|Eclipse Marketplace...), exceptions are thrown complaining about the server certificate.

Usually Eclipse uses the Java in the system, and you can simple add the CA into the keystore following this post.

Sometimes Eclipse uses a different Java instance and to find out which one it is, you need to go to the installation of Eclipse and find this file eclipse.ini. Use a text editor to open it. Find the line -vm. Under it is the Java instance that Elipse uses.

Go to where the Java instance locates, and enter its lib/security/ directory. Follow this post to add the new CA to cacerts, e.g.:

$ keytool -import -alias CloudService -keystore cacerts -file "/path/to/CloudServiceRootCA.cer"

Get This <