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 / 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 / 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 / fizz-buzz.py
Last active February 19, 2023 21:29
FizzBuzz with lambda and destructuring
def fizz_buzz(n: int = 15) -> list[str]:
fizz = lambda x: x % 3 == 0
buzz = lambda x: x % 5 == 0
result = []
for i in range(1, n + 1):
if fizz(i) and buzz(i):
result.append("fizz_buzz")
continue
if buzz(i):
result.append("buzz")
@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 / 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 / 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 / getAndPostRequest.js
Last active January 17, 2022 08:16
Post request with pure JS - no jQuery/ajax
async function getData(){
let url = 'https://jsonplaceholder.typicode.com/posts/1';
let page = await fetch(url);
let json = await page.json();
console.log(json);
}
async function postData(){
let url = 'https://jsonplaceholder.typicode.com/posts';