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 / main.go
Created January 15, 2022 18:47
kill process by name
package main
import (
"fmt"
"syscall"
"github.com/shirou/gopsutil/v3/process"
)
var print = fmt.Println
@costa86
costa86 / nano_syntax.sh
Created December 7, 2021 15:19
nano syntax highlight
search_dir=/usr/share/nano/*.nanorc
nano_file=/.nanorc
for entry in `ls $search_dir`; do
echo include "'${entry}'" >> $nano_file
done
@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 / automate_git.sh
Last active December 1, 2021 13:04
Create repository using a script [requires SSH access]
TOKEN=<github_token>
USERNAME=<github_user>
FILENAME=automate_git.sh
echo "What name do you want to give your remote repo? "
read REPO_NAME
echo "Enter a repo description. Do NOT use spaces: "
read DESCRIPTION
@costa86
costa86 / download-scripts.sh
Created November 13, 2021 19:08
DevOps script
#create-github-repository
curl https://gist.githubusercontent.com/costa86/472edcbb933844ec98aa070ab90c49e6/raw/cb691dc5932b4070521e5d8bc1b41af48fb49a72/automate_git.sh -o automate_git.sh
#ssh-pyhon
curl https://gist.githubusercontent.com/costa86/e720730272385cd2c8c469c0fbac3c3d/raw/5b72d3a4a0b1c4bc73c8341f134a1d87248d8bcd/ssh-sftp-python.py -o ssh-python.py
#aliases
curl https://gist.githubusercontent.com/costa86/0869810c1dc492bb5f4d7d1b9fe8b73e/raw/6313cfe4c7270e87901ecf9f74284b8bc51b9866/aliases.sh -o aliases.sh
@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
@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"