Skip to content

Instantly share code, notes, and snippets.

View mshafiee's full-sized avatar

Mohammad Shafiee mshafiee

View GitHub Profile
import os
import sys
def collect_go_files_content(directory):
content = ""
for root, _, files in os.walk(directory):
for file in files:
if file.endswith(".go"):
file_path = os.path.join(root, file)
with open(file_path, 'r', encoding='utf-8') as f:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Magic Square Generator</title>
<style>
table {
border-collapse: collapse;
margin: 20px 0;
@mshafiee
mshafiee / create-certificate-stack.sh
Created February 13, 2023 20:59
This is a bash script that creates a CloudFormation stack for a public certificate with DNS validation, based on input parameters provided as command line flags.
#!/bin/bash
# This is a bash script that creates a CloudFormation stack for a public certificate with DNS validation,
# based on input parameters provided as command line flags.
# The script starts by defining the print_help function that displays the usage information for the script,
# along with the available command line flags.
# Next, the script uses the getopts command to parse the command line flags and store their values in variables
# (stack_name, csv_file, and domain_name). If any of the required flags are missing, the script will display
# an error message and exit.
# The script then reads the contents of the CSV file into a bash array (subject_alternative_names), which
# will be used to specify the SubjectAlternativeNames for the certificate.
@mshafiee
mshafiee / resetBranch.sh
Created February 4, 2023 15:14
This bash script will check if a branch named BRANCH_NAME exists in the Git repository. If it exists, it will checkout to that branch and reset the branch to the previous commit, discarding all previous commits except the last one. It will then rename the latest commit to COMMIT_NAME and push the rewritten branch to the remote repository. Finall…
#!/bin/bash
# This bash script will check if a branch named BRANCH_NAME exists in the Git repository.
# If it exists, it will checkout to that branch and reset the branch to the previous commit,
# discarding all previous commits except the last one. It will then rename the latest
# commit to COMMIT_NAME and push the rewritten branch to the remote repository.
# Finally, it will display a message indicating that the branch has been rewritten
# and the last commit has been renamed.
if [ $# -ne 2 ]; then
# This script is a command line tool that reads German conjugations of the verb "sein" (to be)
# in the present tense using Festival TTS engine on Linux. The script declares an array of strings,
# each string containing a conjugation of the verb "sein" for a different personal pronoun.
# Then, it uses an infinite while loop to iterate over the array, reading each conjugation 60 times
# with a sleep of 1 second in between each reading. The script uses the echo "$i" | festival --tts -voice de
# command to read the current string in the array, where -voice de option is added to the festival --tts command,
# which causes the TTS engine to use a German voice. The script is useful for language learners who want to
# practice the conjugations of the verb "sein" in the present tense on Linux.
# How to install festival:
# sudo apt-get install festival
@mshafiee
mshafiee / sysctl.conf
Last active June 27, 2022 09:50
Customized sysctl for high network loads
###################################################################
# Protected links
#
# Protects against creating or following links under certain conditions
# Debian kernels have both set to 1 (restricted)
# See https://www.kernel.org/doc/Documentation/sysctl/fs.txt
#fs.protected_hardlinks=0
#fs.protected_symlinks=0
net.ipv4.ip_forward=1
#net.ipv4.ip_local_reserved_ports=30000-32767
@mshafiee
mshafiee / haproxy.cfg
Last active June 13, 2022 10:34
Sample of HAProxy active-active peers rate limiting by counting a custom header
global
localpeer haproxy-1
defaults
timeout connect 5s
timeout client 1m
timeout server 1m
peers haproxy-peers
@mshafiee
mshafiee / bash.sh
Created May 12, 2022 11:57
bash cheatsheets
#!/bin/bash
##############################################################################
# SHORTCUTS and HISTORY
##############################################################################
CTRL+A # move to beginning of line
CTRL+B # moves backward one character
CTRL+C # halts the current command
CTRL+D # deletes one character backward or logs out of current session, similar to exit
CTRL+E # moves to end of line
@mshafiee
mshafiee / clean.sh
Created May 12, 2022 11:39
Free up disk space on Ubuntu - clean log, cache, archive packages/apt archives, orphaned packages, old kernel and remove the trash
#!/bin/sh
#Check the Drive Space Used by Cached Files
du -sh /var/cache/apt/archives
#Clean all the log file
#for logs in `find /var/log -type f`; do > $logs; done
logs=`find /var/log -type f`
for i in $logs
@mshafiee
mshafiee / install-latest-docker.sh
Created May 12, 2022 11:26
Install Latest Docker and Docker-compose on Ubuntu
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
# Install kernel extra's to enable docker aufs support
# sudo apt-get -y install linux-image-extra-$(uname -r)
# Add Docker PPA and install latest version
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
# sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"