Skip to content

Instantly share code, notes, and snippets.

Thiago Campezzi campezzi

Block or report user

Report or block campezzi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 0-Agenda.md
  • 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 Jan 17, 2019
Elixir - Using GenStage's ConsumerSupervisor to have a dynamic pool of consumer processes
View Application.ex
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 How to convert a .pfx SSL certificate to .crt/key (pem) formats. Useful for NGINX
View Howto convert a PFX to a seperate .key & .crt file
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 Oct 20, 2017
CORS Bypass Proxy
View server.js
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
GHCI - Bold Cyan Lambda Prompt
View ghci.conf
:set prompt "\ESC[1;36mλ> \ESC[m"
@campezzi
campezzi / logsearch.sh
Created May 29, 2017
Search for lambda logs
View logsearch.sh
#!/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 Nov 15, 2016 — forked from keeth/api.tf
Apex + Terraform + AWS Lambda + API Gateway + JSON Encoded Errors + CORS
View api.tf
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 Oct 11, 2016
Calculate Postgres index size
View query.sql
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 Oct 11, 2016
Comparison of an imperative bit of code vs. a typical Elixir functional implementation
View 01_imperative.exs
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)
@campezzi
campezzi / instructions.md
Last active Sep 19, 2016
Phoenix + Elm setup
View instructions.md

Phoenix + Elm Setup

Important

  1. This was tested on Phoenix 1.2.0;
  2. Make sure you have npm 3.x or above - older versions will spit out tons of Babel-related errors.

Instructions

  1. Create a Phoenix project: mix phoenix.new my_awesome_project
You can’t perform that action at this time.