Tuesday, January 19, 2021

EPUB error: The 'direction' property must not be included in an EPUB Style Sheet.

This is an example on Linux to resolve the following error from an epub book:

The 'direction' property must not be included in an EPUB Style Sheet.

(The steps on Windows system are similar.)

Steps 1: Put the EPUB book in a directory. And enter that directory.

$ mv mybook.epub tempdir

$ cd tempdir

Step 2: Unzip the book with a zipping tool.

$ unzip mybook.epub

Step 3: Use a text editor to modify the problematic stylesheet.css file to remove the line direction: ltr;

$ vi OEBPS/styles/stylesheet.css


Step 4:  Repackaging

$ zip -r mybook-new.epub META-INF  mimetype  OEBPS

mybook-new.epub is the new book after the fix.

Monday, January 18, 2021

Spring application unit tests context refreshing

If Mockito is used to mock a Spring singleton bean in one test class, it may impact the second test class so that test cases in the 2nd test class could fail.

It appears that all test cases are successfuly if the 2 test classes are run independently, but when they are run together, the test cases in the 2nd test class would fail.

In that case, @DirtiesContext annotation can be used on the 1st test class. It indicates that the ApplicationContext associated with a test is dirty. After the test, the ApplicationContext would be closed and removed from the context cache. The test cases from the 2nd test class can be run independently from the 1st test class.

Monday, January 11, 2021

Linux: Mounting TrueCrypt volume with cryptsetup

To mount:

$ sudo cryptsetup --type tcrypt open /path/to/truecrypt-volume mapping-name

$ sudo mount -o uid=1001 /dev/mapper/mapping-name /media/tcv

(Note: [1] if /media/tcv did not exist, create it using command mkdir. [2] check your uid using command id.)

Access the content at /media/tcv.

To unmount:

$ sudo umount /media/tcv

$ sudo cryptsetup close mapping-name

Saturday, January 9, 2021

Ubuntu Linux cannot boot from SSD harddrive


To replace an old computer's HDD with an SSD harddrive. And install Ubuntu Linux on it.


The computer is too old. Its BIOS does not recognize the SSD harddrive during boot time. However, after the usb live Ubuntu boots up, it can see the SSD.


The first thing to try is to upgrade the firmware of the BIOS. But in my case, it doesn't help.

So I used a small capacity USB drive (1GB is good enough) to help the boot. Use gparted from the live Ubuntu to partition the new SSD with a swap and an ext4. And format the 1GB USB drive as ext2 (which doesn't use journaling).

Now we can run "Install Ubuntu" and during the installation, mount the USB drive to /boot directory. For example, if SSD is /dev/sda and the 1GB USB drive is /dev/sdc, then set up the mount point as below:

/dev/sda1      mount point: /
/dev/sdc1      mount point: /boot

And install the boot loader to /dev/sdc.

Note: Remember to unmount the 1GB USB drive (/dev/sdc) before running the installation. Otherwise, the installation process cannot mount it and install the /boot to it.

Backup the boot drive

To backup the /dev/sdc to an image file, run:

$ dd if=/dev/sdc of=bootdrive.img bs=64M status=progress

After that, in case the 1GB USB drive is damage or lost, you can create a new one from bootdrive.img.

Thursday, October 1, 2020

Powershell: calculate file hash - MD5, SHA256, SHA1

 > Get-FileHash <file-name>

By default, it outputs the SHA256 of the file.

To get the file's MD5:

> Get-FileHash <file-name> -a md5

To get the file's SHA1:

> Get-FileHash <file-name> -a sha1

Friday, September 11, 2020

Python: Install package under $HOME (non-root)

Run command:

$ pip install --prefix=$HOME/local A-PACKAGE

Update $HOME/.bashrc to set PYTHONPATH env variable:

 export PYTHONPATH=$HOME/local/lib/python2.7/site-packages:$PYTHONPATH

Friday, May 8, 2020

Mockito error: You cannot use argument matchers outside of verification or stubbing

There may be many reasons can cause this error. But in this case, this error was wrongly spit out when I wrote:

when(myObject.myMethod(any(), any())).thenReturn("something");

It turned out that it is because the first parameters of myObject.myMethod(int, String) is expecting an int. So that the correction is:

when(myObject.myMethod(anyInt(), any())).thenReturn("something");

Tuesday, May 5, 2020

java.security.NoSuchProviderException - no such provider: BC

1. Download the latest BouncyCastle library, e.g. bcprov-jdk15on-165.jar

2. Copy the JAR file to $JAVA_HOME/jre/lib/ext/.

3. Edit file $JAVA_HOME/jre/lib/security/java.security. Add the following:

(Note: if you have 10 providers or more already, adjust the number 10 to a higher number accordingly.)

Ref: https://docs.oracle.com/cd/E19830-01/819-4712/ablsc/index.html

Saturday, April 11, 2020

Linux: use tcplay to open an TrueCrypt container

# to mount
losetup -f
# if it returns: /dev/loop5
sudo losetup /dev/loop5 foo.tc
sudo tcplay -m foo.tc -d /dev/loop5
sudo mount /dev/mapper/foo.tc ~/tc_mounted

# to umount
sudo umount ~/tc_mounted
sudo dmsetup remove foo.tc
sudo losetup -d /dev/loop5

Monday, February 17, 2020

Install StudioTax 2019 on Ubuntu 18.04

Step 1: install Wine

sudo apt install wine-stable

sudo apt install winetricks

sudo apt install winbind

Step 2: install .Net4.5.2 which is required by StudioTax

env WINEPREFIX=$HOME/WineStudioTax wineboot --init

env WINEPREFIX=$HOME/WineStudioTax winetricks dotnet452 corefonts

Step 3: install IE7 (Although it is not in the requirements of StudioTax, if IE is not installed, notes spit out by StudioTax won't show on some popup dialogues.)

env WINEPREFIX=$HOME/WineStudioTax winetricks ie7

Step 4: install StudioTax 2019
-- Download StudioTax2019Install.exe
-- Check its md5sum

env WINEPREFIX=$HOME/WineStudioTax wine StudioTax2019Install.exe /extract

env WINEPREFIX=$HOME/WineStudioTax winetricks settings win7

env WINEPREFIX=$HOME/WineStudioTax wine msiexec /i StudioTax.msi

Step 5: For the autofill feature, we need to install a Windows version Firefox to do the authentication with CRA.

Download Firefox 49.0.2 Win32 version. Then run command:

env WINEPREFIX=$HOME/WineStudioTax wine 'Firefox Setup 49.0.2.exe'

Set up Firefox as default to open URL. Run:
env WINEPREFIX=$HOME/WineStudioTax wine regedit

Change in Regedit:

    HKEY_CLASSES_ROOT -> http -> shell -> open
        Create/Edit command key to:
            "C:\Program Files\Mozilla Firefox\firefox.exe" "%1"

    (Repeat for https:)
    HKEY_CLASSES_ROOT -> https -> shell -> open
        Create/Edit command key to:
            "C:\Program Files\Mozilla Firefox\firefox.exe" "%1"

Save/close regedit

1. Install .NET with Wine: https://appdb.winehq.org/objectManager.php?sClass=version&iId=25478&iTestingId=104233

2. Install StudioTax with Wine: https://appdb.winehq.org/objectManager.php?sClass=version&iId=37634

3.  Installing StudioTax 2017 on Wine: http://pnijjar.freeshell.org/2018/studiotax/

Get This <