Skip to content

Instantly share code, notes, and snippets.

View andrebaptista's full-sized avatar

André Baptista andrebaptista

  • Santa Maria, RS, Brazil
View GitHub Profile
@andrebaptista
andrebaptista / example.php
Last active October 28, 2016 19:05 — forked from mloberg/example.php
Correcting sending emails with html, because the function json_encode when content has html code, it is set to null
<?php
require("postmark.php");
$postmark = new Postmark("your-api-key","from-email","optional-reply-to-address");
if($postmark->to("[email protected]")->subject("Email Subject")->html_message("<p style='color: red'>Test mail</p>")->send()){
echo "Message sent";
}
@andrebaptista
andrebaptista / toggleAutoScalingGroup.md
Created September 30, 2020 02:13 — forked from veuncent/toggleAutoScalingGroup.md
AWS Auto Scaling Groups: scheduled start/stop

Tutorial: scheduled start/stop of EC2 instances managed by Auto Scaling Groups

If your EC2 instances in AWS are managed through Auto Scaling Groups, it is easy to schedule startup and shutdown of those instances, e.g. to save money.

This tutorial walks you through setting up an AWS Lambda function that is triggered by CloudWatch Events and automatically changes the min, max and desired instances in your Auto Scaling Group(s).

The idea is to toggle between 0 (stop) and a specifed min, max and desired amount of instances (start), so you only need a single Lambda function. The premise is that you do not touch these Auto Scaling Group settings manually, or you might make your EC2 instances nocturnal.

Create new Lambda function and Start Event

@andrebaptista
andrebaptista / middleware.py
Created October 27, 2020 13:20 — forked from SehgalDivij/middleware.py
Middleware in django to log all requests and responses(Inspired by another Github gist I cannot find the link to, now)
"""
Middleware to log all requests and responses.
Uses a logger configured by the name of django.request
to log all requests and responses according to configuration
specified for django.request.
"""
# import json
import logging
from django.utils.deprecation import MiddlewareMixin
@andrebaptista
andrebaptista / set ulimit
Created December 10, 2020 05:09 — forked from bfgits/set ulimit
Set Permanently ulimit -n / open files in ubuntu
# available limit
user@ubuntu:~$ ulimit -n
1024
# To increase the available limit to say 65535
user@ubuntu:~$ sudo vim /etc/sysctl.conf
# add the following line to it
fs.file-max = 65535
@andrebaptista
andrebaptista / nginx-tuning.md
Created December 10, 2020 16:20 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@andrebaptista
andrebaptista / react-app-s3-sync.sh
Created October 25, 2021 18:07 — forked from evert0n/react-app-s3-sync.sh
A shell script for uploading a React app build to S3 + CloudFront for deployment
#!/bin/bash
S3_BUCKET_NAME=$1
CF_ID=$2
# Sync all files except for service-worker and index
echo "Uploading files to $S3_BUCKET_NAME..."
aws s3 sync build s3://$S3_BUCKET_NAME/ \
--acl public-read \
--exclude service-worker.js \