Hexa's Blog

How to make executable jar with Gradle?

16/12/2021 Linux

Gradle is a build automation tool for multi-language software development. It controls the development process in the tasks of compilation and packaging to testing, deployment, and publishing. Supported languages include Java (as well as Kotlin, Groovy, Scala), C/C++, and JavaScript. The other, if not the major function of Gradle is to collect statistical data about the usage of software libraries around the globe.

In this post, I would like to introduce a solution to create an executable jar with Gradle. All modification related to a file named build.gradle. This file located at /project-root/app/build.gradle. By default, this file will be generated with Gradle init task.

There are three part concerned:

  • Add a plugin named application to plugins block.
plugins {
    // Apply the application plugin to add support for building a CLI application in Java.
    id 'application'
}
  • Define mainClass in application block.
application {
    // Define the main class for the application.
    mainClass = 'JekyllPostGenerator.App'              # MODIFY IT
}
  • Define jar block.
jar {
    archiveBaseName = 'jekyll-post-generator'          # MODIFY IT
    archiveVersion =  '2.0.0'                          # MODIFY IT
    manifest {
        attributes(
               'Main-Class': 'JekyllPostGenerator.App' # MODIFY IT
        )
    }
}

Last but not least, you need to run gradle task named jar to created an executable jar file which would be created in /root-project/app/build/libs. Regarding above configuration, my executable file will be jekyll-post-generator-2.0.0.jar. This file now can be executed with java -jar jekyll-post-generator-2.0.0.jar. And this is a command to create jar file.


# In the project-root
./gradlew jar

[1] `gradlew jar` task output example.
[1] `gradlew jar` task output example.

How to install VGA - GTX 1060 on Fedora with Secure Boot enabled?

15/12/2021 Linux

In this post, I would like to introduce solution to install VGA drivers for 1060 on Fedora with enabled SECURE BOOT.

Step 1: Determine vga installed on the motherboard.

On terminal, use the following command to see avaialble installed VGA.

lspci |grep -E "VGA|3D"

Example output:

02:00.0 VGA compatible controller: NVIDIA Corporation GP106 [GeForce GTX 1060 6GB] (rev a1)
04:00.0 VGA compatible controller: ASPEED Technology, Inc. ASPEED Graphics Family (rev 30)

Step 2: Download nvidia driver from Nvidia Official Website

[1] NVIDIA Driver Downloads
[1] NVIDIA Driver Downloads

In this post, I would like to pick the latest stable version 510.68.02 which was released on April 26, 2022. After your downloading finished, remember to make the file executable with chmod +x NVIDIA-Linux-x86_64-510.68.02.run, and copy it to $HOME/Software/VGA-1060-key, you will need to execute this file each time your update your kernels.

mkdir -p $HOME/Software/VGA-1060-key;
cd $HOME/Software/VGA-1060-key;
wget https://us.download.nvidia.com/XFree86/Linux-x86_64/470.94/NVIDIA-Linux-x86_64-470.94.run;
chmod +x NVIDIA-Linux-x86_64-470.94.run;

Step 3: Generate new pair private-key and public-key

mkdir -p $HOME/Software/VGA-1060-key/key;
cd $HOME/Software/VGA-1060-key/key;
openssl req -new -x509 -newkey rsa:2048 -keyout vga-1060.key -outform DER -out vga-1060.der -nodes -days 365000 -subj "/CN=Graphics Drivers";

Your directory tree should look like:

[2] Directory Tree
[2] Directory Tree

Step 4: Enroll new public key with mokutil

You need to run this command to import your new public key with mokutil, this program will ask you a password for enrolling, which then be asked in the next reboot.

sudo mokutil --import $HOME/Software/VGA-1060-key/key/vga-1060.der;

Step 5: Make install.sh in VGA-1060-key directory

This is install.sh content:

#!/bin/bash
./NVIDIA-Linux-x86_64-510.68.02.run --module-signing-secret-key=/home/YOUR_USERNAME/Software/VGA-1060-key/key/vga-1060.key \
                                    --module-signing-public-key=/home/YOUR_USERNAME/Software/VGA-1060-key/key/vga-1060.der

Each time you update your kernel, you need to go boots OS with level 3 and run this script install.sh.

[3] Directory Tree
[3] Directory Tree

Step 5: Install package dependencies & update OS

This step ensure you got the lastest kernel & all dependent packages.

sudo dnf install kernel-devel kernel-headers gcc make dkms acpid libglvnd-glx libglvnd-opengl libglvnd-devel pkgconfig;
sudo dnf update;

Step 6: Disable nouveau

  • Create or edit /etc/modprobe.d/blacklist-nouveau.conf
sudo echo "blacklist nouveau" >> /etc/modprobe.d/blacklist-nouveau.conf
  • Edit /etc/default/grub Append following flag to the end of GRUB_CMDLINE_LINUX
    • rd.driver.blacklist=nouveau
    • modprobe.blacklist=nouveau
    • nvidia-drm.modeset=1

For example:

[4] /etc/default/grub
[4] /etc/default/grub

Step 7: Update grub2 config & generate new initramfs

grub2-mkconfig -o /boot/grub2/grub.cfg;

## Backup old initramfs nouveau image ##
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-with-nouveau.img;

## Generate new initramfs image ##
dracut /boot/initramfs-$(uname -r).img $(uname -r);

Step 8: Boots OS on level 3 and execute the install.sh

Boots OS on level 3 and reboot

sudo systemctl set-default multi-user.target;
sudo shutdown -r now;

After login, go to VGA-1060-key directory and execute install.sh. At this step, just keep accepting and the driver will be installed.

cd /home/nguyenvinhlinh/Software/VGA-1060-key;
sudo ./install.sh;

After installing vga driver, you will need reboot OS on level 5 - graphical

systemctl set-default graphical.target;
shutdown -r now;

Next time, if you update your kernel, you can run this step (Step 8) again, it should be fine. In addition, you should encrypt your private-key with gpg, it’s not a good practice leave it unencrypted. You can check this guide Mã hóa và giải mã file trên linux sử dụng GPG

Reference

PhoenixMiner - config.txt Template

08/12/2021 Mining Rig

# PhoenixMiner configuration file config.txt

-pool   asia1.ethermine.org:4444
-pool2  asia2.ethermine.org:4444
-wal    miner_address_here
-worker huyen-vu

Personal Note: Installing a Monero full node

I. Monero Node Config - monerod.conf

# /opt/monero-gui-v0.17.2.3/monerod.conf

# Data directory (blockchain db and indices)
data-dir=/mnt/disk_2/Monero/  # Remember to create the monero user first

# Log file
log-file=/mnt/disk_2/Monero/log/monerod.log
max-log-file-size=0            # Prevent monerod from managing the log files; we want logrotate to take care of that

# P2P full node
p2p-bind-ip=0.0.0.0            # Bind to all interfaces (the default)
p2p-bind-port=18080            # Bind to default port

# RPC open node
rpc-bind-ip=0.0.0.0            # Bind to all interfaces
rpc-bind-port=18081            # Bind on default port
confirm-external-bind=1        # Open node (confirm)
restricted-rpc=1               # Prevent unsafe RPC calls
no-igd=1                       # Disable UPnP port mapping

# Slow but reliable db writes
db-sync-mode=safe:sync
block-sync-size=100

# Emergency checkpoints set by MoneroPulse operators will be enforced to workaround potential consensus bugs
# Check https://monerodocs.org/infrastructure/monero-pulse/ for explanation and trade-offs
enforce-dns-checkpointing=1

out-peers=64              # This will enable much faster sync and tx awareness; the default 8 is suboptimal nowadays
in-peers=1024             # The default is unlimited; we prefer to put a cap on this

limit-rate-up=1048576     # 1048576 kB/s == 1GB/s; a raise from default 2048 kB/s; contribute more to p2p network
limit-rate-down=1048576   # 1048576 kB/s == 1GB/s; a raise from default 8192 kB/s; allow for faster initial sync

II. Systemctl service - /etc/systemd/system/monero.service

[Unit]
Description=Monero Full Node
After=network.target  mnt-disk_2.mount

[Service]
WorkingDirectory=/opt/monero-gui-v0.17.2.3
ExecStart=/opt/monero-gui-v0.17.2.3/monerod --config-file /opt/monero-gui-v0.17.2.3/monerod.conf --detach
User=nguyenvinhlinh
RemainAfterExit=yes
Restart=on-failure
RestartSec=10
TimeoutStopSec=infinity

[Install]
WantedBy=multi-user.target

III. Firewall-cmd service - /etc/firewalld/services/monero.xml

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>Monero node</short>
  <description>
    This option allows Monero node to use tcp port:
    - 18080: p2p network
    - 18081: JSON-RPC server
  </description>
  <port protocol="tcp" port="18080"/>
  <port protocol="tcp" port="18081"/>
</service>

Personal Note: Installing an Alephium full node

I. Alephium node config - $ALEPHIUM_HOME/user.conf

alephium.network.external-address="x.x.x.x:9973"
alephium.api.network-interface = "0.0.0.0"
alephium.mining.api-interface="0.0.0.0"

alephium.mining.miner-addresses=[
 "miner_address_1",
 "miner_address_2",
 "miner_address_3",
 "miner_address_4",
]

II. Systemctl EnvironmentFile - /opt/alephium/alephium.env

ALEPHIUM_HOME=/mnt/CaHeoNas/disk_3/Alephium

III. Systemctl service - /etc/systemd/system/alephium.service

[Unit]
Description=Alphelium Full Node
After=network.target mnt-CaHeoNas-disk_3.mount

[Service]
WorkingDirectory=/opt/alephium
EnvironmentFile=/opt/alephium/alephium.env
ExecStart=java -jar -Xms512m -Xmx1028m alephium-1.0.0.jar
User=nguyenvinhlinh
RemainAfterExit=yes
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

IV. Firewall-cmd service - /etc/firewalld/services/alephium.xml

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>Alephium node</short>
  <description>
    This option allows Alephium node to use tcp port 9973, 10973, 12973
  </description>
  <port protocol="tcp" port="9973"/>
  <port protocol="tcp" port="10973"/>
  <port protocol="tcp" port="12973"/>
</service>

IV. Balance checking script

All Credit goes this guy Mark Rahmani (diomark#8272) https://www.facebook.com/diomark/

#!/bin/zsh

#first need to unlock wallet. not putting password in here

#check wallet
curlResult=`curl -X 'GET'   'http://127.0.0.1:12973/wallets/MINER_WALLET_NAME/balances'   -H 'accept: application/json' 2>/dev/null | json_pp | grep totalBalanceHint| cut -f1 -d","`
lastdate=`date +%s`


if echo $curlResult | grep -q ALPH; then
  datestr=`date +"%x %R"`
  echo -n "$datestr "
  echo Wallet unlocked - $curlResult;
else
  echo Please unlock wallet first
  exit
fi

while true; do
 oldResult=$curlResult

 datestr=`date +"%x %R"`; echo -n "."; curlResult=`curl -X 'GET'   'http://127.0.0.1:12973/wallets/MINER_WALLET_NAME/balances'   -H 'accept: application/json' 2>/dev/null | json_pp | grep totalBalanceHint| cut -f1 -d","`
 if [ "$oldResult" != "" ]; then
    if [ "$curlResult" != "$oldResult" ]; then
       echo
       echo -n "$datestr "
       newdate=`date +%s`
       secs=`expr $newdate - $lastdate`
       mins=`expr $secs / 60`
       echo  -n "Won a block after $mins minutes! "
       echo $curlResult
       lastdate=$newdate
    fi
 fi

 sleep 30
done

Balance Checking Script Output.
Balance Checking Script Output.

Personal Note: Installing a Bitcoin full node

I. Systemctl service - /etc/systemd/system/bitcoin.service

[Unit]
Description=Bitcoin Full Node
After=network.target  mnt-disk_2.mount

[Service]
WorkingDirectory=/opt/bitcoin-0.21.1/
ExecStart=/opt/bitcoin-0.21.1/bin/bitcoind -datadir=/mnt/disk_2/Bitcoin -daemon
ExecStop=/opt/bitcoin-0.21.1/bin/bitcoin-cli -datadir=/mnt/disk_2/Bitcoin stop
User=nguyenvinhlinh
RemainAfterExit=yes
Restart=on-failure
RestartSec=10
TimeoutStopSec=infinity

[Install]
WantedBy=multi-user.target

II. Firewall-cmd service - /etc/firewalld/services/bitcoin.xml

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>Bitcoin node</short>
  <description>This option allows Bitcoin node to use tcp port 8333</description>
  <port protocol="tcp" port="8333"/>
</service>

Thiết lập thông số 3080 - Dàn #2 Bạch Hổ

01/10/2021 Mining Rig

I. Lời mở đầu

Bài viết này phục vụ mục đích duy nhất là đó là nếu tôi lỡ tay xóa mấy profile trên MSI Afterburner. Tôi sẽ quay lại đây xem.

  • MSI 3080 GAMING X TRIO (1 cái)
  • MSI 3080 VENTUS (2 cái)
  • GIGABYTE 3080 GAMING OC 10G (1 cái)
Vị Trí trên main VGA Vị trí trên OS
1 MSI 3080 GAMING X TRIO 3
2 MSI 3080 VENTUS 1
3 MSI 3080 VENTUS 2
4 GIGABYTE 3080 GAMING OC 10G 4
[1] Dàn 3080 - #2 Bạch Hổ
[1] Dàn 3080 - #2 Bạch Hổ

II. Ethereum - MSI Afterburner - 95MH/s

a. Tinh chỉnh tốc độ quạt theo nhiệt độ

  • 30C –> 40% Fan
  • 50C –> 80% Fan
  • 60C –> 90% Fan
  • 65C –> 100% Fan
[2] Tinh chỉnh tốc độ quạt
[2] Tinh chỉnh tốc độ quạt

b. Tinh chỉnh MSI Afterburner

No. VGA Power Limit Temp. Limit Core Clock Mem Clock
1 MSI 3080 VENTUS 77% priority 65C -502MHz +900Mhz
2 MSI 3080 VENTUS 77% priority 65C -502MHz +900Mhz
3 MSI 3080 GAMING X TRIO 106% priority 65C -502MHz +825Mhz
4 GIGABYTE 3080 GAMING OC 10G 64% priority 65C -502MHz +900Mhz

c. Kết quả thu được

No. VGA Power Consumption Hashrate GPU Temperature Memory Temperature
1 [1] MSI 3080 VENTUS 246W 96.50Mh/s 61C 90C
2 [2] MSI 3080 VENTUS 246W 96.01Mh/s 64C 90C
3 [3] MSI 3080 GAMING X TRIO 229W 95.02MH/s 62C 106C
4 [4] GIGABYTE 3080 GAMING OC 10G 236W 95.51Mh/s 65C 90C
           
  Total 957 Walt 383.04 MH/s    

III Ethereum - Minerstat - 95 MH/s

a. Tinh chỉnh ClockTune

  • Mode: Built-in (Default)
  • Power Limit (%): skip
  • Core Clock (-/+ MHz): skip
  • Locked Memory Clock (MHz):skip
  • Force P2 State: skip
  • ClockTune delay: 30
No. No. VGA Power Limit (Walt) Locked Core Clock (MHz) Memory Clock (-/+ MHz)
1 MSI 3080 VENTUS 240 1170 950
2 MSI 3080 VENTUS 240 1170 950
3 MSI 3080 GAMING X TRIO 392 1170 950
4 GIGABYTE 3080 GAMING OC 10G 240 1170 950

b. Triggers trong Minerstat

  • IF GPU temperature OF Any IS >=40°C THEN Set fans TO 60%
  • IF GPU temperature OF Any IS >=50°C THEN Set fans TO 85%
  • IF GPU temperature OF Any IS >=55°C THEN Set fans TO 90%
  • IF GPU temperature OF Any IS >=60°C THEN Set fans TO 95%
  • IF GPU temperature OF Any IS >=65°C THEN Set fans TO 100%

c. Kết quả thu được

No. No. VGA Power Consumption Hashrate GPU Temperature Memory Temperature
1 MSI 3080 VENTUS 228 Walt 97.468 MH/s 51C 82C
2 MSI 3080 VENTUS 236 Walt 97.588 MH/s 57C 84C
3 MSI 3080 GAMING X TRIO 221 Walt 96.377 MH/s 54C 102C
4 GIGABYTE 3080 GAMING OC 10G 227 Walt 97.529 MH/s 58C 82C
           
  Total 912 Walt 388.962 MH/s    
[3] Minerstat
[3] Minerstat

CSGO, binding để nhảy ném smoke

15/09/2021 CSGO

Trong trường hợp này phím nhảy ném là phím mouse-5. Mở console lên và gõ lệnh sau:

alias +jumpthrow "+jump;-attack";
alias -jumpthrow "-jump";
bind mouse5 +jumpthrow;

Cách sử dụng tương đối đơn giản, bắt đầu bằng giữ chuột trái, tiếp theo là căn góc ném, cuối cùng là ấn phím mouse-5.

Support dropdown with multiple value in Redash, plus ALL value

09/09/2021 Redash

In Redash, there is a big demand for dropdown with ALL value. However, it’s tricky to write where statement for ALL value. This post is all about work-around this issue. Thank for my colleague - Trieu. All Credit to him.

[1] Dropdown Field
[1] Dropdown Field

The dropdown configuration is in the following image.

[2] Dropdown Configuration
[2] Dropdown Configuration

In the where section, condition statement should look like this one

(column_name in (SELECT unnest(CONCAT('{', '', '}')::varchar[])) OR '' LIKE '%ALL%')

And It’s all done, you are ready to go!

Cách thiết lập GPG cho Emacs trên Window

01/09/2021 Emacs

Bài viết này hướng dẫn cách cài đặt GPG cho emacs trên window. Đầu tiên, cần vào trang web https://gnupg.org/download/index.html và tải Gpg4Win

[1] Download Gpg4Win
[1] Download Gpg4Win

Sau khi cài đặt xong Gpg4Win. Trong emacs, thiết lập các biến sau:

  • epg-gpg-home-directory
  • epg-gpg-program
  • epg-gpgconf-program

Ví dụ như sau:

(custom-set-variables
 '(epg-gpg-home-directory "C:/Users/nguye/AppData/Roaming/gnupg")
 '(epg-gpg-program "D:/Software/GnuPG/bin/gpg.exe")
 '(epg-gpgconf-program "D:/Software/GnuPG/bin/gpgconf.exe")
 )

(provide 'window-gpg)