Skip to content

Instantly share code, notes, and snippets.

View MohamedElashri's full-sized avatar

Mohamed Elashri MohamedElashri

View GitHub Profile
@MohamedElashri
MohamedElashri / Persistent_SSH_Tunnel_with_systemd.md
Created September 28, 2024 22:14
Persistent SSH Tunnel with systemd

This guide explains how to create a persistent SSH reverse tunnel using systemd without relying on tools like autossh. This approach automatically restarts the SSH tunnel if it fails or gets stuck due to disconnections.

Why Use systemd for SSH Tunnels?

Using systemd provides several benefits over standalone SSH or autossh:

  • Automatic Restart: If the SSH connection fails, systemd restarts it automatically.
  • Keep Alive: Prevents stale SSH connections by using SSH's ServerAliveInterval and ServerAliveCountMax.
  • Clean and Simple: Avoids external tools and manages the service with native system management.

Steps to Set Up

@MohamedElashri
MohamedElashri / create_and_push_repo.md
Last active September 29, 2024 20:37
Automate GitHub Repo Creation and Push with a Bash Function

This bash function automates the process of initializing a Git repository, creating a GitHub repository, and pushing your local files—all from the command line using the GitHub CLI (gh). It also disables wikis and issues for the created repo.

Add the following function to your .bashrc or .zshrc file:

create_and_push_repo() {
    if ! command -v gh &> /dev/null
    then
        echo "Error: GitHub CLI (gh) is not installed. Please install it first."
@MohamedElashri
MohamedElashri / input_source_switch_comsic_desktop.md
Created September 25, 2024 22:12
Enable Input Source Switching in Cosmic Desktop by System76

Description

At present, Cosmic Desktop by System76 lacks a GUI to configure input source switching. However, the system uses the XKB (X Keyboard Extension) system, which allows manual configuration of input switching by modifying the relevant XKB settings.

The grp:win_space_toggle option defines a key combination (Super+Space or Win+Space) for switching between input sources. The provided workaround manually sets this option by editing the xkb_config file.

This approach gives users the flexibility to switch between keyboard layouts without waiting for native support in Cosmic Desktop.

Notes

@MohamedElashri
MohamedElashri / nvidia_gpu_information.md
Created September 19, 2024 10:47
Information about some NVIDIA GPUs
Memory Type NVIDIA GeForce RTX 3090 NVIDIA RTX A5000 NVIDIA GeForce RTX 2080 Ti
Global Memory 24 GB GDDR6X 24 GB GDDR6 11 GB GDDR6
Memory Interface 384-bit 384-bit 352-bit
Memory Bandwidth 936 GB/s 768 GB/s 616 GB/s
L2 Cache 6 MB Not specified 5.5 MB
Shared Memory 164 KB per SM 164 KB per SM 64 KB per SM
Constant Memory 64 KB 64 KB 64 KB
Texture Memory Part of global memory Part of global memory Part of global memory
Local Memory Part of global memory Part of global memory Part of global memory
@MohamedElashri
MohamedElashri / LLM_shell_prompt.md
Created September 15, 2024 01:25
LLM shell script generation prompt helper

When generating the shell script, please ensure it adheres to the following best practices to provide a robust and user-friendly experience on Unix/BSD systems:

  1. Comprehensive Error Handling and Input Validation:

    • Use set -euo pipefail at the beginning of the script to catch errors, unset variables, and failed pipes.
    • Validate all input arguments and provide meaningful error messages to guide the user.
  2. Clear and Colorful Output:

    • Implement clear, user-friendly messages.
    • Use color coding (e.g., bold yellow for warnings) to enhance readability and draw attention to important information.
@MohamedElashri
MohamedElashri / README.md
Last active September 14, 2024 07:15
Interactive bash script that tells you if you need to write bash or python script for a particular case

Criteria for using Bash scripts instead of Python:

  1. The problem is easy to solve
  2. I don't need to do any math beyond simple addition or multiplication
  3. I don't need concurrency
  4. I don't need data structures
  5. I don't need functional programming code style
  6. I don't need to work on Windows
  7. I don't care about performance
@MohamedElashri
MohamedElashri / crowdsec_clean.sh
Last active August 23, 2024 19:22
Clean the system from any crowdsec precence.
#!/bin/bash
# Color definitions
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
@MohamedElashri
MohamedElashri / config.yml
Created August 19, 2024 11:19
yml config file for glance dashboard with dracula theme
pages:
- name: Home
columns:
- size: small
widgets:
- type: calendar
- type: rss
limit: 10
collapse-after: 3
@MohamedElashri
MohamedElashri / homarr_reset_proxmox.sh
Created August 19, 2024 10:52
How to Reset a User's Password in Homarr on Proxmox LXC
#!/usr/bin/env bash
# Access the LXC container
pct enter <container_id>
# Navigate to the Homarr installation directory
cd /opt/homarr
# Access the SQLite database
sqlite3 /opt/homarr/database
@MohamedElashri
MohamedElashri / positron_update.sh
Created July 18, 2024 13:42
MacOS positron update script. Script checks beta version from github releases and compare with current installed one
#!/usr/bin/env bash
set -e
# Function to log errors
log_error() {
echo "ERROR: $1" >&2
}
# Function to log info