Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
isingasimplesong committed Oct 27, 2024
0 parents commit a10fba3
Show file tree
Hide file tree
Showing 29 changed files with 798 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.env
data/
node_modules/
venv/
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
*.log
logs/
npm-debug.log*
coverage/
.cache/
*.pem
*.key
vendor/
storage/
bootstrap/cache/
composer.lock
docker-compose.override.yml
docker-compose.yml
.dockerignore
*.sqlite3
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
GLWT(Good Luck With That) Public License
Copyright (c) Everyone, except Author

Everyone is permitted to copy, distribute, modify, merge, sell, publish,
sublicense or whatever they want with this software but at their OWN RISK.

Preamble

The author has absolutely no clue what the code in this project does.
It might just work or not, there is no third option.


GOOD LUCK WITH THAT PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION

0. You just DO WHATEVER YOU WANT TO as long as you NEVER LEAVE A
TRACE TO TRACK THE AUTHOR of the original product to blame for or hold
responsible.

IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

Good luck and Godspeed.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# duct-tape
2 changes: 2 additions & 0 deletions btrfs-backup-stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
sudo btrfs filesystem du -s /run/media/mathieu/ext_ssd/backups
126 changes: 126 additions & 0 deletions btrfs-backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/usr/bin/env bash

# Config
SOURCE="/home"
LOCAL_DEST="/snapshots"
DEST="/run/media/mathieu/ext_ssd/backups"
KEEP_LOCAL=10 # Nombre de snapshots locaux à conserver
KEEP_DISTANT=31 # Nombre de snapshots distant à conserver
# KEEP_DAILY=7 # Rétention des snapshots distants
# KEEP_WEEKLY=4
# KEEP_MONTHLY=6
DATE=$(date +"%Y-%m-%d_%H-%M-%S")
SNAPSHOT_NAME="$DATE"
LAST_RUN_FILE="$DEST/.last_run"
LAST_SNAPSHOT_FILE="$DEST/.last_snapshot"

get_age_days() {
local file=$1
local file_time=$(date -r "$file" +%s)
local current_time=$(date +%s)
echo $(((current_time - file_time) / 86400))
}

if ! mountpoint -q "$DEST/.."; then
echo "Erreur: Le disque externe n'est pas monté sur $DEST"
exit 1
fi

# Vérifier la dernière exécution
if [ -f "$LAST_RUN_FILE" ]; then
last_run=$(cat "$LAST_RUN_FILE")
days_since_last_run=$((($(date +%s) - $(date -d "$last_run" +%s)) / 86400))
if [ $days_since_last_run -gt 7 ]; then
echo "Attention: $days_since_last_run jours se sont écoulés depuis la dernière sauvegarde."
fi
else
echo "Première exécution détectée."
fi

# Créer un nouveau snapshot en lecture seule de /home
if sudo btrfs subvolume snapshot -r "$SOURCE" "$LOCAL_DEST/$SNAPSHOT_NAME"; then
echo "Snapshot local créé avec succès: $LOCAL_DEST/$SNAPSHOT_NAME"
else
echo "Erreur lors de la création du snapshot local"
exit 1
fi

# Envoyer le snapshot vers la destination
if [ -f "$LAST_SNAPSHOT_FILE" ]; then
last_snapshot=$(cat "$LAST_SNAPSHOT_FILE")
if [ -d "$LOCAL_DEST/$last_snapshot" ]; then
echo "Envoi d'un snapshot incrémentiel..."
if sudo btrfs send -p "$LOCAL_DEST/$last_snapshot" "$LOCAL_DEST/$SNAPSHOT_NAME" | sudo btrfs receive "$DEST"; then
echo "Snapshot incrémental envoyé avec succès vers $DEST/$SNAPSHOT_NAME"
else
echo "Erreur lors de l'envoi du snapshot incrémentiel. Tentative d'envoi complet..."
if sudo btrfs send "$LOCAL_DEST/$SNAPSHOT_NAME" | sudo btrfs receive "$DEST"; then
echo "Snapshot complet envoyé avec succès vers $DEST/$SNAPSHOT_NAME"
else
echo "Erreur lors de l'envoi du snapshot complet"
sudo btrfs subvolume delete "$LOCAL_DEST/$SNAPSHOT_NAME"
exit 1
fi
fi
else
echo "Le snapshot précédent n'existe pas localement. Envoi d'un snapshot complet..."
if sudo btrfs send "$LOCAL_DEST/$SNAPSHOT_NAME" | sudo btrfs.receive "$DEST"; then
echo "Snapshot complet envoyé avec succès vers $DEST/$SNAPSHOT_NAME"
else
echo "Erreur lors de l'envoi du snapshot complet"
sudo btrfs subvolume delete "$LOCAL_DEST/$SNAPSHOT_NAME"
exit 1
fi
fi
else
echo "Aucun snapshot précédent trouvé. Envoi d'un snapshot complet..."
if sudo btrfs send "$LOCAL_DEST/$SNAPSHOT_NAME" | sudo btrfs receive "$DEST"; then
echo "Snapshot complet envoyé avec succès vers $DEST/$SNAPSHOT_NAME"
else
echo "Erreur lors de l'envoi du snapshot complet"
sudo btrfs subvolume delete "$LOCAL_DEST/$SNAPSHOT_NAME"
exit 1
fi
fi

# Mettre à jour les fichiers de suivi
date +"%Y-%m-%d %H:%M:%S" >"$LAST_RUN_FILE"
echo "$SNAPSHOT_NAME" >"$LAST_SNAPSHOT_FILE"

# Fonction de nettoyage des snapshots locaux
cleanup_local_snapshots() {
echo "Nettoyage des snapshots locaux..."
local snapshots=($(ls -1d "$LOCAL_DEST"/20*_*-*-* | sort -r))
local count=0
for snapshot in "${snapshots[@]}"; do
if [ $count -ge $KEEP_LOCAL ]; then
echo "Suppression du snapshot local: $snapshot"
sudo btrfs subvolume delete "$snapshot"
fi
count=$((count + 1))
done
}

# Fonction de nettoyage des snapshots sur la destination
cleanup_remote_snapshots() {
echo "Nettoyage des snapshots distants..."
cd "$DEST" || exit

local snapshots=($(ls -1d 20*_*-*-* | sort -r))

for snapshot in "${snapshots[@]}"; do
local age=$(get_age_days "$snapshot")

# Supprimer tous les snapshots plus vieux que 31 jours
if [ $age -gt $KEEP_DISTANT ]; then
echo "Suppression du snapshot distant: $snapshot"
sudo btrfs subvolume delete "$snapshot"
fi
done
}

# Exécuter le nettoyage
cleanup_local_snapshots
cleanup_remote_snapshots

echo "Sauvegarde et nettoyage terminés"
60 changes: 60 additions & 0 deletions btrfs-move-fast.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash

# Vérifier les arguments
if [ $# -lt 2 ]; then
echo "Usage: $0 <source_pattern> <destination_directory>"
exit 1
fi

# Le dernier argument est toujours la destination
DEST_DIR="${@: -1}"
# Tous les arguments sauf le dernier sont considérés comme des motifs source
SOURCE_PATTERNS=("${@:1:$#-1}")

# Créer le répertoire de destination s'il n'existe pas
mkdir -p "$DEST_DIR"

# Fonction pour déplacer rapidement un snapshot
move_snapshot_fast() {
local src=$1
local dest=$2
local snapshot_name=$(basename "$src")

echo "Déplacement rapide du snapshot $src vers $dest/$snapshot_name"

# Créer un nouveau snapshot read-write à la destination
sudo btrfs subvolume snapshot "$src" "$dest/$snapshot_name"

if [ $? -eq 0 ]; then
echo "Nouveau snapshot créé avec succès."

# Supprimer l'ancien snapshot
echo "Suppression de l'ancien snapshot..."
sudo btrfs subvolume delete "$src"

if [ $? -eq 0 ]; then
echo "Ancien snapshot supprimé avec succès."
else
echo "Erreur lors de la suppression de l'ancien snapshot. Veuillez le supprimer manuellement."
fi
else
echo "Erreur lors de la création du nouveau snapshot."
fi
}

# Parcourir tous les motifs source
for pattern in "${SOURCE_PATTERNS[@]}"; do
# Utiliser la commande find pour gérer les jokers
while IFS= read -r -d $'\0' snapshot; do
if [ -d "$snapshot" ]; then
# Vérifier si c'est un sous-volume BTRFS
if sudo btrfs subvolume show "$snapshot" &> /dev/null; then
move_snapshot_fast "$snapshot" "$DEST_DIR"
else
echo "Ignoré: $snapshot n'est pas un sous-volume BTRFS."
fi
fi
done < <(find "$(dirname "$pattern")" -maxdepth 1 -mindepth 1 -type d -name "$(basename "$pattern")" -print0)
done

echo "Opération terminée."
46 changes: 46 additions & 0 deletions github-init-repo-priv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

project_name=$(basename "$(pwd)")
gitignore_source="$HOME/dotfiles/misc/gitignore"
license="$HOME/dotfiles/misc/license"

# Initialisation du dépôt git local
git init || {
echo "Erreur lors de l'initialisation du dépôt git" >&2
exit 1
}

# Configuration des fichiers de base
if [[ -f "$gitignore_source" ]]; then
cat "$gitignore_source" >.gitignore
else
echo "Erreur : le fichier .gitignore source est introuvable." >&2
exit 1
fi

touch .env && echo "MY_ENV=$project_name" >>.env

echo "# $project_name" >README.md

if [[ -f "$license" ]]; then
cat "$license" >LICENSE
else
echo "Erreur : le fichier 'LICENSE' source est introuvable." >&2
exit 1
fi

# Création du dépôt GitHub
if ! command -v gh &>/dev/null; then
echo "Erreur : GitHub CLI (gh) n'est pas installé." >&2
exit 1
fi

gh repo create "$project_name" --private --source=. --remote=origin || {
echo "Erreur lors de la création du dépôt GitHub." >&2
exit 1
}

git add . && git commit -m "initial commit" && git push --set-upstream origin main

echo "Le dépôt GitHub '$project_name' a été créé avec succès à l'adresse \
https://github.com/isingasimplesong/$project_name"
46 changes: 46 additions & 0 deletions github-init-repo-pub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

project_name=$(basename "$(pwd)")
gitignore_source="$HOME/dotfiles/misc/gitignore"
license="$HOME/dotfiles/misc/license"

# Initialisation du dépôt git local
git init || {
echo "Erreur lors de l'initialisation du dépôt git" >&2
exit 1
}

# Configuration des fichiers de base
if [[ -f "$gitignore_source" ]]; then
cat "$gitignore_source" >.gitignore
else
echo "Erreur : le fichier .gitignore source est introuvable." >&2
exit 1
fi

touch .env && echo "MY_ENV=$project_name" >>.env

echo "# $project_name" >README.md

if [[ -f "$license" ]]; then
cat "$license" >LICENSE
else
echo "Erreur : le fichier 'LICENSE' source est introuvable." >&2
exit 1
fi

# Création du dépôt GitHub
if ! command -v gh &>/dev/null; then
echo "Erreur : GitHub CLI (gh) n'est pas installé." >&2
exit 1
fi

gh repo create "$project_name" --public --source=. --remote=origin || {
echo "Erreur lors de la création du dépôt GitHub." >&2
exit 1
}

git add . && git commit -m "initial commit" && git push --set-upstream origin main

echo "Le dépôt GitHub '$project_name' a été créé avec succès à l'adresse \
https://github.com/isingasimplesong/$project_name"
3 changes: 3 additions & 0 deletions hypr-toggle-layouts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
TOGGLE_PATH="/home/mathieu/.config/hypr/modules/envvar.conf"
sed -i 's/master/passeplat/;s/dwindle/master/;s/passeplat/dwindle/' $TOGGLE_PATH
40 changes: 40 additions & 0 deletions kinetic_energy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3

import argparse

# get kinetic energy for any object you know the speed and weight
# To use, just run python3 kinetic_energy.py --speed 30 --weight 1500
# speed is in Km/h, weight in Kg


def calculate_energy(weight, velocity):
# Convert weight from kg to Newtons (1 kg = 9.81 N)
mass = weight * 9.81

# Calculate kinetic energy (in Joules)
kinetic_energy = 0.5 * mass * (velocity**2)

return kinetic_energy


def convert_kmh_to_ms(kmh):
return kmh * (1000 / 3600)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Calculate kinetic energy of a moving vehicle"
)
parser.add_argument(
"-s", type=float, required=True, help="Velocity in kilometers per hour"
)
parser.add_argument("-w", type=float, required=True, help="Weight in kilograms")
args = parser.parse_args()

velocity_km = args.s
velocity_ms = convert_kmh_to_ms(velocity_km)
weight = args.w

energy = calculate_energy(weight, velocity_ms)

print(f"Kinetic Energy: {energy:.2f} J")
Loading

0 comments on commit a10fba3

Please sign in to comment.