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)

網誌存檔