Skip to content

Instantly share code, notes, and snippets.

View costa86's full-sized avatar
🏠
Working from home

Lourenço Costa costa86

🏠
Working from home
View GitHub Profile
@costa86
costa86 / updated-log-file.py
Created October 22, 2021 18:21
Get a new log file based on size
MAX_LOG_FILE_SIZE_IN_MB = 1.00
def get_current_log_file() -> str:
logs_path = os.path.join(os.getcwd(), "logs")
log_files = os.listdir(logs_path)
log_files_numbers = [int(i.split(".")[0].split("-")[-1])
for i in log_files]
greater_log_file_number = max(log_files_numbers)
current_log_file = os.path.join(
os.getcwd(), "logs", f"log-{greater_log_file_number}.json")
@costa86
costa86 / elastic.py
Last active October 10, 2021 15:48
Elastic Search with Python
from typing import List
import requests
import json
from pprint import pprint
from csv import reader,DictReader
from ast import literal_eval
base_url = "http://localhost:9200"
data_stream = "women"
@costa86
costa86 / fish.txt
Last active October 8, 2021 21:48
fish shell - define aliases and functions
fish
1.Create ~/.config/fish/config.fish
2.Set aliases here
3.Restart fish
----------
One-line solution for defining and saving an alias (for example): alias cl 'clear' -s. Instantly works across all sessions and is persisted.
Navigate to the ~/.config/fish/functions/ and you'll see cl.fish file.
------------------
Functions in this dir are auto-loaded
@costa86
costa86 / ssh-sftp-python.py
Last active September 27, 2021 08:49
Python script to display and connect to available SSH/SFTP servers
"""
Requirements:
tabulate==0.8.9
"""
import os
from tabulate import tabulate
headers = ["ALIAS",'USER',"IP","PRIVATE KEY FILE","LOCAL FORWARD","ID"]
PRIMARY_SSH_KEY = r"C:\Users\costa\.ssh\sample"
@costa86
costa86 / cloufare-api.py
Last active December 2, 2021 12:34
CloudFare API as CLI
import click
import requests
ZONE = "<zone>"
API_VERSION = 4
TYPE_TYPES = list(set(["CAA","A","AAAA","CNAME","URI","MX","SRV","URI","TXT","CERT","DS","HTTPS","LOC","NAPTR","NS","PTR","SMIMEA","SPF","SRV","SSHFP","SVCB","TLSA","TXT"]))
TYPE_TYPES.sort()
defaults = {
"email": "<email>",
@costa86
costa86 / aliases.sh
Last active September 11, 2022 15:45
Aliases for Ubuntu
#misc
alias c=clear
alias l=ls
alias start="xdg-open"
#docker
alias dcu="docker compose up"
alias dcd="docker compose down"
alias dcud="docker compose up -d"
alias di="docker images"
@costa86
costa86 / main.tf
Created August 5, 2021 14:44
Terraform example for Digital Ocean
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.10.1"
}
random = {
source = "hashicorp/random"
version = "3.1.0"
}
@costa86
costa86 / config
Last active July 30, 2021 17:42
SSH config file
Host *
IdentitiesOnly=yes
Port 22
Host <custom_name>
Hostname <ip>
User <user>
IdentityFile <private_key>
Host <another_custom_name>
@costa86
costa86 / create-user.sh
Last active July 29, 2021 15:07
Create a user
read -p 'User: ' user
group=$user
adduser $user
usermod -aG sudo $user
cd /home/$user
rsync --archive --chown=$user:$group ~/.ssh /home/$user
su $user
@costa86
costa86 / create-ssh-key.sh
Last active November 13, 2021 17:08
Create SSH key - bash
eval "$(ssh-agent -s)"
number=100
path=$HOME/.ssh/
read -p 'Keyname: ' keyname
comment=$keyname
ssh-keygen -a $number -t ed25519 -f $path$keyname -C $comment
ssh-add $path$keyname