Skip to content

Instantly share code, notes, and snippets.

View agu3rra's full-sized avatar
🧠
"Let chaos reign, then reign in chaos."

Andre Guerra agu3rra

🧠
"Let chaos reign, then reign in chaos."
View GitHub Profile
@agu3rra
agu3rra / docker-mongo.sh
Created February 14, 2020 23:05
Docker commands for playing with MongoDB
# Run a container and expose port to host
docker run --name mongo-instance-01 -p 27017:27017 -d mongo:latest
# Access its terminal
docker ps
docker exec -it <container-id> bash
# Run the same mongo DB in the above example with persistence.
docker volume create mongo-volume-01
docker run \
@agu3rra
agu3rra / caesarcipher.py
Created February 18, 2020 15:05
A simple snippet for a Caesar cipher in Python
message = 'Divide the army in two, advance and outflank them on the right. I will advance on the left flank from the woods getting them by surprise.'
message = message.replace(' ','')
message = message.replace(',','')
message = message.replace('.','')
shift_secret = 6
ciphered_message = ''
print(message)
for character in message:
if character.isupper():
ciphered_message += chr((ord(character) + shift_secret - 65) % 26 + 65)
@agu3rra
agu3rra / ospath-win.py
Created March 20, 2020 10:10
Python script to ensure Windows PATH has distinct values
# Not sure why some of them appear repeated but sometimes they do.
# Since there is a limit of 1024 chars to the SETX command, this sometimes comes in handy.
import os
path = os.environ['PATH']
elements = path.split(';')
elements = set(elements)
new_path = ''
for item in elements:
new_path+='{};'.format(item)
@agu3rra
agu3rra / unix-install.md
Created March 25, 2020 10:02
Installing binaries in Unix
  1. Extract tar file and place it in /usr/local. E.g.: tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
  2. Edit your $HOME/.profile adding export PATH=$PATH:/usr/local/<extracted folder>.
  3. source .profile.
@agu3rra
agu3rra / install.sh
Last active September 30, 2022 18:38
Installing .deb packages
sudo dpkg -i <installer>.deb
@agu3rra
agu3rra / key.sh
Created May 19, 2020 10:36
Create a pair of aync encryption keys
ssh-keygen -b 4096 -t rsa -C <youremail@domain.com>
@agu3rra
agu3rra / cmd.sh
Created September 5, 2020 23:16
Find and remove openjdk version from Ubuntu
apt list | grep jdk
sudo apt remove <program-name-here>
@agu3rra
agu3rra / coverage.sh
Created September 12, 2020 17:39
Python coverage report for pytest
pip install coverage
coverage run --omit 'venv/*' -m pytest
coverage report -m
@agu3rra
agu3rra / converter.py
Created September 17, 2020 16:32
Quick snippet to convert values into base64 encoding for usage with Kubernetes secrets.yml files
import yaml
import base64
# Assumes sample.yml will have a data: entry
if __name__ == '__main__':
with open('sample.yml', 'r') as fh:
stream = fh.read()
data = yaml.safe_load(stream)
for key, value in data['data'].items():
encoded = base64.b64encode(str(value).encode('utf-8')).decode('utf-8')
@agu3rra
agu3rra / kube.sh
Last active September 29, 2020 13:36
Userful Kubernetes Commands
az aks get-credentials -g <resourceGroup> -n <clusterName>
kubectl create namespace [namespacenamehere]
kubectl config set-context --current --namespace=[namehere]
kubectl exec --stdin --tty [podname] -- [command]
kubectl create -f samplePod.yml
kubectl logs pods/[podname]
kubectl apply -f deployment.yml --record
kubectl rollout stauts deployment [namehere]
kubectl rollout history deployment [namehere]
kubectl undo deployment [namehere] --to-revision=1