Skip to content

Instantly share code, notes, and snippets.

@Tharwat96
Tharwat96 / editing text
Last active May 29, 2021 23:31
Linux commands that I keep forgetting
sed:
to substitute something with something else:
sed "s/something/something_else/g" file.sh
the g in the right is for changing all occurrences in all lines, if it was not written, only the first occurrence of each line is replaced
sed example to substitute new lines with spaces:
sed ':a;N;$!ba;s/\n/ /g' file
# write/overwrite file
f = open("text.txt", "w")
f.write("bla bla")
f.close()
# search for something in file
with open('data') as f:
if 'test' in f.read():
@Tharwat96
Tharwat96 / rails_naming_conventions.md
Last active March 26, 2020 14:48 — forked from iangreenleaf/gist:b206d09c587e8fc6399e
Rails naming conventions

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

@Tharwat96
Tharwat96 / Errors.md
Last active July 4, 2020 16:43
Jenkins tips & tricks

In this file I will list stubborn errors encountered and their fix in order not to fall for them again and solve them fast

SSH Build keeps failing because of secret key authorization error.
  • Make sure to generate the keys using rsa encryption.
  • Make sure that both keys (pub and priv) are a pair.
  • Don't trust Jenkins connections check as it has some issues sometimes.
  • Try using different Jenkins version on your development env to make sure it is not a jenkins error.
@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]
@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

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 / 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());
@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 / 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