Skip to content

Instantly share code, notes, and snippets.

Docker default address pooling

Default settings

{
 "default-address-pools" : [
 {
 "base" : "172.17.0.0/12",
 "size" : 16
@mahrous-amer
mahrous-amer / postgres-dev.sh
Created October 29, 2024 06:29
A Bash utility script for managing a local PostgreSQL Docker container with ease.
#!/bin/bash
# Environment Variables
CONTAINER_NAME="dev-postgres"
POSTGRES_IMAGE="postgres"
POSTGRES_PASSWORD="dev_password"
DATA_DIR="${HOME}/dev_postgres/"
# Display Help
Help()
#!/bin/bash
# Define variables
REGION="eu-west-1"
PROFILE="default"
OUTPUT_FORMAT="json"
PERIOD_IN_SECONDS=3600
STATISTIC="Maximum"
END_TIME=$(date -u "+%Y-%m-%dT%H:%M:%SZ")
START_TIME=$(date -u -v-7d "+%Y-%m-%dT%H:%M:%SZ")
@mahrous-amer
mahrous-amer / aws_scrape.sh
Created January 7, 2025 04:29
Gather detailed information about various AWS resources in a specific region, using a specified AWS CLI profile.
#!/bin/bash
# Define variables
REGION="eu-west-1"
PROFILE="default"
OUTPUT_FORMAT="json"
# Helper function to fetch and print results
function fetch_and_print {
local description=$1
@mahrous-amer
mahrous-amer / aws_ebs_comliance.sh
Created January 7, 2025 04:31
This script calculates total IOPS for the volumes, compares it with the instance's maximum allowed IOPS, and provides a compliance status based on EBS optimization support.
#!/bin/bash
PROFILE=""
INSTANCE_ID=""
echo "Instance ID: $INSTANCE_ID"
echo "Fetching instance details..."
instance_details=$(aws --profile $PROFILE ec2 describe-instances --instance-ids "$INSTANCE_ID" --query 'Reservations[0].Instances[0]' --output json)
echo "Instance details fetched successfully."
@mahrous-amer
mahrous-amer / git_cheat_sheet.md
Created January 13, 2025 03:59
This cheat sheet serves as a quick reference guide for developers of all levels. It covers essential commands for version control, including file comparison (diff and patch), repository management, committing, branching, remote operations, and security features like GPG signing. It also includes tips for viewing logs, handling file changes acros…

Git and GitHub

Diff and Patch

diff

diff is used to find differences between two files. For easier usage, combine it with -u:

diff -u file1 file2
@mahrous-amer
mahrous-amer / alphavantage_daily.sh
Created July 3, 2025 06:20
Bash script to fetch symbol data from Alpha Vantage API, save as JSON, and generate a daily close price graph using gnuplot. Requires curl, jq, gnuplot, and an Alphavantage API key.
#!/bin/bash
# Author: Mahrous Amer
# Date: September 23, 2024
set -euo pipefail
# Constants
BASE_URL='https://www.alphavantage.co'
CONFIG_FILE='config.conf'
@mahrous-amer
mahrous-amer / GoDockerfile
Created July 3, 2025 06:35
Dynamic Dockerfile for any local Go project
ARG GO_VERSION=1.20
ARG BASE_IMAGE=golang:${GO_VERSION}-bullseye
ARG APP_NAME=app
ARG APP_PORT=3000
FROM ${BASE_IMAGE} AS build
WORKDIR /app
COPY go.mod go.sum ./
@mahrous-amer
mahrous-amer / tcp_server_client.pl
Created July 3, 2025 06:38
Perl script for TCP server and client communication. Supports server and client modes via command-line options. Server echoes client input, supports multiple connections, and includes SO_REUSEADDR. Client reads server responses. Features include configurable host/port, non-blocking I/O, and detailed connection logging. Usage: `--mode=server|clie…
#!/usr/bin/perl -w
use strict;
use Socket;
use Getopt::Long;
use IO::Handle;
# Configuration
my $default_port = 7890;
my $default_host = 'localhost';
my $backlog = 5;