Pre-Print meines neuen TikZ-Artikels

Für die DTK habe ich einen neuen Artikel zum Thema TikZ geschrieben, hier das Pre-Print PDF und der LaTeX-Quelltext.

Ein Folgeartikel ist bereits in der Entstehung.

Uwe-TikZ (PDF)

Uwe-TikZ (Quellcode)

ADSR Hüllkurve mit TikZ

Hier die Darstellung einer ADSR Hüllkurve (Quelle: Wikipedia) mit TikZ:

\begin{tikzpicture}
%\draw[step=0.5cm,lightgray,thin] (0,0) grid (10,7);
\draw[very thick, black,->](1,1) -- (9.5,1);
\draw[very thick, black,->](1,1) -- (1,6.5);
\draw[very thick, green,](3,1) -- (3,6);
\draw[very thick, orange,](5,1) -- (5,6);
\draw[very thick, black](7,1) -- (7,6);
\draw[very thick, magenta](9,1) -- (9,6);
 
\draw[very thick, gray,](1,1) -- (3,5.5) -- (5,4) -- (7,4)--(9,1);
% max amp line
\draw[thick, gray,dotted](0.8,5.5) -- (9.5,5.5);
 
\draw[very thick, blue,->](6,1.1) -- (6,3.9);
 
\draw[very thick, green,->](1.1,5.65) -- (2.9,5.65);
\draw[very thick, orange,->](3.1,5.65) -- (4.9,5.65);
 
\draw[very thick, blue](5.1,4) -- (6.9,4);
 
\draw[very thick, magenta,->](7.1,5.65) -- (8.9,5.65);
 
\node[label=left:0] (A) at (1,1) {};
\node[label=below:t] (B) at (9.5,1) {};
\node[label=left:{{\scriptsize Amp\textsubscript{max}}}] (C) at (1,5.5) {};
 
\node[label=above:A] (D) at (2,5.5) {};
\node[label=above:D] (E) at (4,5.5) {};
\node[label=left:S] (F) at (6,2.5) {};
\node[label=above:R] (G) at (8,5.5) {};
 
\draw[very thick, black,->](1,0.5) -- (1,0.9);
\draw[very thick, black,->](7,0.5) -- (7,0.9);
 
\node[label=above:{Key press}] (D) at (1.1,-0.2) {};
\node[label=above:{Key release}] (D) at (7.2,-0.2) {};
 
\end{tikzpicture}

Das thematicpuzzle Paket

Es gibt ein neues Paket auf CTAN, thematicpuzzle. Damit gehen dann TikZ-basiert Dinge wie die folgenden (der Anleitung entnommen):

Video meines Vortrags zu „LaTeX-Formulare erstellen mit eforms“

Unter https://www.youtube.com/watch?v=WMCj_EPDms8 ist jetzt das geschnittene Video meines Vortrags zur „Formularerstellung mit eforms“ online.

Python und LaTeX in einem Lauf kombinieren mit pylualatex

Mi dem pylualatex Paket gibt es eine neue Möglichkeit, Python und LaTeX miteinander zu „verheiraten“. Das Besondere an diesem Paket ist, dass es keine zwei Durchläufe benötigt, sondern nur einen einzigen.

%!TEX TS-program = Arara
% arara: lualatex: {shell: yes}
 
\documentclass{article}
 
\usepackage[executable=python.exe,localimports=false]{pyluatex} 
 
\begin{document}
 
\py{2**2**2}
 
\end{document}

SFTP mit Python und der Paramiko-Bibliothek – Upload

Neben dem Download von Dateien klappt auch der Upload von Dateien problemlos.

import os
import paramiko
 
# Replace these variables with your specific values
host = '192.168.0.22'
port = 22
username = '<user>'
private_key_path = 'keyfile'
remote_directory_path = '/home/uwe/uploadtest'
local_directory_path = 'E:/uploadtest'
 
 
# Establish an SSH transport session
private_key = paramiko.RSAKey(filename=private_key_path)
transport = paramiko.Transport((host, port))
transport.connect(username=username, pkey=private_key)
 
# Create an SFTP client
sftp = paramiko.SFTPClient.from_transport(transport)
 
try:
    # Iterate through local files in the specified folder
    for local_file in os.listdir(local_directory_path):
        local_file_path = os.path.join(local_directory_path, local_file)
 
        # Check if the file is a CSV file
        if os.path.isfile(local_file_path): # and local_file.lower().endswith('.csv'):
            remote_file_path = os.path.join(remote_directory_path, local_file)
 
            # Upload the CSV file
            sftp.put(local_file_path, remote_file_path)
            print(f"Uploaded: {local_file} to {remote_file_path}")
 
finally:
    # Close the SFTP session and SSH transport
    sftp.close()
    transport.close()

SFTP mit Python und der Paramiko-Bibliothek – Download

Aktuell benötige ich Funktionen, um mit Python Dateien von SFTP Servern zu holen bzw. Dateien auf diese hochzuladen. Chat GPT hatte folgenden Code für mich, der sehr gut funktioniert.

import os
import paramiko
 
# Replace these variables with your specific values
host = '192.168.0.238'
port = 22
username = '<user>'
private_key_path = '<keyfile>'
remote_directory_path = '/home/uwe/downloadtest'
local_directory_path = 'E:/downloadtest'
 
# Establish SSH connection
try:
    # Create a new SSH client
    ssh_client = paramiko.SSHClient()
 
    # Automatically add the server's host key
    ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 
    # Load the private key for authentication
    private_key = paramiko.RSAKey.from_private_key_file(private_key_path)
 
    # Connect to the server
    ssh_client.connect(hostname=host, port=port, username=username, pkey=private_key)
 
    # Open an SFTP session on the SSH connection
    sftp = ssh_client.open_sftp()
 
    # Change to the remote directory
    sftp.chdir(remote_directory_path)
 
    # List all files in the remote directory
    files = sftp.listdir()
 
    # Download each CSV file in the remote directory
 
    for file_name in files:
        # os path join uses system slashes, must make sure they are right
        remote_file_path = os.path.join(remote_directory_path, file_name).replace("\\","/")
        local_file_path = os.path.join(local_directory_path, file_name).replace("\\","/")
        print(remote_file_path, local_file_path)
 
        # Check if the file is a CSV file
        if file_name.lower().endswith('.txt'):
            sftp.get(remote_file_path, local_file_path)
            print(f"File '{file_name}' downloaded successfully to '{local_directory_path}'")
 
    # Close the SFTP session and SSH connection
    sftp.close()
    ssh_client.close()
 
except paramiko.AuthenticationException:
    print("Authentication failed. Please check your credentials or SSH key path.")
except paramiko.SSHException as e:
    print(f"SSH connection failed: {e}")
except FileNotFoundError:
    print("File not found. Please provide the correct file paths.")
except Exception as e:
    print(f"An error occurred: {e}")

E-Mails senden aus Python heraus

Aktuell benötige ich Funktionalitäten in Python, um E-Mails automatisch versenden zu lassen. Über Chat-GPT habe ich mir passenden Code basteln lassen, der recht gut funktioniert.

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
 
def send_email():
    # Email content
    sender_email = 'YOUR_EMAIL_ADDRESS'
    password = 'YOUR_PASSWORD'
    recipient_email = 'RECIPIENT_EMAIL_ADDRESS'
    subject = 'SUBJECT'
    body = 'EMAIL_BODY'
 
    # Create a multipart message and set headers
    message = MIMEMultipart()
    message['From'] = sender_email
    message['To'] = recipient_email
    message['Subject'] = subject
 
    # Add body to email
    message.attach(MIMEText(body, 'plain'))
 
    try:
        # Connect to SMTP server (for Gmail use 'smtp.gmail.com', for others, refer to your provider's settings)
        smtp_server = smtplib.SMTP('smtp.yourprovider.com', 587)
        smtp_server.starttls()  # Enable encryption for security
        smtp_server.login(sender_email, password)
 
        # Send email
        smtp_server.sendmail(sender_email, recipient_email, message.as_string())
        print("Email sent successfully!")
 
        # Close the connection
        smtp_server.quit()
    except Exception as e:
        print(f"Error: {e}")
        print("Email was not sent.")
 
# Call the function to send the email
send_email()

Falls der SMTP-Server keine Authentifizierung braucht, dann reicht auch das folgende

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
 
def send_email():
    # Email content
    sender_email = 'YOUR_EMAIL_ADDRESS'
    recipient_email = 'RECIPIENT_EMAIL_ADDRESS'
    subject = 'SUBJECT'
    body = 'EMAIL_BODY'
 
    # Create a multipart message and set headers
    message = MIMEMultipart()
    message['From'] = sender_email
    message['To'] = recipient_email
    message['Subject'] = subject
 
    # Add body to email
    message.attach(MIMEText(body, 'plain'))
 
    try:
        # Connect to SMTP server
        smtp_server = smtplib.SMTP('smtp.yourprovider.com')  # Replace with your SMTP server address
        smtp_server.sendmail(sender_email, recipient_email, message.as_string())
        print("Email sent successfully!")
 
        # Close the connection
        smtp_server.quit()
    except Exception as e:
        print(f"Error: {e}")
        print("Email was not sent.")
 
# Call the function to send the email
send_email()

TexLive Mirror setzen

So setzt man den TeX Live mirror auf einen der zentralen Server:

tlmgr option repository http://mirror.ctan.org/systems/texlive/tlnet

Windows Daten mit Linux Borg sichern

Ich nutze auf meiner Windows-Maschine das Windows Subsystem for Linux (WSL) und habe mal ausprobiert, wie ich Windows Daten mit WSL-Hilfe auf ein NAS sichern kann.

Nach der Installation von borg-backup und den cifs Utilities kann ich das NAS unter Linux mounten:

sudo mount -t cifs -o vers=3.0,user=uwe,password=xxxxxxxxx //192.168.0.40/Datengrab /mnt/borg/

Dann kann ich unter WSL z.B. in den User-Desktop von Windows wechseln und das Backup anschupsen:

uwe@DESKTOP-RH75H57:/mnt/c/Users/Uwe/Desktop$ pwd
/mnt/c/Users/Uwe/Desktop

sudo borg create -v /mnt/borg/borgtarget/::'{now:%Y-%m-%d_%H-%M}' .