Skip to content

Instantly share code, notes, and snippets.

View filipeandre's full-sized avatar

Filipe Ferreira filipeandre

  • 01:38 (UTC +01:00)
View GitHub Profile
@filipeandre
filipeandre / migrate_git_submodule_https_ssh.sh
Created August 12, 2024 07:02
Migrate gitmodules from https to ssh
#!/usr/bin/env bash
set -e
git config -f .gitmodules --get-regexp 'submodule\..*\.path' | while read -r key submodule_path; do
http_url=$(git config --file .gitmodules --get submodule.$submodule_path.url)
ssh_url=${http_url/https:\/\/github.com\//git@github.com:}
git config -f .gitmodules submodule.$submodule_path.url $ssh_url
git config -f .gitmodules submodule.$submodule_path.shallow true
echo "Updated $submodule_name ($submodule_path) URL:"
@filipeandre
filipeandre / list_banned_ips.sh
Last active August 5, 2024 11:02
Fail2ban usefull Aliases
sudo zgrep 'Ban' /var/log/fail2ban.log*
@filipeandre
filipeandre / read_gzipped_from_s3.ts
Last active August 1, 2024 11:21
Get a gziped file from s3 to memory
import { createGunzip } from 'node:zlib';
import { text } from 'node:stream/consumers';
import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3';
async function readGzippedFromS3(s3Client: S3Client, bucket: string, objectKey: string): Promise<string> {
const command = new GetObjectCommand({
Bucket: bucket,
Key: objectKey,
});
const response = await s3Client.send(command);
@filipeandre
filipeandre / create_ppt_presentation.py
Created July 10, 2024 07:33
Script used to create a power point presentation
from pptx import Presentation
from pptx.util import Inches
prs = Presentation()
# Slide 1: Title Slide
slide_1 = prs.slides.add_slide(prs.slide_layouts[0])
title_1 = slide_1.shapes.title
subtitle_1 = slide_1.placeholders[1]
title_1.text = "Suspend Manager Event Flow Representation"
@filipeandre
filipeandre / zip_lambda.py
Created July 2, 2024 18:53
Create a zip to be used as python lambda
#!/usr/bin/env python
import os
import re
import zipfile
import site
import argparse
"""Package this lambda"""
ignore = ["__pycache__", "_pytest"]
@filipeandre
filipeandre / remove_sls_sdk_wrapper.py
Last active June 17, 2024 17:27
Remove the AWS_LAMBDA_EXEC_WRAPPER env variable and sls-sdk-* layers from all aws lambdas of current region and account
import boto3
def list_and_update_lambdas():
client = boto3.client('lambda')
paginator = client.get_paginator('list_functions')
response_iterator = paginator.paginate()
lambdas_updated_count = 0
for page in response_iterator:
@filipeandre
filipeandre / mongo_collection_to_excel.py
Created June 15, 2024 21:25
Example of a script that exports a mongo db collection to an excel file
import os
import pandas as pd
from pymongo import MongoClient
import inquirer
import configparser
# pip install pymongo pandas openpyxl inquirer
config_file = 'to_excel.ini'
config_section = 'mongodb'
@filipeandre
filipeandre / update_to_most_recent_template.py
Last active June 14, 2024 14:25
It gets the latest github tag from a repository, gets a stack from an s3 location and deploy it by using a temporary bucket. It support deployment in another aws accounts. The settings are saved and it supports profiles.
import os
import sys
import re
import requests
import configparser
import tempfile
import uuid
import argparse
import subprocess
import inquirer
@filipeandre
filipeandre / valitate_hello_sign.py
Created June 6, 2024 16:46
Validate hello sign key
import requests
from requests.auth import HTTPBasicAuth
def validate_hellosign_credentials(api_key):
url = 'https://api.hellosign.com/v3/account'
response = requests.get(url, auth=HTTPBasicAuth(api_key, ''))
if response.status_code == 200:
print("Valid HelloSign credentials")
@filipeandre
filipeandre / get_user_data.sh
Created May 29, 2024 10:45
Get user data script from EC2
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
export INSTANCE_ID=`curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/instance-id`
sudo cat /var/lib/cloud/instances/$INSTANCE_ID/user-data.txt