Thursday, July 16, 2020

Set up Google Cloud VM

Setup up ssh

https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys

Note:
$ ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]


Set [USERNAME] for the same user.

Change root password

$ sudo passwd


Change user password

$ sudo passwd [USERNAME]

Install zsh

https://ohmyz.sh/

Graphical user interface (GUI) for Google Compute Engine instance

https://medium.com/google-cloud/linux-gui-on-the-google-cloud-platform-800719ab27c5
https://medium.com/google-cloud/graphical-user-interface-gui-for-google-compute-engine-instance-78fccda09e5c
https://help.realvnc.com/hc/en-us/articles/360003474792-Why-does-VNC-Server-in-Virtual-Mode-on-Linux-appear-to-hang-show-a-gray-screen-or-not-start-at-all-#using-vnc-5-x-or-vnc-connect-6-0-6-1-or-on-a-different-version-of-linux--0-1

Steps:
1. sudo apt install xfce xfce4-goodies vnc4server
2. change .vnc/xstartup to

#!/bin/sh
DESKTOP_SESSION=xfce
export DESKTOP_SESSION
startxfce4
vncserver-virtual -kill $DISPLAY


3. start vncserver
$ vncserver

4. stop vncserver
$ vncserver -kill :1

5. set firewall on Google VM by adding a rule with tag "vnc-server": https://console.cloud.google.com/networking/firewalls/list?_ga=2.140666673.226794997.1594947656-1741100383.1594947656&project=covid-19-283520&folder=&organizationId=
6. add "vnc-server" in "Network tag" in the VM instance
7. On local machine, install RealVNC

Wednesday, December 18, 2019

How to use Docker, GPU on Linux


Ubuntu 18.04

1. Install Docker: https://docs.docker.com/install/

$ sudo apt install docker.io

2. Install NVIDIA docker support: https://github.com/NVIDIA/nvidia-docker

# Add the package repositories
$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
$ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
$ sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
$ sudo systemctl restart docker


3. Grant permission

$ sudo setfacl -m user:pengy6:rw /var/run/docker.sock

4. Download a TensorFlow Docker image

$ docker pull tensorflow/tensorflow:1.15.0-gpu
$ docker pull pytorch/pytorch

5. Start a TensorFlow Docker container

$ docker run -it --rm pytorch/pytorch bash

6. Mount local folder (in order)

$ docker run --mount type=bind,source=source,target=target  -it --rm pytorch/pytorch bash

Tuesday, December 10, 2019

Using Bibtex in MS Word 2015 (Mac OS)

BibTeX is a reference management software for formatting lists of references. It makes it easy to cite sources in a consistent manner. However, BibTex is typically used together with the LaTeX document preparation system.

On the other hand, Microsoft Word is still the most commonly used text editor and used in the group to share documents. Thus, I use BibTex to manage the bibliography and use MS Word to write documents.

One of the most famous reference manager software integrated into Word is EndNote, but unfortunately it is a very expensive and not open-source software. In Windows OS, there is a awesome plug-in called “Bib4Word”, but it is not usable in Max OS.

This post will describe how to use BibTex in MS Word in Mac for free.

To organize BibTex, I am using JabRef, which is an open-source and free reference manager. Please follow the following steps:
  1. In JabRef, export the bibliography in MS Word 2008 xml format
  2. Name the file Sources.xml (case sensitive)
  3. In Mac OS with MS Word 2015, go to ~/Library/Containers/com.microsoft.word/Data/Library/Application Support/Microsoft/Office.
  4. Rename the original Sources.xml file to Sources.xml.bak
  5. Copy the generated Sources.xml in this folder
  6. Restart MS Word.
Now you can choose citations from the list.

Build FreeRDP with smartcard on Ubuntu

Compilation instruction

Besides the suggested base dependencies, also install libpcsclite-dev



sudo apt install libpcsclite-dev
cmake -DWITH_PCSC=ON -DWITH_SSE2=ON .
 
Then follow the Build section in the compilation instruction.

Java data structure to use C implementation of word2vec

Data structure to use C implementation of word2vec. https://github.com/yfpeng/pengyifan-word2vec

Getting started






<dependency>
  <groupid>com.pengyifan.word2vec</groupid>
  <artifactid>pengyifan-word2vec</artifactid>
  <version>0.0.1</version>
</dependency>`
or
















<repositories>
    <repository>
        <id>oss-sonatype</id>
        <name>oss-sonatype</name>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
...
<dependency>
  <groupid>com.pengyifan.word2vec</groupid>
  <artifactid>pengyifan-word2vec</artifactid>
  <version>0.0.1-SNAPSHOT</version>
</dependency>

Webpage

The official word2vec webpage is available with all up-to-date instructions and code.

How to install pip and create virtualenv on Windows without administrative permission

Since Python 2.7.9, pip is released together with the Python. But I still cannot find it when our administrator installed the latest python on my PC. How to install pip, then create virtualenv on Windows without the administrative permission?
  1. Download get-pip.py.
  2. Run python get-pip.py --user. It will install pip locally.
  3. Install virtualenv by running python -m pip install --user virtualenv. This will install the package of virtualenv
  4. Run python -m virtualenv ENV to create a new virtual environment. ENV is a directory to place the new virtual environment.
  5. Activate the script by running ENV/Scripts/activate.bat.
Now you are in the new virtualenv that is isolated from the python that was used to create it.
You can then install python package by running pip install ... as usual.

Install brat on Ubuntu (Apache2)

Install brat

Install Apache2
Download and unzip the brat v1.3
Move the folder to /var/www/brat
In /var/www/brat run ‘./install’. Follow the instruction to set username, password and email.
In etc/apache2/sites-avialble/000-default.conf add









Alias /brat "/var/www/brat"
<Directory "/var/www/brat">
    Options +ExecCGI
    AddHandler cgi-script .cgi
    # AddHandler fastcgi-script fcgi
    AllowOverride Options Indexes FileInfo Limit
    AddType application/xhtml+xml .xhtml
    AddType font/ttf .ttf
</Directory>
Restart apache2:


sudo service apache2 reload

Enable FastCGI

Install fastcgi by running ‘sudo apt-get install libapache2-mod-fastcgi’
Change etc/apache2/sites-avialble/000-default.conf


 
# AddHandler cgi-script .cgi
AddHandler fastcgi-script fcgi