Skip to content

Instantly share code, notes, and snippets.

View campezzi's full-sized avatar

Thiago Campezzi campezzi

View GitHub Profile
@campezzi
campezzi / ecs-cli-commands.sh
Last active February 22, 2021 02:02
Amazon ECS deployment using the ecs-cli
# Full documentation: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI.html
# Replace the cluster name, keypair, exposed ports etc. as necessary.
# Install the ECS CLI and make it executable
sudo curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest
sudo chmod +x /usr/local/bin/ecs-cli
# Configure the CLI (login details, region and cluster name)
ecs-cli configure --region ap-southeast-2 --access-key $AWS_ACCESS_KEY_ID --secret-key $AWS_SECRET_ACCESS_KEY --cluster CreateBTATaskUI
@campezzi
campezzi / 0-Agenda.md
Last active November 8, 2019 03:24
Refactoring
  • About me
  • The world's fastest explanation of refactoring
  • Some examples of refactoring from real-life applications
  • Hairier examples of refactoring from real-life applications
  • My refactoring algorithm
  • Open mic
@campezzi
campezzi / Application.ex
Last active January 17, 2019 01:54
Elixir - Using GenStage's ConsumerSupervisor to have a dynamic pool of consumer processes
defmodule MyApp.Application do
use Application
def start(_type, _args) do
children = [
Supervisor.Spec.worker(Producer, []),
Supervisor.Spec.worker(Consumer, [], id: 1)
]
opts = [strategy: :one_for_one, name: Stages.Supervisor]
@campezzi
campezzi / Howto convert a PFX to a seperate .key & .crt file
Created December 12, 2018 06:17 — forked from TemporaryJam/Howto convert a PFX to a seperate .key & .crt file
How to convert a .pfx SSL certificate to .crt/key (pem) formats. Useful for NGINX
source: http://www.markbrilman.nl/2011/08/howto-convert-a-pfx-to-a-seperate-key-crt-file/
`openssl pkcs12 -in [yourfile.pfx] -nocerts -out [keyfile-encrypted.key]`
What this command does is extract the private key from the .pfx file. Once entered you need to type in the importpassword of the .pfx file. This is the password that you used to protect your keypair when you created your .pfx file. If you cannot remember it anymore you can just throw your .pfx file away, cause you won’t be able to import it again, anywhere!. Once you entered the import password OpenSSL requests you to type in another password, twice!. This new password will protect your .key file.
Now let’s extract the certificate:
`openssl pkcs12 -in [yourfile.pfx] -clcerts -nokeys -out [certificate.crt]`
@campezzi
campezzi / server.js
Created October 20, 2017 04:58
CORS Bypass Proxy
const express = require('express');
const proxy = require('express-http-proxy');
const cors = require('cors');
const app = express();
app.use(cors());
app.use('/', proxy('http://target-server.com'));
app.listen(3005);
@campezzi
campezzi / ghci.conf
Created May 29, 2017 09:11
GHCI - Bold Cyan Lambda Prompt
:set prompt "\ESC[1;36mλ> \ESC[m"
@campezzi
campezzi / logsearch.sh
Created May 29, 2017 05:04
Search for lambda logs
#!/usr/bin/env bash
function get_events() {
echo "Fetching logs for $1 lambda in the $2 region (since $3)..."
aws logs filter-log-events --log-group-name "/aws/lambda/$1" --region "$2" --start-time "$3" --filter-pattern requestId | jq '.events'
}
case $1 in
"all")
get_events $2 ${3:-us-west-2} ${4:-1496030995836}
;;
@campezzi
campezzi / api.tf
Created November 15, 2016 00:01 — forked from keeth/api.tf
Apex + Terraform + AWS Lambda + API Gateway + JSON Encoded Errors + CORS
resource "aws_api_gateway_rest_api" "myApi" {
name = "myApi-${var.env}"
description = "My awesome API (${var.env} environment)"
}
resource "aws_api_gateway_deployment" "myApi" {
depends_on = [
"aws_api_gateway_integration.myApi_myEndpoint_post",
"aws_api_gateway_integration_response.myApi_myEndpoint_post",
"aws_api_gateway_integration_response.myApi_myEndpoint_post_400",
@campezzi
campezzi / query.sql
Created October 11, 2016 23:32
Calculate Postgres index size
SELECT
t.tablename,
indexname,
c.reltuples AS num_rows,
pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size,
pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size,
CASE WHEN indisunique THEN 'Y'
ELSE 'N'
END AS UNIQUE,
idx_scan AS number_of_scans,
@campezzi
campezzi / 01_imperative.exs
Created October 11, 2016 23:25
Comparison of an imperative bit of code vs. a typical Elixir functional implementation
chunk_size = 50_000
lists =
Enum.map(0..19, fn x ->
range_start = x * chunk_size
range_end = range_start + chunk_size
Enum.map(range_start..range_end, fn y -> %{data: %{title: "#{y} is love, #{y} is life"}} end)
end)
Enum.each(lists, fn list -> Repo.insert_all(Meme, list) end)