Manjaro UI Improvement

These usages are helpful to build a solution of NAS Status Monitor Visualization.

Fix pacman-mirrors: ModuleNotFoundError

Look for the missing modules failed to be imported:

1
sudo pacman -S python3 python-urllib3 python-charset-normalizer python-idna

Fix blocking pacman upgrade failure

Option 1:
1
2
sudo pacman-mirrors -g -f5
pamac upgrade --force-refresh
Option 2:
1
sudo pacman-mirrors --fasttrack && sudo pacman -Syyu

Also check for

1
yay -Suy

It’s sometimes possibly also needs to remove conflicting packages to proceed, rather than trying to install by force using the pacman options -d/-dd/-nodeps.

Allow installing dependencies from AUR

1
sudo pacman -S yay

UI tools

1
2
3
yay -S gotop
sudo pacman -S bspwm sxhkd polybar picom dunst dmenu nitrogen
sudo pacman -S mpd ncmpcpp

UI modules

1
2
sudo pacman -S rofi calc xorg xorg-xinit xorg-xbacklight alsa-utils
yay -S pywal networkmanager-dmenu

Font dependencies

1
2
sudo pacman -S ttf-font-awesome [ttf-dejavu]
yay -S ttf-material-design-iconic-font ttf-unifont ttf-cascadia-code ttf-nerd-fonts-symbols ttf-material-icons

Check if TTF fonts are present in the OS:

1
2
fc-cache -f -v
fc-list | grep ...

Clock

1
systemctl start mpd.service

Press = after starting ncmpcpp in CLI.

Python Interview Refinement in Mid-2023

LRU Cache

1
2
3
4
5
6
class Node:
def __init__(self, key, value):
self.prev = None
self.next = None
self.key = key
self.val = value
Read more

Arch Linux Environmental Setup FAQ

Dependencies

  • Issue of dependency conflict or failure to find the dependency that should be there:

    sudo pacman -Syu –debug
    It triggers a prompt
    This also performs wide-range package upgrades.

  • Issue of CMake / makepkg -si:

    1
    2
    3
    4
    5
    6
    7
    8
    ==> Starting build()...
    CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".
    CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
    CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
    CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
    -- Configuring incomplete, errors occurred!
    ==> ERROR: A failure occurred in build().
    Aborting...

    To resolve such building depedencies:

    sudo pacman -S base-devel

    1
    2
    3
    4
    5
    Packages (12)
    autoconf-2.71-4 automake-1.16.5-2 bison-3.8.2-5
    debugedit-5.0-5 flex-2.6.4-5 gc-8.2.2-1 guile-3.0.9-1
    m4-1.4.19-3 make-4.4.1-2 patch-2.7.6-9 pkgconf-1.8.1-1
    base-devel-1-2
  • Install pytorch with ROCm backend (read more)

    For CPUs with AVX2 instruction set support, that is, CPU microarchitectures beyond Haswell (Intel, 2013) or Excavator (AMD, 2015), install python-pytorch-opt-rocm to benefit from performance optimizations. Otherwise install python-pytorch-rocm.

    sudo pacman -S python-pytorch-opt-rocm

    This may generate an installation as large as:

    1
    2
    3
    4
    Total Download Size:    2654.00 MiB
    Total Installed Size: 29579.85 MiB

    :: Proceed with installation? [Y/n]

Appearance

Configure a ZFS volume for Time Machine on NAS

Preparation

A ZFS pool should surely pre-exist there to allow for the operations introduced later.

  • Key point: Why not split, or shrink existing volumes for a Time Machine volume?

    Not viable. A ZFS partition always tries to occupy as much space as possible, so does ZFS volumes under it, sharing the entire space of it. To reserving some space is exactly what the quota property is designed for.

    In addition, you can use the reservation property to guarantee that a specified amount of disk space is available to a file system. Both properties apply to the dataset on which they are set and all descendents of that dataset.

    More…

  • Creating a new ZFS filesystem

    zfs create -o compression=lz4 pool/filesystem

    where the purpose of an optional argument -o compression=lz4 is to turn on the compression for this dataset.

Read more

Non Built-in Data Structures And Algorithms in Python3

Unordered MultiSet

1
2
3
4
5
6
7
8
9
10
11
12
13
class MultiSet:
def __init__(self):
self.data = dict()

def add(self, val):
self.data[val] = 1 + (self.data[val] if val in self.data else 0)

def remove(self, val):
if not val in self.data:
return
self.data[val] -= 1
if self.data[val] == 0:
del self.data[val]

Fenwick Tree / Binary-indexed Tree

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class BIT:
def __init__(self, size):
self.size = size
self.data = [0] * size

def add(self, pos, val):
while pos < self.size:
self.data[pos] += val
pos += pos & (-pos)

def query(self, pos):
res = 0
while pos > 0:
res += self.data[pos]
pos &= pos - 1
return res
Read more

Universal Code Competition Template in Python3 (editing) [2022]

Number Theory

Quick power and modulo

To calculate $ n^m % mod $:

Division and modulo

DO NOT dividing an integer by another integer with respect to the modulus $mod$.
To calculate $ n/m%mod $ correctly ($ mod$ is a prime number thus $ φ(mod)=mod-1 $).
Use Eular function or modular multiplicative inversion.

Euler function $ φ(n) $

Quick greatest common divisor

1
2
3
4
5
6
7
8
9
10
11
12
13
def kgcd(a, b):
if a == 0:
return b
if b == 0:
return a
if (a & 1) == 0 and (b & 1) == 0:
return kgcd(a >> 1, b >> 1) << 1
elif (b & 1) == 0:
return kgcd(a, b >> 1)
elif (a & 1) == 0:
return kgcd(a >> 1, b)
else:
return kgcd(abs(a - b), min(a, b))
Read more

How to backup LinkedIn saved posts manually

What?

To export account data from LinkedIn website can be of a lot of muddle and hassle, but the result may not be yet decent for the missing saved posts.

Let’s do this in a manual automated way by scripting.

Solution

Code snippet for saving data as a downloadable JSON file (source):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(function(console){
console.save = function(data, filename){

if(!data) {
console.error('Console.save: No data')
return;
}

if(!filename) filename = 'console.json'

if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
}

var blob = new Blob([data], {type: 'text/json'}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')

a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
}
})(console)

This line looks weird, just an ad-hoc cure when the error of undefined $ occurs with the arrow function operating on the jQuery selector. The cause of error still remains a mystery…

Read more

Apple M1 Development Quick-start

  • Command Line Tools
1
2
3
==> Downloading and installing Homebrew...
xcrun: error: unable to load libxcrun (dlopen(/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib, 0x0005): could not use '/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib' because it is not a compatible arch).
Failed during: git init -q

To get rid of the initial git error, install a complete version of Command Line Tools from Apple Developer site.

Validate Command Line Tools:

sudo xcode-select -p

  • Homebrew

/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  • Curl & wget

brew install curl wget

If you need to have curl first in your PATH, run:

echo ‘export PATH=”/opt/homebrew/opt/curl/bin:$PATH”‘ >> ~/.zshrc

For compilers to find curl you may need to set:

export LDFLAGS=”-L/opt/homebrew/opt/curl/lib”
export CPPFLAGS=”-I/opt/homebrew/opt/curl/include”

  • Oh-my-zsh

Extend the default zsh shell with rich sources of plugins and themes.

  • NVM

You should create NVM’s working directory if it doesn’t exist:

mkdir ~/.nvm

Add the following to ~/.zshrc or your desired shell
configuration file:

1
2
3
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && . "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && . "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion