Skip to content

Instantly share code, notes, and snippets.

View eugen-hoppe's full-sized avatar
🏠
Working from home

Eugen Hoppe eugen-hoppe

🏠
Working from home
View GitHub Profile
@eugen-hoppe
eugen-hoppe / case.py
Last active January 14, 2024 10:34
Snippet (Python) to convert camelcase-string to snake-string and vise versa. #python
import re
class To:
@staticmethod
def camel(snake: str, upper_first: bool = False) -> str:
if snake.startswith("_"):
snake = snake[1:]
parts = snake.lower().split("_")
if upper_first:
@eugen-hoppe
eugen-hoppe / ssh_connection_cs.md
Last active January 14, 2024 10:41
Cheatsheet for SSH connection from MacOS. #ssh #macos

How to use SSH? (MacOS)

1. How to connect via SSH?

1.1 How is the key named?

your_key
ssh -i ~/.ssh/your_key root@ip-address
id_rsa
@eugen-hoppe
eugen-hoppe / create_linux_user_cs.md
Last active June 9, 2026 22:12
Cheat sheet to create a new user (Linux) with SSH public key. #linux #ssh

How to create a new user (Linux) with SSH Public Key?

To create new users and add their public keys on an Ubuntu server, follow these steps:

1. Create a New User

First, open a terminal and enter the following command to create a new user. Replace newuser with your desired username.

sudo adduser newuser
@eugen-hoppe
eugen-hoppe / traefik_basic_auth_pw_gen.md
Created January 29, 2024 17:49
Generate Basic Auth Checksum for Traefik Configuration File

echo $(htpasswd -nB USERNAME) | sed -e s/\$/\$\$/g

from typing import Callable, Tuple, Type, Optional
from functools import wraps
def try_except(
errors: Tuple[Type[Exception], ...] = (Exception,),
raise_: Optional[Type[Exception]] = None,
txt_: str = ""
) -> Callable:
"""A decorator that wraps a function to handle exceptions"""
@eugen-hoppe
eugen-hoppe / ypcat.py
Created August 22, 2024 17:27
2024-08-22
@dataclass
class Cat:
ignore_steps: bool = False
step: int = 0
labels: pd.DataFrame | None = None
categories: pd.DataFrame | None = None
sorted_labels: pd.DataFrame | None = None
merged_final: pd.DataFrame | None = None
category_prefixes: list[str] = field(
default_factory=lambda: ['c1', 'c2']
@eugen-hoppe
eugen-hoppe / version_of_each_requirement.py
Created August 28, 2024 12:18
Create for each record in requirements.txt a record with a version depending on environment.
import pkg_resources
import os
INPUT_FILE = "requirements.txt"
OUTPUT_FILE = "requirements_.txt"
# OUTPUT_FILE = "requirements.txt"
def get_installed_version(package_name):
@eugen-hoppe
eugen-hoppe / pandas_create_sample_csv.py
Created September 21, 2024 08:13
Create sample from CSV-file and save as CSV.
def create_sample_csv(path: str, name: str, rows: int, shuffle: int = 0) -> None:
path_file_csv = f'{path}/' + name.removesuffix('.csv') + '.csv'
input_df = pd.read_csv(path_file_csv)
if bool(shuffle):
input_df.sample(frac=1, random_state=shuffle)
output_df = input_df.head(rows)
output_df.to_csv(path_file_csv.replace('.csv', '_sample.csv'), index=False)
@eugen-hoppe
eugen-hoppe / colab_zip_from_drive.py
Last active February 3, 2025 14:54
Copies a ZIP file from Google Drive to the local VM in Google Colab and unzips it.
import shutil
import zipfile
import os
from google.colab import drive
def copy_and_unzip_from_drive(drive_path, local_path, drive_mount = "/content/drive"):
"""docs: https://gist.github.com/eugen-hoppe/93ece48e0b224b853698249502aa9ba9"""
drive.mount(drive_mount)
@eugen-hoppe
eugen-hoppe / ds_plot.py
Last active February 20, 2025 09:13
Histogram and Boxplot
from dataclasses import dataclass
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.axes as type_ax
@dataclass
class Plot:
"""src: https://gist.github.com/eugen-hoppe/400e47930f733229eaf773f070c81e62"""
df: pd.DataFrame # . Cache pd.Dataframe for plot