Skip to content

Instantly share code, notes, and snippets.

View rameerez's full-sized avatar
creating

Javi rameerez

creating
View GitHub Profile
@rameerez
rameerez / listmonk-s3-policy.json
Created February 23, 2023 20:04
AWS IAM policy for a Listmonk user to access only one S3 bucket
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:PutBucketPublicAccessBlock",
@rameerez
rameerez / aws-al2023-ec2-instance-setup-for-rails-7-capistrano.sh
Last active May 3, 2023 16:40
Configure an AWS EC2 instance running Amazon Linux 2023 (AL2023) to run a Rails 7 app using Capistrano for deployment
#!/bin/bash
# This scrips takes a clean AWS Amazon Linux 2023 AMI and installs and configures
# everything needed to deploy a Rails app to it. The resulting state is a clean
# instance that can be used to build a base AMI for an EC2 ASG.
# --- AESTHETICS ---
# Define the color code for green for echo messages
@rameerez
rameerez / lambda_function.py
Last active December 25, 2023 01:02
AWS Lambda function to forward UptimeRobot up / down events to a Telegram group chat
# Needed previous configuration:
#
# - In UptimeRobot, configure a new **Webhook** Alert Contact with this POST payload:
# ```
# {
# "monitorID": "*monitorID*",
# "monitorURL": "*monitorURL*",
# "monitorFriendlyName": "*monitorFriendlyName*",
# "alertType": "*alertType*",
# "alertTypeFriendlyName": "*alertTypeFriendlyName*",
@rameerez
rameerez / lambda_function.py
Last active December 25, 2023 18:39
AWS Lambda function to send Telegram messages when CloudWatch alarms trigger
# You need to give the Lambda the following permissions.
# Head to the Lambda page, and under Configuration > Permissions > Resource-based policy statements add a new policy statement:
# - Select "AWS Service"
# - On "Service", choose "Other"
# - Statement ID: AlarmAction
# - Principal: lambda.alarms.cloudwatch.amazonaws.com
# - Source ARN: arn:aws:cloudwatch:us-east-1:YOUR_ACCOUNT_ID:alarm:*
# - Action: lambda:InvokeFunction
#
# The same result can be achieved with `aws-cli`:
@rameerez
rameerez / remove-site.sh
Last active December 26, 2023 03:40
Remove site from Apache conf
#!/bin/bash
# Ensure the script is run as root
if [ "$(id -u)" -ne 0 ]; then
echo -e "${RED}ERROR: This script must be run as root.${NC}"
exit 1
fi
# Define aesthetics
RED='\033[0;31m'
@rameerez
rameerez / aws-amazon-linux-al2023-ec2-instance-setup-for-rails-docker-kamal-deployment.sh
Last active January 14, 2024 20:27
Configure an AWS EC2 instance running Amazon Linux 2023 to deploy Rails apps using Kamal (Docker)
#!/bin/bash
# This scrips takes a clean AWS Amazon Linux 2023 AMI and installs and configures
# everything needed to deploy a Rails app to it using Kamal.
# The resulting state is a clean instance ready to accept Kamal (Dockerized) apps.
# --- AESTHETICS ---
# Define the color code for green for echo messages
@rameerez
rameerez / download_controlnet.py
Created February 15, 2024 02:39
Download all CrontrolNet models to Automatic1111
# Meant to be ran inside a `download.ipynb` notebook inside
# the `/workspace/stable-diffusion-webui/extensions/sd-webui-controlnet/models/` folder
# of an Automatic1111 installation
# !pip install requests
import requests
import os
# List of file names to download
@rameerez
rameerez / set-up-new-site.sh
Last active June 12, 2024 23:56
Bash script to set up a new site on a LAMP-based Ubuntu server (Wordpress, PHP, etc.)
#!/bin/bash
# Ensure the script is run as root
if [ "$(id -u)" -ne 0 ]; then
echo -e "\e[31mERROR: This script must be run as root.\e[0m"
exit 1
fi
# Define aesthetics
GREEN='\033[0;32m'
@rameerez
rameerez / add-new-website.sh
Last active June 12, 2024 23:56
Script to set up a new site with SSL cert in a Unix (Apache VirtualHost) server
#!/bin/sh
# Should be run as sudo
# Usage: add-new-website.sh domain -- script to set up a new site with SSL cert
# where:
# domain website domain without subdomains (ex: example.com)
if [ ! -z "$1" ]
then
@rameerez
rameerez / mail.example.com.conf
Last active June 26, 2024 08:24
Nginx configuration for Listmonk running on Docker port 9000 using SSL certificates provided by Bitnami on AWS Lightsail
# This file goes in /opt/bitnami/nginx/conf/server_blocks as mail.example.com.conf (make sure to replace the filename with your actual subdomain)
# This Nginx config file assumes we're runing a Bitnami image (thus the non-standard /opt/bitnami paths)
# FULL TUTORIAL to set up Listmonk on AWS Lightsail here: https://rameerez.com/free-mailchimp-alternative-email-marketing-service#listmonk-tutorial
server {
listen 443 ssl;
server_name mail.example.com;
server_tokens off;
ssl_certificate /opt/bitnami/letsencrypt/certificates/mail.example.com.crt;