August 9, 2020

[Note] Ada on Ubuntu 20

Installing Ada


Apt has two packages.  GNAT-GPS (IDE) didn't work properly for me:
  • gnat-gps - integrated development environment for C and Ada
  • gnat - GNU Ada compiler

Get this file from here and install instead -- it will install everything in one directory:
https://www.adacore.com/community


Compiling in console

$ vi helloworld.adb

with Ada.Text_IO;
procedure Hello is
begin
    Ada.Text_IO.Put_Line("Hello, world!");
end Hello;

$ gnatmake helloworld.adb
$ ll
total 52
drwxrwxr-x 2 kkim kkim  4096 Aug  8 20:02 ./
drwxrwxr-x 4 kkim kkim  4096 Aug  8 20:00 ../
-rwxrwxr-x 1 kkim kkim 30000 Aug  8 20:01 helloworld*
-rw-rw-r-- 1 kkim kkim   211 Aug  8 20:02 helloworld.adb
-rw-rw-r-- 1 kkim kkim  1662 Aug  8 20:01 helloworld.ali
-rw-rw-r-- 1 kkim kkim  1640 Aug  8 20:01 helloworld.o
$ ./helloworld
Hello, world!


 
Tutoria, misc
 

Open Source Ada projects

August 8, 2020

[Note] Kinect2 on Ubuntu

This is NOT about XBox-360 Kinect.

Environment: Ubuntu 20.04

Kinect v2, XBox One version + USB adapter for PC

For Win10 and more info, see - https://blog.keithkim.com/2020/02/kinect2-on-windows-motion-detection.html


Install

The whole step is just about downloading, compiling and installing libfreenect2

  • Requires gcc version 8
  • Requires CUDA sample code
  • Requires a lot of apt packages

[1] multiple gcc versions

Default was version 9.  I had to install version 8 and made it as default.

$ sudo apt -y install gcc-7 g++-7 gcc-8 g++-8 gcc-9 g++-9
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 7
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 7
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 8
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9

# select v8:

$ sudo update-alternatives --config gcc
$ sudo update-alternatives --config g++

# check version

$ gcc --version
$ g++ --version

[2] install CUDA sample code

See, https://blog.keithkim.com/2020/08/note-cuda-on-ubuntu-2004.html

[3] Install lots of APT packages

$ sudo apt-get install build-essential cmake autoconf pkg-config doxygen \
 libusb-1.0-0-dev libtool libudev-dev \
 libturbojpeg libjpeg-turbo8-dev \
 mesa-common-dev libgl1-mesa-glx \
 freeglut3-dev libxrandr-dev libxi-dev libva-dev libva-drm2 \
 openni2-utils

[4] compile libfreenect2

If want to disable CUDA, change cmake line as below,

$ cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2 -ENABLE_CUDA OFF

If CUDA is installed, and you have the sample, type this before make to point where the sample is installed,

$ export CPATH=$CPATH:$HOME/NVIDIA_CUDA-10.1_Samples/common


$ git clone https://github.com/OpenKinect/libfreenect2.git
$ cd libfreenect2
$ mkdir build && cd build
$ cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2
$ make
$ sudo make install
$ sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/
 

# Unplug, plug in Kinect first
# you may have to add yourself to 'plugdev' group.

$ ./bin/Protonect

 

Closing

 Using it in Python, OpenCV will be another posting.


Reference

 

August 7, 2020

[Note] CUDA on Ubuntu 20.04

Install Options

A couple of ways to install CUDA:

  1. get everything from NVIDIA CUDA site
  2. apt-get
  3. docker

 

For the latest CUDA version,  do method #1.  For easier way, #2.  I chose to do #2.  But after went through it, I'm not sure if it's really easier. 

And #2 method, the CUDA version is 10.1.  I haven't tried docker method.

 

Install

Checking driver version:

$ nvidia-smi


Fri Aug  7 18:35:38 2020      
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.100      Driver Version: 440.100      CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0   Quadro P2000        Off  | 00000000:09:00.0  On |                  N/A |
| 53%   47C    P8     7W /  75W |    663MiB /  5057MiB |     17%      Default |
+-------------------------------+----------------------+----------------------+
...


Install packages using apt-get

$ sudo apt-get install build-essentials nvidia-cuda-toolkit

Check nvcc version:

$ nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243


Install cudnn

  1. Download cudnn, https://developer.nvidia.com/cudnn
  2. uncompress
  3. sudo cp cuda/include/cudnn.h /usr/lib/cuda/include/
    sudo cp cuda/lib64/libcudnn* /usr/lib/cuda/lib64/
    sudo chmod a+r /usr/lib/cuda/include/cudnn.h /usr/lib/cuda/lib64/libcudnn*


Install sample codes

Using apt-get, it doesn't come with sample codes.  For installing Kinect2 (will be on another posting), the sample is needed.  Install only if you need it.

Download from github, https://github.com/NVIDIA/cuda-samples/tree/10.1.2 

And store it anywhere you want.  Note that some other dependent code may look for it in a certain path, such as /usr/local/cuda-X-Y...


A couple more things to do:

[1] 

nvcc is installed in /usr/bin/  -- examples and some programs I use (sorry didn't write it down and forgot what it was) looks for it in /usr/local/cuda/bin.  Create a sym link there.

[2] vi .vashrc

export LD_LIBRARY_PATH=/usr/lib/cuda/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/lib/cuda/include:$LD_LIBRARY_PATH


Reference

 

CUDA Samples

  1. https://docs.nvidia.com/cuda/cuda-samples/index.html
  2. https://github.com/NVIDIA/cuda-samples/tree/10.1.2
  3. https://www.pugetsystems.com/labs/hpc/How-To-Install-CUDA-10-together-with-9-2-on-Ubuntu-18-04-with-support-for-NVIDIA-20XX-Turing-GPUs-1236/#step-6-test-cuda-by-building-the-samples-from-source-for-both-cuda-92-and-cuda-100


Nvidia Docker

 

August 2, 2020

SikuliX on Linux - vision based automation

http://sikulix.com

It's a vision based automation tool, you give an image, it will find a match and do automation.  It's a great open source tool.

I used this on Windows, and now my main OS is Ubuntu, and this is some information and note on it.  It uses OpenCV and Tesseract OCR.

https://avleonov.com/wp-content/uploads/2017/02/script_window.png

Install On Ubuntu 20.04

Installing and using SikuliX on Window is simple and straightforward.  On Linux (Ubuntu 20.04 for my case), it needs little bit more work.

Requirements
  • OpenCV
  • Tesseract OCR
  • Java 11 or later

1. Download SikuliX

Download it from https://raiman.github.io/SikuliX1/downloads.html
or do
$ wget https://launchpad.net/sikuli/sikulix/2.0.4/+download/sikulixide-2.0.4.jar

2. Install Java 11 or later
  • This will not work with Java8. 
  • OpenJDK works fine.
  • Dealing with multiple Java versions: I have Java 8, 11, 14, and Oracle JDK8 as well.  My default Java is set to 8.  To run this software with Java 14, I used bash script, and added using Alacarte (https://en.wikipedia.org/wiki/Alacarte)
3. Install/Set up OpenCV, Tesseract OCR

$ sudo apt-get install libopencv4.2-java libopencv4.2-jni
$ sudo apt-get install tesseract-ocr

$ cd /usr/lib/jni/
$ sudo ln -s libopencv_java420.so libopencv_java.so


4. Bash script

#!/usr/bin/bash
JAVA_HOME=/usr/lib/jvm/java-14-openjdk-amd64
SIKULIX_HOME=/opt/sikulix
SIKULIX_JAR=sikulixide-2.0.4.jar
LOG=$SIKULIX_HOME/sikulix.log
$JAVA_HOME/bin/java -jar $SIKULIX_HOME/$SIKULIX_JAR >> $LOG 2>&1


SikuliX Resources

Other Resources

Other opensource or free automation tools

July 29, 2020

[dev note] anaconda and uwsgi

conda search doesn't show uwsgi, and pip install fails with various python versions.

Finally found the solution after a couple of days of frustration --
https://anaconda.org/conda-forge/uwsgi

conda install -c conda-forge uwsgi

July 27, 2020

Joplin - Onenote, Evernote replacement

About 10 years or so ago, I wrote a posting on Evernote when it was new and shiny.  Back then it was revolutionary, before Onenote added feature for sharing across multiple devices.

After it started to charge more than I'm willing to pay, and limiting storage spaces, I stopped using it.  And OneNote started to offer the same features and I had/still have license for it.  OneNote is free now, I believe.  I stopped using it as well -- I didn't like some of its features and how it works.

Since then I've been using just text editor and share the note via cloud services, gave up finding alternative solutions.

There is Joplin - https://joplinapp.org/
Open Source, free, available for all OS and mobile devices, and sync via cloud services.  I like that I have the control how/where my notes are stored/sync'd.

Joplin Adds Experimental WYSIWYG Editor



Some notes on Ubuntu


If Joplin is installed through SNAP, due to SNAP's security model, it has some limitation where notes are stored/backed up for directory sync.

Notes are stored in /home/$USER/snap/joplin-james-carroll/13/.config/joplin-desktop
(See this by going to Tools > General)  I don't think this location can be changed -- at least I haven't found how.

If sync to directory, due to SNAP model, this directory cannot be outside of user home directory.  Sym link won't work.



Installer versions

If preferred, use Desktop installer version.  There is no restriction which directory you want to sync (backup).

wget -O - https://raw.githubusercontent.com/laurent22/joplin/master/Joplin_install_and_update.sh | bash

Installer version stores the notes in, ~/.config/joplin-desktop

For terminal version of Joplin, https://joplinapp.org/terminal/

$ NPM_CONFIG_PREFIX=~/.joplin-bin npm install -g joplin
$ sudo ln -s ~/.joplin-bin/bin/joplin /usr/bin/joplin


Terminal version stores the notes in, ~/.config/joplin

Removing Installer version

Desktop version
$ rm ~/.joplin
$ rm ~/.local/share/applications/appimagekit-joplin.desktop

Remove note files and configuration
$ rm ~/.config/joplin-desktop

Terminal version,
$ sudo rm /usr/bin/joplin
$ rm -rf ~/.joplin-bin

To remove note files,
$ rm ~/.config/joplin


Warning on Desktop Joplin on Ubuntu 20.04

This is for both SNAP and installer versions for Desktop Joplin.

Tools > Options > Application, there is "Show tray icon".  This doesn't work for me.  If checked, and close the Joplin window by click on "X" button, it disappears but stay in memory.  Only way to get it back is run Joplin again.  You have to File > Quit to properly quit the application.  If "Show tray icon" is not checked off, closing Joplin window by clicking on "X" button will quit the application.


[Note] Gitea in Docker


Gitea (https://gitea.io/en-us/) is like a light weight Gitlab.

I wrote on Gitea previously, running on my personal server,
https://blog.keithkim.com/2019/03/ownserver-gitea-host-own-github-gitlab.html


Again, my server goes up and down depends on the schedule I set it to.  It usually in sleep mode and wakes up according the the schedule I set.  My main computer is on almost all day but the server is not as it's not heavily used.

This posting is a note on installing Gitea in Docker.

Docker image page, https://hub.docker.com/r/gitea/gitea

Pull the image,
$ docker pull gitea/gitea

Gitea official shows using docker-compose to customize further, https://docs.gitea.io/en-us/install-with-docker/ -- for my use, default works for me.  No volume mapping, no DB.

Run it,

$ docker run --name gitea -p 3000:3000 -p 222:22 -d gitea/gitea
$ docker logs -f gitea


Access it,
http://localhost:3000

  1. Click on "Sign-in" at upper-right corner, and it'll show Initial Configuration page.
  2. Configure as needed (for my case/this posting, no mysql, external volume is mapped).
  3. And then register user -- that will be the admin.