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.py
Created October 28, 2023 11:22
Remove duplicated files in a folder
import os
import sys
def get_folder() -> str:
args = sys.argv
if len(args) != 2 or not os.path.isdir(args[1]):
print("a folder must be set as the first argument")
sys.exit(1)
return sys.argv[1]
@costa86
costa86 / Makefile
Last active May 29, 2023 12:21
Makefile for terraform to handle workspaces
valid_envs := dev uat bench prod
env := $(word 1,$(valid_envs))
cmd_plan := terraform plan -var-file=$(env).tfvars
cmd_apply := terraform apply -auto-approve -var-file=$(env).tfvars
cmd_destroy := terraform destroy -auto-approve -var-file=$(env).tfvars
ifeq (,$(filter $(env),$(valid_envs)))
$(error Invalid env specified. Available envs: $(valid_envs))
endif
@costa86
costa86 / fake_extension_detector.py
Last active March 26, 2023 13:01
Python script to monitor downloads folder and detect files with extensions maliciously tampered
import os
import magic
from pydantic import BaseModel
from enum import Enum
import tkinter as tk
import time
# Tip: run it in the background with: nohup python fake_extension_detector.py &
SECONDS_TO_WAIT = 60
@costa86
costa86 / folder_organizer_by_file_extension.py
Last active March 23, 2023 18:02
Python script to organize files by moving them to folders accordingly to their extensions
import os
import shutil
FOLDER = "/home/costa/Downloads"
NAME = "name"
EXTENSION = "extension"
EXTENSION_FOLDER_MAPPING = [
["text", ["doc", "docx", "pdf"]],
["image", ["png", "jpeg", "gif", "jpg"]],
@costa86
costa86 / spp.py
Last active May 31, 2023 16:23
python project creator
import os
from datetime import datetime
current_year = datetime.now().year
project_path = "/home/costa/coding/python"
author = "Lourenço Costa"
new_project = ""
gitignore_content = """
# Ignore compiled Python files
*.pyc
@costa86
costa86 / gist-cli.py
Last active February 19, 2023 20:39
Gist CLI
import requests
import json
from tabulate import tabulate
import questionary
import webbrowser
API_ENDPOINT = "https://api.github.com/gists"
AUTH_TOKEN = ""
USERNAME = ""
@costa86
costa86 / decorator.py
Created January 26, 2022 13:46
Python decorator to validate argument types (args and kwargs)
def check_args_and_kwargs_types(func):
def inner(*args, **kwargs):
hints = typing.get_type_hints(func)
#args
keys = func.__code__.co_varnames
args_dict = {}
for k, v in zip(keys, args):
@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 / 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