Skip to content

Instantly share code, notes, and snippets.

@Tharwat96
Tharwat96 / git.sh
Created November 23, 2020 03:14
git commands
# delete last commit without losing changes
git reset HEAD^
@Tharwat96
Tharwat96 / aws_commands.sh
Last active September 6, 2020 10:04
aws cli useful commands
# describe ec2 instance
aws ec2 --region us-east-1 describe-instances --instance-ids i-xxxxxxxxxxx
# associate iam instance profile to running instance
aws ec2 associate-iam-instance-profile --instance-id i-xxxxxxxxxxx --iam-instance-profile Name=xxxxxxxxx
@Tharwat96
Tharwat96 / create_users.groovy
Last active November 9, 2020 09:50
Jenkins Useful Groovy Scripts
import hudson.model.*
import hudson.security.*
import hudson.tasks.Mailer
def userId = args[0]
def password = args[1]
def email = args[2]
def instance = jenkins.model.Jenkins.instance
def existingUser = instance.securityRealm.allUsers.find {it.id == userId}
@Tharwat96
Tharwat96 / git useful commands.sh
Last active September 3, 2020 10:27
git scripts
# sort all branches in repository by date updated
git for-each-ref --sort=committerdate refs/heads/ --format="%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))" --no-merged=origin/HEAD refs/remotes/origin
@Tharwat96
Tharwat96 / basics.yaml
Created July 28, 2020 22:27
YAML Basics and Kubernetes Manifests
# This is a comment, we will use comments to explain.
# There are three types of data in YAML:
# - key value pair, lists/arrays, dictionaries
# key value pair:
Fruit: Apple
Vegetable: Carrot
Liquid: Water
Meat: Chicken
@Tharwat96
Tharwat96 / docker.md
Last active July 2, 2020 00:41
Docker Cheat Sheet and Tricks

Docker Cheat Sheet

Copy a file from host to container:

docker cp file.xz container_name:/tmp/file.xz

List all containers with their volumes

docker ps -a --format '{{ .ID }}' | xargs -I {} docker inspect -f '{{ .Name }}{{ printf "\n" }}{{ range .Mounts }}{{ printf "\n\t" }}{{ .Type }} {{ if eq .Type "bind" }}{{ .Source }}{{ end }}{{ .Name }} => {{ .Destination }}{{ end }}{{ printf "\n" }}' {}

@Tharwat96
Tharwat96 / any.php
Created June 26, 2020 21:25
Eloquent ORM Without Laravel
// any file to use the Eloquent driver
<?php
require "../vendor/autoload.php";
require "../config/database.php";
use Illuminate\Database\Capsule\Manager as Capsule;
$dbclass = new Database();
$capsule = new Capsule();
$capsule->addConnection($dbclass->EloquentConnection());

List the active account name

gcloud auth list

Set the compute zone

gcloud config set compute/zone us-central1-a

Creates a cluster called bootcamp with 5 nodes (including the master)

gcloud container clusters create bootcamp --num-nodes 5 --scopes "https://www.googleapis.com/auth/projecthosting,storage-rw"

@Tharwat96
Tharwat96 / commands.sh
Last active November 2, 2023 10:35
Kubernetes Cheat Sheet
# delete all pods that are evicted
kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod
# delete all pods that are erroring and sleep a bit to avoid rate limit
# you can add head or tail to work in batches
kubectl get pods --all-namespaces | grep 'Evicted\|Error\|ContainerStatusUnknown' | awk '{print $2 " --namespace=" $1}' | xargs -I % sh -c '{ kubectl delete pod %; sleep 0.1; }'
# print all failing pods with their describe reason of failiure
@Tharwat96
Tharwat96 / gitea.service
Last active May 12, 2020 10:33
scripts to install services
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
#After=mysqld.service
#After=postgresql.service
#After=memcached.service
#After=redis.service
[Service]