Cheat Sheet

no hurry, no pause.

Last update: 2024-09-28

Start an HTPP Server

python3 -m http.server 8000

The keyboard command Ctrl+C sends a SIGINT

Echo the Name of the Script that is Currently Running

You can use the special shell variable $0. This variable holds the name of the script being executed.

# Echo the name of the script
echo "Running script: $0"

Use the -maxdepth Option with Find

This option limits the search depth to the current directory, preventing it from descending into subdirectories.

# Find the latest 10 modified .md files in the current directory only
LATEST_FILES=$(find . -maxdepth 1 -name "*.md" -type f -exec stat -f "%m %N" {} + | sort -nr | head -10 | cut -d' ' -f2-)

Transform the Absolute Paths into Relative Paths

#!/bin/bash

# Directory containing the Markdown files
DIR="path/to/your/directory"

# Store the current working directory
CURRENT_DIR=$(pwd)

# Change to the directory containing the Markdown files
cd "$DIR" || exit

# Find the latest 10 modified .md files based on modification time
LATEST_FILES=$(find . -name "*.md" -type f -exec stat -f "%m %N" {} + | sort -nr | head -10 | cut -d' ' -f2-)

# Loop over the files and convert each to HTML
for FILE in $LATEST_FILES; do
    # Convert to HTML (using pandoc)
    OUTPUT_FILE="${FILE%.md}.html"

    # Convert only if the output HTML doesn't exist or the MD file is newer
    if [ ! -f "$OUTPUT_FILE" ] || [ "$FILE" -nt "$OUTPUT_FILE" ]; then
        pandoc "$FILE" -o "$OUTPUT_FILE"
        echo "Converted $FILE to $OUTPUT_FILE"
    else
        echo "$OUTPUT_FILE is up to date; skipping conversion."
    fi
done

# Change back to the original directory
cd "$CURRENT_DIR" || exit

Convert .md Files to .html if the .html File is Missing or Outdated

#!/bin/bash

# Directory containing the Markdown files
DIR="path/to/your/directory"

# Find the latest 10 modified .md files based on modification time
LATEST_FILES=$(find "$DIR" -name "*.md" -type f -exec stat -f "%m %N" {} + | sort -nr | head -10 | cut -d' ' -f2-)

# Loop over the files and convert each to HTML
for FILE in $LATEST_FILES; do
    # Convert to HTML (using pandoc)
    OUTPUT_FILE="${FILE%.md}.html"

    # Convert only if the output HTML doesn't exist or the MD file is newer
    if [ ! -f "$OUTPUT_FILE" ] || [ "$FILE" -nt "$OUTPUT_FILE" ]; then
        pandoc "$FILE" -o "$OUTPUT_FILE"
        echo "Converted $FILE to $OUTPUT_FILE"
    else
        echo "$OUTPUT_FILE is up to date; skipping conversion."
    fi
done

Make Script Executable

chmod +x script.sh

Using partials as shown in Pandoc docs. Added ${ footer.html() } at the end of template.html as shown below:

${ footer.html() }

</body>

</html>

This simplifies arguments in Obsidian Export Settings, i.e. removed -A footer.html:

-f ${fromFormat} --resource-path="${currentDir}" --resource-path="${attachmentFolderPath}" --lua-filter="${luaDir}/math_block.lua" --standalone --template template.html --bibliography refs.bib --citeproc --csl apa.csl -o "${outputPath}" -t html

Obsidian Export Settings

-f ${fromFormat} --resource-path="${currentDir}" --resource-path="${attachmentFolderPath}" --lua-filter="${luaDir}/math_block.lua" --standalone --template template.html -A footer.html --bibliography refs.bib --citeproc --csl apa.csl -o "${outputPath}" -t html
--mathjax="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg-full.js"

Terminal Default Directory

How to set a default directory when you open a new Terminal window on macOS:1

  1. Open Terminal.
  2. Go to Terminal > Settings in the menu bar.
  3. Select the “Profiles” tab and choose the profile you are using (usually “Default”).
  4. Duplicate the profile and rename it.
  5. Set the renamed profile to default.
  6. Go to the “Shell” section and check “Run command” box.
  7. In the box, type: cd /path/to/your/default/directory; clear
  8. Close the settings and open a new Terminal window. It should start in the directory you specified.

Typeset Math

\(\LaTeX\)

\(f(x)=\frac{P(x)}{Q(x)}\:\frac{\frac{1}{x}+\frac{1}{y}}{y-z}\:\int_0^\infty \mathrm{e}^{-x}\,\mathrm{d}x\)

\(\left\{\begin{array}{cl} {a_{11}x_1+a_{12}x_2+\cdots+a_{1n}x_n=b_1}\\\vdots \\{a_{21}x_1+a_{22}x_2+\cdots+a_{2n}x_n=b_1}\end{array}\right.\)

\[ \sum_{\substack{0\le i\le m\\ 0\lt j\lt n}} P(i,j) \]

\(\texttt{Typewriter}\)

\(\texttt{CONTINUUM}\)

\(\texttt{continuum}\)

\(\mathbb{CONTINUUM}\)

\(\mathbb{Continuum}\)

Pretty good \(\mathbb{LaTeX}\) equation editor.


  1. Based on steps via ChatGPT.↩︎