Sunday, January 23, 2022

Linux: edit PDF with LibreOffice Draw

On Linux, PDF files can be opened and edited by LibreOffice Draw.

However, depending on how the PDF is generated, the formatting of the file can be a mess when it is opened by LibreOffice Draw.

If that happens, we can use a PDF reader to open it first and print it into a SVG image file.

After that, use LibreOffice Draw to open the SVG file and edit it.

After the edit, LibreOffice Draw can export the modified image into a new PDF file.

Windows: install application as non-admin user

Some Windows applications require Administrator account to install.

To force the applications to run as a normal user, set the following first:

        set __COMPAT_LAYER=RunAsInvoker

Note: there are two underscore (_) characters at the prefix.

For example, if you want to run SteamSetup.exe as a regular user, create a run.bat file and put the following 2 lines in:

        set __COMPAT_LAYER=RunAsInvoker

        Start SteamSetup

Save and run run.bat.

Wednesday, December 15, 2021

Linux: Change Swap size

Disable the old swap file:

$ sudo swapoff /swapfile

Create a bigger (8gb) swap file:

$ sudo fallocate -l 8G /swapfile
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile

Enable the new swap file:

$ sudo swapon /swapfile


Sunday, October 31, 2021

GIMP: Outline text or add border to text

Add text and copy path from the text.

right-click on the text, and from the context menu, select the Path from Text option


Create a new transparent layer and select from path.

Menu -> Layer -> New Layer... 

Menu -> Select -> From Path

Move the layer below the layer having the text.

Set up a grow size.

Menu -> Select -> Grow


Add a stroke line to the selection.

Menu -> Edit -> Fill with BG Color



Friday, October 29, 2021

GIMP: Resizing image and filling the empty space

1. Resize the Canvas

Menu -> Image -> Canvas Size...

Note: Click the "Center" button to center the original image.


2.  Duplicate the layer

Menu -> Layer -> Duplicate Layer

3. Resize the lower layer

Select the lower lay (on the right panel)

Menu -> Layer -> Scale Layer...

Change the Width/Height to a bigger value to make the image cover the whole Canvas.

4. Fuzzy the lower layer

Select the lower lay (on the right panel)

Press Ctrl-A to select all on the lower layer

Filter -> Blur -> Gaussian Blur...

Adjust "Size X"/"Size Y" to blur the lower layer


Wednesday, October 20, 2021

MySQL: Sorting query result with conditions

Use MySQL CASE function to first sort result into 3 sets, then sort them by columns:

SELECT City, Country FROM Customers
WHEN Country LIKE 'U%' THEN 1
WHEN Country LIKE 'S%' THEN 2
END), Country, City;

The output will be:

    City    Country
    Cowes    UK
    London    UK
    London    UK
    Albuquerque    USA
    Anchorage    USA
    Boise    USA
    Butte    USA
    Elgin    USA
    Barcelona    Spain
    Madrid    Spain
    Sevilla    Spain
    Bräcke    Sweden
    Luleå    Sweden
    Bern    Switzerland
    Genève    Switzerland
    Graz    Austria
    Salzburg    Austria
    Bruxelles    Belgium
    Charleroi    Belgium
    Montréal    Canada
    Tsawassen    Canada
    Vancouver    Canada
    Aachen    Germany
    Mannheim    Germany
    Stuttgart    Germany
    Barquisimeto    Venezuela
    Caracas    Venezuela

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:


Get This <