Sunday, December 4, 2022

Completing Removing a Git Submodule

This is a note about removing  a Git submodule completely.

  1. Revise the .gitmodules by removing the reference to the submodule Git repo;
  2. Revise the .git/config file by removing the reference to the submodule Git repo;
  3. Remove the submodule from Git index, e.g.,
        git rm --cached path_to_submodule
    
  4. Delelete the meta data from .git directory, by removing .git/module/path_to_submodule
  5. Stage the changes, and commit the changes, e.g.,
        git add -u
        git commit -m "removed the submodule"
        

Reference

The above is a summary from these references

Friday, December 2, 2022

Installing R Packages in User Space on Linux

On a Linux system, without running R as the root user, we can install R packages and libraries in the user space. By default, the installation directory is $HOME/R/library. What if we want to install it to a different directory without having to specifying it on the R command line? For this, we can set R_LIBS environment variables to point to the directory. For instance, if we wish to install the libraries to a hidden directory, e.g., the $HOME/.R/library directory, we can set it up in the user profile, such as, in the .profile or .bash_profile file,


if [ -n $R_LIBS ]; then
  R_LIBS="/home/hchen/.R/library":${R_LIBS}
else
  R_LIBS="/home/hchen/.R/library"
fi
export R_LIBS



Installing devtools and landmap in R

It took me several trial and error to install the devtools package and the landmap package from Github repo. This is a note about the installation procedure on Fedora Linux so that we don't have to repeat the trial and error process. 



sudo dnf install  \
		freetype-devel \
		libpng-devel \
        libtiff-devel \
        libjpeg-turbo-devel \
		gdal-devel \
		gdal-libs \
		proj-devel \
		geos-devel \
		udunits2-devel

Then in R,


install.packages('devtools')
library(devtools)
install_github('envirometrix/landmap')

Saturday, July 30, 2022

Windows 10 does not know some "devices" of a Dell Precision Workstation

I was installing Windows 10 on a Dell Precision T3620 Workstation. Although the systems worked well, it bothers me that the Windows Device Manager reported that some devices were not recognized, i.e., an yellow exclamation point on the devices, like the following screenshot shows,

In fact, these unrecognized devices are,

  • PCI Data Acquisition and Signal Processing Controller,
  • PCI Memory Controller, and
  • SM Bus Controller

It turns out that many users had similar problem, and the solution is to update some device drivers. However, I was slightly frustrated that the very driver that solved my problem (all three unrecognized devices) wasn't listed under "driver" on the Dell Support's website. Instead, it was listed under "Utility", and was the "Intel Chipset Device Software."

Friday, July 29, 2022

Oldest Recorded Supernova

Source: NASA

I was listening to the "Stuff you should know" podcast when I was driving to work, and heard the story about supernovae. The host of the podcast says that the oldest recorded supernova is Supernova 86. I looked it up on the Web, and yes, NASA has a Web page about it and states,

Chinese astronomers witnessed the event in 185 A.D., documenting a mysterious 'guest star' that remained in the sky for eight months.

The Wikipedia page about it (SN 185 about RCW 86) has the exactly the quote in the Chinese record, 

《後漢書·卷十二·天文下》:'中平二年十月癸亥,客星出南門中,大如半筵,五色喜怒稍小,至後年六月消。占曰:‘為兵。’至六年,司隸校尉袁紹 誅滅中官,大將軍 部曲將 吳匡 攻殺 車騎將軍 何苗,死者數千人。

and an English translation about the quote,

In the 2nd year of the epoch Zhongping, the 10th month, on the day Guihai (i.e., December 7, 185 AD), a 'guest star' appeared in the middle of the Southern Gate (i.e., an asterism consisting of ε Centauri and α Centauri), The size was half a bamboo mat. It displayed various colors, both pleasing and otherwise.It gradually lessened. In the 6th month of the succeeding year it disappeared.

Our Sun will eventually go "supernova" (although after a very long time (a billion years. Also stronomers think that our Sun is too small to go "supernova", but our Sun will die). It makes me wonder about the fate of the humanity. Well, perhaps, the humanity has long destroyed itself (by a nuclear war) before that; or perhaps, the humanity has found an eventual peace and has mastered the technology to find a new home ...

Wednesday, June 15, 2022

Cannot Safely Remove USB Drive on Windows 10? Use Diskpart

From time to time, I cannot safely remove or eject a USB drive. The reason is that one or more processes locks some files. For instance, I observed the following files were locked by a svchost.exe process on the USB drive F:,

F:\$Extended$
F:\System Volume Information\

The method that works consistently for me is to use Diskpart. Note this requires administrative privilege.   Below is an example to remove the external drive (shown as Disk 1),

C:> diskpart
DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          465 GB  1024 KB        *
  Disk 1    Online         1862 GB      0 B

DISKPART> select disk 1

Disk 1 is now the selected disk.

DISKPART> offline disk

DiskPart successfully offlined the selected disk.

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          465 GB  1024 KB        *
* Disk 1    Offline        1862 GB      0 B

To bring the disk back online without re-plugging it, we do the steps illustrated in the example below,
C:> diskpart
DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          465 GB  1024 KB        *
* Disk 1    Offline        1862 GB      0 B

DISKPART> select disk 1

Disk 1 is now the selected disk.

DISKPART> online disk

DiskPart successfully onlined the selected disk.

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          465 GB  1024 KB        *
* Disk 1    Online         1862 GB      0 B

DISKPART>

Wednesday, June 1, 2022

Removing OpenVPN 2 Private Key Password

I wanted to remove the password protection for a OpenVPN 2 client private key. The solution is to use the ssh-keygen command. For instance, assuming the key file is client_private_key.key, we run

ssh-keygen -p -N "" -m pem -f client_private_key.key

The key file will be replaced by the key without the password protection.

Before I figured out this solution for OpenVPN 2, I ran into a problem. That is, I ran the following command instead,

ssh-keygen -p -N "" -f client_private_key.key

where there is no "-m" option to specify "pem" as the format of the key file and the key file is in the default PKCS 8 format. Then when I attempted to restart the OpenVPN 2 client, I saw in the log,

Error: private key password verification failed

The message is misleading in this case because the actual problem is that OpenVPN 2 does not recognize the PKCS 8 format. To correct the problem, we just need to run the ssh-keygen again and this time we specify the pem format as the file format, i.e.,

ssh-keygen -p -N "" -m pem -f client_private_key.key

Of course, in retrospective, I should have had run this command from the beginning with.

Tuesday, May 24, 2022

Setting up Wi-Fi on Linux Hosts using NetworkManager Client on Command Line

This is a note about setting up Wi-Fi interface on Linux hosts using NetworkManager client on the command line.

  1. The first step is to figure out the name of the Wi-Fi interface. For this, we can use the nmcli device command, e.g.,
    
    $ nmcli device
    DEVICE          TYPE      STATE         CONNECTION
    wlp5s0          wifi      disconnected  --
    p2p-dev-wlp5s0  wifi-p2p  disconnected  --
    
    where wlp5s0 is the Wi-Fi interface. Below we use this name in our examples and should replace it with the actual interface name.

  2. For a Wi-Fi interface, we can create connection profiles to connect to Wi-Fi Access Points. In the following, we assume that
    • the Wi-Fi interface name is wlp5s0,
    • we name the Wi-Fi connection profile HomeWiFi5GhzConnection,
    • the ssid of the Access Point that the Wi-Fi interface connects to is WiFiAp5GHz,
    • the Access Point does not broadcast ssid, i.e., is hidden, and
    • the Access Point is configured to use the WPA-PSK security protocol, and the PSK password is "ThisPasswordIsDumb".
    , which we should replace with actual ones.

    We create the connection profile,
    sudo nmcli connection add type wifi con-name HomeWiFi5GhzConnection ifname wlp5s0 ssid WiFiAp5GHz
    sudo nmcli connection modify HomeWiFi5GhzConnection wifi-sec.key-mgmt wpa-psk
    sudo nmcli connection modify HomeWiFi5GhzConnection wifi-sec.psk ThisPasswordIsDumb
    sudo nmcli connection modify HomeWiFi5GhzConnection 802-11-wireless.hidden yes
    
  3. Finally, to connect to the Wi-Fi access point using the connection profile, use the nmcli connection up command, e.g.,
    sudo nmcli connection up HomeWiFi5GhzConnection    
    

Tuesday, May 17, 2022

Dell iDRAC Default IP Address and Account

This is to note Dell iDRAC default IP address and default account information.

By default, Dell iDRAC is configured with DHCP disabled and assigned a static IP address,

192.168.0.120/24

The default username and password for iDRAC is

Username: root

Password: calvin

A quick way to configure iDRAC without a keyboard and a monitor is via Ethernet. 

  1. Connect an Ethernet cable from a host computer like a laptop computer to the iDRAC Ethernet port
  2.  Configure the host computer with an IP address on the same subnet, e.g.,
    On Windows, use
    netsh interface ip set address static 192.168.0.121 255.255.255.0 192.168.0.1
      
    On Linux, use
    ip adddress add 192.168.0.121/24 dev eth0
          
  3. Open https://192.168.0.120 and accept the SSL certificate 
  4. Configure the system or iDRAC via the Web interface

Monday, April 18, 2022

Matploblib does not show interactive plots on SciView in PyCharm

I encounter a problem when I plot an interactive plot using Matplotlib in PyCharm. The problem is that it does not show the interactive plot on SciView as it usually does. Although it could be due to the idiomatic way of  my creating python plot, I look for a "cheap" way to fix this since the code successfully creates interactive plots when I run it fron the console outside of PyCharm. The solution tends out to be use a different Matploblib backend. 

In PyCharm's python console, we can determine which Matploblib backend is currently using, e.g.,


>>> import matplotlib
>>> matplotlib.get_backend()
'module://backend_interagg'

>>>

In an OS console, we can determine which Matploblib backend is currently using, e.g.,


>>> import matplotlib
>>> matplotlib.get_backend()
'TkAgg'

>>>

Based on the observations in the above, the solution is to set the Matplotlib backend as the one used by Matplotlib on the OS console, e.g.,



import matplotlib


if __name__ == '__main__':
    matplotlib.use('TkAgg')
    # ...
    # more code ...
    # ...



Saturday, April 16, 2022

Setting up X2Go

If you wish to have Windows Remote Desktop-like experience when we access a Linux hosts, X2GO is probably the best solution. X2GO runs on the NX or NoMachine protocol. Contrast to the solution that runs a X server on a Linux host, and run a client application on another host, we can leave a session and resume it with NX or X2GO, which offers the experience similar to Windows Remote Desktop. 

Below is a "minimal" setup for a Fedora Linux server and a Windows client. We call it a "minimal" setup because we do not install a full Linux desktop, rather, we install a graphical terminal like xterm. 

  1. Install the X2GO server on Fedora Linux
    
    sudo dnf install x2goserver x2goserver-xsessions xterm
        
  2. Install the X2GO client on Windows. For this, we download the client installation package, and run the installation package.
  3. Now we can use X2GO -- nothing needs to be done on the Linux server
    1. Start the X2GO client on the Windows host
    2. Create a new sessiono if we have not done so
    3. When creating the new session, we specify the Linux host we connect to and the user name we log on
    4. It is important to note that we should select the "Session Type" as "Single Application" and enter the command as "/usr/bin/xterm" since we did not install a full Linux Deskop and only installed xterm
    5. To connect to the Linux server and run xterm, we open the session.
    6. We can close the session. Next time when we open it, it resumes from where we close it

Friday, April 8, 2022

SSH cannot connect to any non-local SSH servers on WSL 2

Recently, I encountered a strange problem. That is, I cannot connect to any non-local SSH servers from a WSL 2 terminal using the ssh client from WSL 2. However, I would not have any problem to connect to these SSH servers using ssh.exe from Windows and PuTTY or other SSH clients on Windows. Here is what I observe when I try to connect Github.com,


ssh -vvv -T ssh@github.com
OpenSSH_7.9p1 Debian-10+deb10u2, OpenSSL 1.1.1d  10 Sep 2019
debug1: Reading configuration data /home/hui/.ssh/config
debug1: /home/hui/.ssh/config line 17: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "github.com" port 22
debug2: ssh_connect_direct
debug1: Connecting to github.com [140.82.113.3] port 22.

The process hangs on "Connecting to ..." until times out. I attempted all of the methods discussed in this threads and the method of adding a Firewall rule for WSL, but to no avail in my case. The solution finally works for me is to restart the Windows Container Networking service.

Using PowerShell, we can restart the service on command line as follows,


PS C:\WINDOWS\system32> Restart-Service -Force -Name hns

The solution came to me because I wanted to restart the networking stack of WSL and to see if it would resolve this issue. The method to do it comes from this Github gist. To restart the networking stack of WSL, run the following commands,


# Restart the Host Network Service 
Restart-Service -Force -Name hns
# Restart the Windows Subsystem for Linux Manager
Restart-Service LxssManager
# Restart the WSL Network adapter
Restart-NetAdapter -Name "vEthernet (WSL)"

In my case, restarting the Windows Container Networking service (hns) is sufficient for me to resolve the problem.

Reference

  1. Reset your WSL network connection trying to fix WSL2 media disconnected error
  2. WSL2 SSH can't connect to any public SSH server
  3. SSH connections hanging from WSL2

Thursday, April 7, 2022

Failed to start Android Studio on Windows

Android Studio refuses to start due to the error,


Internal error. ...

java.util.concurrent.CompletionExecution: java.net.BindExcetion: Address already in use: bind
...

Apparently, Windows sometimes does release TCP ports completely for some reason, and the solution is to restart the winnat service. 

  1. Open Windows Command Prompt as an Administrator 
  2. Run the following to stop and restart winnat service
    net stop winnat
    net start winnat
    

Alternatively, open PowerShell as an Administrator, and run


Restart-Service -Name winnat

Thursday, March 24, 2022

Stopping Android Emulator From Command Line

To stop all Android emulator instance, we do,


adb emu kill

If we want to kill a specific Android emulator instance, we need to find out the device's serial number or identifier. For this, we do,


adb devices

The typical emulator serial number or identifier is emulator-5554. Using this as an example, we can kill the emulator instance using the command below,


adb -s emulator-5554 emu kill

Tuesday, March 15, 2022

Reinstalling disappeared ddclient

I upgraded a CentOS 8 host to CentOS Stream 8. Later I discovered the ddclient package disappeared. I attempted to install it, and this error occurred. 

$ sudo dnf install ddclient
 Problem: conflicting requests
  - nothing provides perl(Digest::SHA1) needed by ddclient-3.9.1-1.el8.noarch
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
$

A research on the web tells me that I need the PowerTools package. To find out the exact name of the package, 




$ dnf repolist all | grep -i tool
powertools                               CentOS Stream 8 - PowerTools   enabled
powertools-source                        CentOS Stream 8 - PowerTools - disabled
$

Following this, I enable the repo



$ sudo dnf install ddclient
CentOS Stream 8 - PowerTools                    2.5 MB/s | 4.2 MB     00:01
......
......
Complete!
$

Tuesday, February 1, 2022

Purging a directory or a list of files from a Git repository

Sometimes we want to remove a directory or a file at a given path completely from a Git repository's history. BFG Repo-Cleaner is a recommended tool for this. Typical examples examples given are to remove files matching a name or a pattern anywhere in the repository. Sometimes this is not what we wanted, for instance, we want to remove a Readme.md in a particular directory, or remove a doc directory from a repository that has multiple files or directories of those names instead.

Below we show an example where we remove a file or a directory at a particular path. This relies on the following option of BFG Repo-Cleaner,

-bi, --strip-blobs-with-ids <blob-ids-file>  
           strip blobs with the specified Git object ids

where it is noteworthy that the argument given to this option is a file. The file contains Git object hashes of the files we wish to purge. 

In addition, to purge a directory is to purge all the files in the directory; once all of the files are gone, the directory is gone; however, BFG Repo-Cleaner would yield an error if we pass the Git object hash of a directory to it. 

The question becomes how we figure out the Git object hashes of the files we wish to purge. For this, we can use git rev-list command, e.g.,

git rev-list --all --objects | \
      grep "src/Readme.md" | \
      cut -d' ' -f1 > file_hashes.txt

Following this,

bfg -bi file_hashes.txt 

git push --force




Thursday, January 27, 2022

Linux Command Prompt Displays (base), why?

Upon logging to a Linux host, I observe that the command prompt contains (base), e.g,


(base) user@host ~] $

Variable PS1 has the value of (base) [\u@\h \W]\$


(base) [user@host ~] $ echo $PS1
(base) [\u@\h \W]\$

This is because we had Anaconda installed and Anaconda is showing which virtual environment we are in. To get rid of this, we can deactivate this by


conda config --set auto_activate_base false

Tuesday, January 25, 2022

Install pygraphviz on Windows

I wanted to install python package pygraphiz on Windows. However, I encountered an error, as shown below,


C:> python -m pip  install pygraphviz
python -m pip  install pygraphviz
Collecting pygraphviz
  Using cached pygraphviz-1.8.zip (119 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pygraphviz
  Building wheel for pygraphviz (setup.py) ... error
  ERROR: Command errored out with exit status 1:
  ...
  ...
  ...
  pygraphviz/graphviz_wrap.c(2711): fatal error C1083: Cannot open include file: 'graphviz/cgraph.h': No such file or directory
  ...
  ...
  ...

Clearly, the problem is that pip cannot locate the graphviz's header files. Given that I have already installed Graphviz, I reran the pip command as follows, and it solved the problem.


set GRAPHVIZPATH=C:\Applications\Graphviz\Graphviz2.50
python -m pip install --global-option=build_ext --global-option="-I%GRAPHVIZPATH%\include" --global-option="-L%GRAPHVIZPATH%\lib" pygraphviz

In the above, we provide pip with the location of the include files and the library files. Note that it shows that I had graphviz installed at C:\Applications\Graphviz\Graphviz2.50, which should be adjusted according to your set up.