Ubuntu 管理心得

搜尋此網誌

2024年3月30日 星期六

Save export matplotlib image from jupyter to pdf

  1. Right click image
  2. Click 在新頁中開始圖片
  3. Click 新頁
  4. Ctrl-p to print to pdf or printer

 

2024年3月29日 星期五

inside ubuntu run clonezilla

Mount /home/partimage, otherwise clonezilla will mount /home/partimage on root /.
So run these lines before running clonezilla:
 
sudo mkdir /home/partimag (YES! partimag RATHER THAN partimage)
sudo mount /dev/sdd7 /home/partimag
sudo clonezilla
 
ATTN: 在「掛載再生龍…」中,click the last one "skip"

2024年3月25日 星期一

shred wipe all data in ubuntu

sudo shred -vfz /dev/sdX

  1. -n , --iterations=N. Instead of the default (3) times, overwrite the data N times.
  2. -z , --zero. Add a final overwrite with zeros to hide shredding.
  3. -f , --force. Force the permissions to allow writing if necessary.
  4. -v , --verbose. Show progress in detail.
  5. -u , --remove. Truncate and remove file after overwriting.

2024年3月23日 星期六

mkLectNote_clean_tex.sh

#!/bin/bash
TeXfile=$1
LyXfile="${1%.*}.lyx"

sed -i -e '0,/\\maketitle$/d' -e '/^\\end{document}/d' -e '/hypertarget/d' -e 's/\\label.*$//' -e 's/\\section/\\chapter/g' -e 's/\\subsection/\\section/g' -e 's/\\subsubsection/\\subsection/g'  -e 's/\\textgreater/>/'  $TeXfile
sed -i '1 i\\\\def\\mylabel#1{\\label{#1}}' $TeXfile

#sed -i 's/\/\\/g' $TeXfile


jupyter export latex missing label workaround

In jupyter lab, use \mylabel instead of \label e.g 

<img src="if.png" alt="if example flowchart" style="width: 400px;"/>
\begin{figure}
\centering
\includegraphics{if.png}
\caption{if 流程圖}
\mylabel{fig:if 流程圖}
\end{figure}

After export to LaTeX, run 

/home/chiao/scripts/mkLectNote_clean_tex.sh chapterXX.tex

 

2024年3月20日 星期三

jupyter lab traditional Chinese

. .bashrc_anaconda
conda install -c conda-forge jupyterlab-language-pack-zh-TW
 
or
pip install jupyterlab-language-pack-zh-TW

2024年3月8日 星期五

slide show jpeg files, feh

#!/bin/bash
if [ "$#" -lt 2 ]; then
    echo "Usage: $0 <delay sec.> <subdirerory>"
    exit
fi
feh -r -d -Z -D ${1} #{2}


                     

2024年3月3日 星期日

Spyder 正體中文

  1. Download Chinese po file here: http://here.vixual.net/files/python/spyder/Spyder-v5.4.3-zh_TW-20231113.zip
  2. Copy add_traditional_Chinese.py (below) and Spyder-v5.4.3-zh_TW-20231113.zip to the user desktop.
  3. Run the script add_traditional_Chinese.py (Spyder or Python IDLE).
  4. Inside Spyder, Tools -> Preferences -> Application (2nd option on left panel) -> Advanced settings (right panel). Select 正體中文 in Language.
  5. Restart Spyder.

Save the following codes to add_traditional_Chinese.py:

# -*- coding: utf-8 -*-
import os
import zipfile

def unzip_and_copy(zip_file, destination):
    # Unzip the file
    with zipfile.ZipFile(zip_file, 'r') as zip_ref:
        zip_ref.extractall(destination)

def edit_base_file(base_file):
    # Read the contents of the base file
    with open(base_file, 'r', encoding='utf-8') as f:
        lines = f.readlines()

    # Find the index where to insert the new line
    insert_index = -1
    for i, line in enumerate(lines):
        if "简体中文" in line:
            insert_index = i + 1
            break

    if insert_index != -1:
        # Insert the new line
        lines.insert(insert_index, "    'zh_TW': u'正體中文',\n")

        # Write the modified content back to the file
        with open(base_file, 'w', encoding='utf-8') as f:
            f.writelines(lines)
        print("File edited successfully.")
    else:
        print("Line containing '简体中文' not found.")

if __name__ == "__main__":
    # Set paths
    desktop_path = os.path.join(os.getenv('USERPROFILE'), 'Desktop')
    zip_file = os.path.join(desktop_path, 'Spyder-v5.4.3-zh_TW-20231113.zip')
    unzip_destination = os.path.join(os.environ['USERPROFILE'], 'anaconda3', 'Lib', 'site-packages', 'spyder', 'locale')
    base_file = os.path.join(os.environ['USERPROFILE'], 'anaconda3', 'Lib', 'site-packages', 'spyder', 'config', 'base.py')

    # Step 1: Unzip and copy files
    unzip_and_copy(zip_file, unzip_destination)

    # Step 2: Edit base.py
    edit_base_file(base_file)

2024年2月24日 星期六

disable onedrive service for user

 
systemctl --user stop onedrive
systemctl --user disable onedrive
 
delete the symbolic link
sudo rm /etc/systemd/user/default.target.wants/onedrive.service
 
which is linked from 
/usr/lib/systemd/user/onedrive.service
 
 


2024年2月23日 星期五

sync onedrive

#!/bin/bash
if [ "$#" -lt 1 ]; then
#    echo "Usage: $0 <upload_path>"
    echo "Usage: $0 <full local  directory> "
    echo "e.g. $0 /home/chiao/Python"
    exit
fi
SUBDIR=$(basename "$1")
ROOTPATH=$(dirname "$1")
read -p "Start dryrun (press y or n) ? " yn
case $yn in
#     [Yy]* ) echo "Start dryrun (not really uploading) ..." ;onedrive --synchronize --verbose --resync --dry-run;;
#     [Yy]* ) echo "Start dryrun (not really uploading) ..." ;onedrive --syncdir ${1} --synchronize --skip-symlinks  --verbose --dry-run --resync;;
     [Yy]* ) echo "Start dryrun (not really uploading) ..." ;onedrive --syncdir ${ROOTPATH} --single-directory ${SUBDIR} --synchronize --skip-symlinks  --verbose --dry-run --resync;;
#     [Yy]* ) echo "Start dryrun (not really uploading) ..." ;echo "Testing dryrun";;
esac     
read -p "Strat uploading? (press y or n) " yn
case $yn in
#    [Yy]* ) echo "-----------------------------------------------------------";START=$(date +%F\ %T);onedrive --synchronize --verbose --resync; echo "Start at:  $START"; echo "End at: $(date +%F\ %T)"; echo "-----------------------------------------------------------";;
#    [Yy]* ) echo "-----------------------------------------------------------";START=$(date +%F\ %T);onedrive --syncdir ${1} --synchronize --skip-symlinks --verbose --resync; echo "Start at:  $START"; echo "End at: $(date +%F\ %T)"; echo "-----------------------------------------------------------";;
    [Yy]* ) echo "-----------------------------------------------------------";START=$(date +%F\ %T);onedrive --syncdir ${ROOTPATH} --single-directory ${SUBDIR} --synchronize --skip-symlinks --verbose --resync; echo "Start at:  $START"; echo "End at: $(date +%F\ %T)"; echo "-----------------------------------------------------------";;
#     [Yy]* ) echo "-----------------------------------------------------------";START=$(date +%F\ %T); echo "Testing";echo "Start at:  $START"; echo "End at: $(date +%F\ %T)"; echo "-----------------------------------------------------------";;
    [Nn]* ) exit;;
    * ) echo "Please answer yes or no.";;
esac

2024年1月27日 星期六

bash check number of input arguments

#!/bin/bash
if [ "$#" -lt 1 ]; then
    echo "Usage: $0 <arg1>"
    exit
fi

2024年1月20日 星期六

after composer update error "The website encountered an unexpected error. Try again later"

  1. Edit settings.php, set $settings['update_free_access'] = FALSE; to TRUE
  2. Browse http://192.168.1.14/~chiao/drupaldam10_from_9/dam/web/update.php
  3. update the database
  4. Set $settings['update_free_access'] to = FALSE

2024年1月19日 星期五

聯想詞的設定

Edit boshiamy_my.txt, add two codes, e.g.
vdm 矩陣
rect 矩形
Key in "vdf" for 矩, then it will show two codes:
0: 形, 1:陣
to be selected. 


Engineering Graphics Lecture Notes, mkEngGraLectureNotes.sh

#!/bin/bash
docxfile=$1
TeXfile=$2
LyXfile="${2%.*}.lyx"
pandoc --extract-media ./ $docxfile -o $TeXfile
sed -i -e '/hypertarget/d' -e 's/\\label.*$//' -e 's/includegraphics\[width=.*\]/includegraphics/' -e '/includegraphics{/i \\\\begin\{figure\}\n\\begin\{centering\}' -e '/includegraphics{/a \\\end\{centering\}\n\\caption\{\}\n \\\end\{figure\}' -e 's/\\textgreater/>/' $TeXfile
#sed -i 's/\/\\/g' $TeXfile
echo " \\end{document}" >> $TeXfile

cat > tmpfile << EOF
\\documentclass[10pt,a4paper]{extarticle}
\\usepackage[utf8]{inputenc}
\\usepackage{amsmath}
\\usepackage{amsthm}
\\usepackage{fontspec}
\\setmainfont[Mapping=tex-text]{Noto Serif CJK TC}
\\setsansfont[Mapping=tex-text]{Noto Serif CJK TC}
\\setmonofont{Noto Serif CJK TC}
\\usepackage{float}
\\usepackage{graphicx}
\\usepackage[unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=false]
 {hyperref}

\\makeatletter

\\pdfpageheight\\paperheight
\\pdfpagewidth\\paperwidth
\\theoremstyle{definition}
\\newtheorem{example}{\\protect\\examplename}

\\@ifundefined{date}{}{\\date{}}
\\makeatother

\\providecommand{\\examplename}{範例}

\\begin{document}

\\renewcommand{\\footrulewidth}{0.4pt}
\\thispagestyle{empty}\\tableofcontents{}
\\pagebreak{}
\\renewcommand{\\footrulewidth}{0.4pt}
\\thispagestyle{empty}\\tableofcontents{}
\\pagebreak{}
EOF
cat $TeXfile >> tmpfile
mv -f tmpfile $TeXfile
tex2lyx -f $TeXfile

2024年1月18日 星期四

window dialog using zenity with buttons

zenity --question --width=100 --ok-label="Shutdown anyway" --cancel-label="Cancel" --title="Shutdown reminder" --text="Shutdown now?"
status="$?"
if [ "$status" = 0 ]; then
    zenity --info --width=100 --title="Cancel Shutdown" --text="Cancel Shutdown"
fi
else
  gnome-session-quit --power-off
fi

find hiddent subdir

find ~/.\.* -iname "xxx"
grep -ri dynwall .[^.]*
 

Compress with tar 7z

tar --one-file-system -cf - <dirs> | 7z a -mx=9 -mmt=2 -p -si `date +<filename>%Y%m%d_bsun.tar.7z`


2024年1月12日 星期五

software update pop up notification turn off

cf: https://askubuntu.com/questions/1237825/how-to-turn-off-software-updater-pop-up-notification

  1. gsettings set com.ubuntu.update-notifier no-show-notifications true
  2. Or use dconf-editor. Go to /com/ubuntu/update-notifier, and unclick  no-show-notification to false.

Check with:

 gsettings get com.ubuntu.update-notifier no-show-notifications

If shows true, done.

2024年1月8日 星期一

Test video nouveau driver nvidia graphic card

glmark2 -b ideas:duration=10.0:speed=.5 --fullscreen
glmark2 -b :duration=5.0 -b build -b shadow -b shading -b jellyfish --fullscreen

[Scene] buffer
[Scene] build
[Scene] bump
[Scene] clear
[Scene] conditionals
[Scene] desktop
[Scene] effect2d
[Scene] function
[Scene] ideas
[Scene] jellyfish
[Scene] loop
[Scene] pulsar
[Scene] refract
[Scene] shading
[Scene] shadow
[Scene] terrain
[Scene] texture

[Option] speed
    Description  : Time coefficient (1.0 is "wall clock" speed, <1.0 is slower, >1.0 is faster).  A special value of "duration" computes this as a function of the "duration" option
    Description  : Enable random rotation speeds


2024年1月5日 星期五

My boshiamy fcitx

cf: https://newtoypia.blogspot.com/2021/09/fcitx.html
  1. Adding new codes into /download/Boshiamy/boshiamy_my.txt
  2. sudo apt install fcitx-tools
  3. txt2mb boshiamy_my.txt boshiamy_my.mb
  4. cp boshiamy_my.mb /home/chiao/.config/fcitx/table/
  5. sudo cp boshiamy_my.mb /usr/share/fcitx/table/
  6. cd /home/chiao/.config/fcitx/table
  7. mv boshiamy.mb boshiamy_orig
  8. ln -s boshiamy_my.mb boshiamy.mb
  9. cd /usr/share/fcitx/table/
  10. sudo mv boshiamy.mb boshiamy_orig
  11. sudo ln -s boshiamy_my.mb boshiamy.mb
  12. im-config, select fcitx as new input method
  13. logout, then login
  14. Done
 
 

2023年12月30日 星期六

ubuntu 22.04+ 無中文台灣

cf: https://aishuafei.com/ubuntu-chinese-language/
  1. sudo add-apt-repository universe 
  2. sudo apt-get install fcitx fcitx-chewing
  3. 「設定」-> 「地區及語言」->「管理安裝的語言」->「調整輸入法系統」,選取fcitx
  4. 在「語言」tab 中選取並移動「中文台灣」至第一選項
  5. logout, then login
  6. Done
 


2023年12月26日 星期二

Check Pi Camera connected

sudo vcgencmd get_camera

If exists:
    supported=1 detected=1, libcamera interfaces=0

else
    supported=0 detected=0, libcamera interfaces=0


2023年12月15日 星期五

lyx package keyval error

 Delete ~/texmf/tex/latex/hyperref

2023年12月14日 星期四

Remove texlive

 sudo apt-get purge texlive-* -y
 sudo apt-get autoremove -y
 sudo apt-get autoclean -y
 sudo /bin/rm -rf /var/lib/texmf
 sudo /bin/rm -rf /etc/texmf
 sudo /bin/rm -rf /usr/local/share/texmf
 sudo /bin/rm -rf /usr/share/doc/texmf
 sudo /bin/rm -rf /usr/share/doc/texlive
rm -rf ~/.texlive2021
sudo /bin/rm -rf /var/lib/texmf



lmroman12-regular not loadable

 sudo apt-get install fonts-lmodern

2023年12月11日 星期一

pi raspbian backup system

Browse the link: Image File Utilities
Download image-utils.zip

  1. Unzip image-utils.zip to ~/image-copy
  2. cd ~/image-copy
  3. Create shell script, mkpi4.sh from dash line to dash line:
    ----------------------------------------------------------------------
    #!/bin/bash
    if [ "$#" -lt 1 ]; then
        echo "Usage: $0 <path>"
        exit
    fi

    prefix=$1
    IMG=$(date +pi4_bookworm_%Y%m%d.img)
    START=$(date +%F\ %T)
    sudo /bin/bash /home/chiao/image-copy/image-backup --initial $prefix/$IMG,,1000 -o -P,--exclude-from=/home/chiao/image-copy/exclude.txt
    echo "Start:  $START"
    echo "End: $(date +%F\ %T)"
    ----------------------------------------------------------------------
  4. sudo mount -t nfs 192.168.1.2:/BACKUP-nvme1n1p2/pi4 /mnt/nfs
  5. sudo ./mkpi4.sh /mnt/nfs
  6. Wait ...
 



 

 

 


2023年12月9日 星期六

Software and updates not working 軟體與更新 無法開啟

 https://askubuntu.com/questions/789966/software-updates-crashes-and-will-not-open

 

sudo aptitude reinstall apt apt-utils aptdaemon\
 aptdaemon-data update-manager update-manager-core dbus

2023年12月6日 星期三

CKeditor 5 setup for drupal 10

 Go to
     首頁->管理 ->設定-> 內容撰寫 ->文字格式與編輯器
set 文字編輯器 to CKEditor 5

Also, for other 文字格式。

2023年12月3日 星期日

docx to lyx

  1. pandoc --extract-media ./ chapter14_text_2022_111_1.docx -o chap14.tex
  2. cd images/media
  3. rename imagexx.tmp imagexx.png
  4. convert imagexx.emf image40.png
  5. sed -i -e '/hypertarget/d' -e 's/\\label.*$//' -e 's/includegraphics\[width=.*\]/includegraphics/' -e '/includegraphics{/i \\\\begin\{figure\}\n\\begin\{centering\}' -e '/includegraphics{/a \\\\end\{centering\}\n\\caption\{\}\n\\end\{figure\}' -e 's/\\textgreater/>/' chap1.tex
  6. Edit chap1.tex. Add the lines at the beginning:
    \documentclass[10pt,a4paper]{extarticle}
    \usepackage[utf8]{inputenc}
    \usepackage{amsmath}
    \usepackage{amsthm}
    \usepackage{fontspec}
    \setmainfont[Mapping=tex-text]{Noto Serif CJK TC}
    \setsansfont[Mapping=tex-text]{Noto Serif CJK TC}
    \setmonofont{Noto Serif CJK TC}
    \usepackage{float}
    \usepackage{graphicx}
    \usepackage[unicode=true,pdfusetitle,
     bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
     breaklinks=false,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=false]
     {hyperref}

    \makeatletter

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
    \pdfpageheight\paperheight
    \pdfpagewidth\paperwidth


    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
    \theoremstyle{definition}
     \newtheorem{example}{\protect\examplename}

    \@ifundefined{date}{}{\date{}}
    \makeatother

    %\providecommand{\examplename}{範例}

    \begin{document}

    \renewcommand{\footrulewidth}{0.4pt}
    \thispagestyle{empty}\tableofcontents{}
    \pagebreak{}
    \renewcommand{\footrulewidth}{0.4pt}
    \thispagestyle{empty}\tableofcontents{}
    \pagebreak{}
  7. Add the line at the endding:
    \end{document}
  8. import into lyx
  9. inside lyx:
    文件->設定->字型,click 「使用非-TeX字型」,底下全選「Noto Serif CJK TC」
    文件->設定->語言,選「中文(正體)」
    文件->設定->PDF屬性,click「使用 Hyperref 功能」
    文件->設定->浮動框位置,選「肯定在此」
  10. 編輯 LyX 檔內容

2023年12月2日 星期六

lyx 匯入latex 中文亂碼

 Add this line in LaTeX file:

\usepackage[utf8]{inputenc}

網誌存檔