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 - 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/ Add the following:

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


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
sudo tcplay -m -d /dev/loop5
sudo mount /dev/mapper/ ~/tc_mounted

# to umount
sudo umount ~/tc_mounted
sudo dmsetup remove
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:

2. Install StudioTax with Wine:

3.  Installing StudioTax 2017 on Wine:

Wednesday, January 29, 2020

Powershell Script: Write to a file

1. Append a string to the end of a file

Add-Content -Path .\theFile -Value "the string to be appended"

2. Append file_a to the end of file_b

Get-Content -Path .\file_a | Add-Content -Path .\file_b

3. Create a new file with a sting as the content

"the string to be put into the file" | Out-File -FilePath .\theFile

Tuesday, January 28, 2020

Powershell Script: Read input with default value

$defaultVal = 'No'

$inputVal = Read-Host -Prompt "Input something? [$defaultVal]"

if ($inputVal -eq '')
  $inputVal = $defaultVal

Monday, January 27, 2020

Speakout and Android Oreo

When inserting the Speakout SIM into an Android Oreo phone, the APN settings are pushed from the Rogers Network as "ltemobile.apn".

As Speakout does not support LTE, that APN setting does not work. And APN settings are locked for Speakout SIM. The "Add APN" button is not there and the only available APN is grayed out that we cannot change it.

The workaround is to use an unrestricted SIM to generate an APN profile.


1. With Speakout SIM in, change the Network Operator to "Speakout 3G" (Settings / Network&Internet / Mobile network / Network operators) (However, I am not sure if this step is necessary. But in my case, it didn't work when on Speakout 4G.)

2. Power off the phone. Remove Speakout SIM.

3. Insert an unlocked/unrestricted SIM, e.g. Roam Mobility. Power on.

4. Go to APN settings (Settings / Network&Internet / Mobile network / Access point names). Now we can add a new APN.

5. Tap the "+" icon on the top right. Add an new profile with this values:
      APN: speakout
      APN: rogers-core-appl1.apn
      APN type: default,supl
      APN Protocol: IPv4/IPv6
      APN Roaming Protocol: IPV4
      MVNO type: None

    Don't touch the MCC and MNC fields which are set as the US codes.

6. Tap the Save button to save it. Check that speakout is generated.

7. Power off the phone. Remove Roam Mobility SIM.

8. Insert Speakout SIM. Power on.

9. Go to APN settings. Tap to select the newly created "speakout" profile. If you look into it, you can find that MCC and MNC are automatically updated to what Speakout uses:
      MCC: 302
      MNC: 720
      MVNO type: GID
      MVNO value: D4

10. Switch back the Network Operator to "Speakout 4G" (refer to step 1).

11. Reboot if necessary.

Tuesday, December 31, 2019

C# programming: Debug and trace

To generate a trace, use

System.Diagnostics.Trace.WriteLine("some trace");

This code works when TRACE is turned on during compiling. Add the compile option in web.config:

<compilation defaultLanguage="c#" debug="true" targetFramework="4.5">
    <compiler language="c#" ... compilerOptions="/d:DEBUG;TRACE" />

During the development, the trace can be found in the Visual Studio's console. If the application is deployed, the trace can be seen with the tool Debugview, which can be downloaded from:

Get This <