Skip to content

Instantly share code, notes, and snippets.

View viniciusjssouza's full-sized avatar

Vinícius Souza viniciusjssouza

View GitHub Profile
@viniciusjssouza
viniciusjssouza / auto_prune_docker.sh
Created February 15, 2019 11:01
Prune docker images after the disk getting a given usage
#!/usr/bin/env bash
# To deploy using cron:
#
# sudo crontab -l | tail -n1
# */5 * * * * /home/ubuntu/docker_prune.sh >/dev/null 2>&1
USED_SPACE=$(df -h | grep -viE "(tmpfs|loop)" | awk '{print $5}' | grep -v Us | grep -vi loop |sort -rV | head -n1 | tr -d '%')
DISK_LIMIT_PERCENTAGE=60
@viniciusjssouza
viniciusjssouza / logger.ex
Created February 25, 2019 22:51
elixir_better_logger
defmodule Logging.Logger do
@moduledoc "Handle application errors and log."
require Logger
def log_info(message) do
Logger.info(message)
end
def log_error(message, stacktrace \\ [])
SELECT current_database(), schemaname, tblname, pg_size_pretty(bs*tblpages) AS real_size,
pg_size_pretty(((tblpages-est_tblpages)*bs)::numeric) AS extra_size,
CASE WHEN tblpages - est_tblpages > 0
THEN 100 * (tblpages - est_tblpages)/tblpages::float
ELSE 0
END AS extra_ratio, fillfactor, pg_size_pretty(((tblpages-est_tblpages_ff)*bs)::numeric) AS bloat_size,
CASE WHEN tblpages - est_tblpages_ff > 0
THEN 100 * (tblpages - est_tblpages_ff)/tblpages::float
ELSE 0
END AS bloat_ratio, is_na
@viniciusjssouza
viniciusjssouza / postgres.sql
Last active September 8, 2020 18:11
Postgres commands
-- slow queries RUNNING
SELECT now() - query_start AS duration, datname, pid, query
FROM pg_stat_activity
WHERE state = 'active'
ORDER BY 1 DESC;
select * from locks();
select * from lock_relations();
@viniciusjssouza
viniciusjssouza / screen.txt
Last active April 5, 2019 12:34
Prevent GNU screen resizing you screen
Add this (from /etc/screenrc) to your ~/.screenrc:
# Change the xterm initialization string from is2=\E[!p\E[?3;4l\E[4l\E>
# (This fixes the "Aborted because of window size change" konsole symptoms found
# in bug #134198)
termcapinfo xterm* 'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l'
@viniciusjssouza
viniciusjssouza / launch_template.tf
Created April 6, 2019 14:36
Launch template with mixed policy - Terraform example
resource "aws_launch_template" "nodes_template" {
name_prefix = "nodes.stock-staging.querobolsa.space-"
image_id = "ami-03b850a018c8cd25e"
instance_type = "t3.small"
key_name = "${aws_key_pair.kubernetes-stock-staging-querobolsa-space-ec167cae983d36fa6a38301fa47f31da.id}"
iam_instance_profile {
name = "${aws_iam_instance_profile.nodes-stock-staging-querobolsa-space.name}"
}
network_interfaces {
@viniciusjssouza
viniciusjssouza / kubernetes.sh
Created April 6, 2019 17:56
Kubernetes useful commands #kubernetes #kops
#!/usr/bin/env bash
# install weave network driver
kubectl create -f https://git.io/weave-kube-1.6
# install kubernetes dashboard service
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml
# Create service account
kubectl create serviceaccount cluster-admin-dashboard-sa
@viniciusjssouza
viniciusjssouza / SEO guide
Created April 11, 2019 13:29
SEO useful tips
In order to build a site optimized for organic search engine rankings, it is important to implement certain standards throughout the code. These include:
- Specifying an alt tag on images
- Using the correct HTML tags for content hierarchy i.e., <h1>/<h2>/<h3> and p
- Connect the site to the company’s social pages
- Add an XML sitemap
@viniciusjssouza
viniciusjssouza / site optimizations
Created April 11, 2019 13:34
Web site optimizations
Optimizing websites is an art that few are familiar with. The more the engineer is able to list off the top of their head, the more likely they are to do all of the following naturally as they code instead of having to return later.
(Also, typically a professionally constructed site should score over 75 percent when analyzed by gtmetrix.com, which can also serve as a checklist.)
- Optimize all assets
- Place all assets on a separate, cookie-free domain. Using a CDN is best
- Avoid inline JavaScript and CSS
- Enable gzipping
- Ensure all code is minified
- Defer parsing of JavaScript
@viniciusjssouza
viniciusjssouza / klogs
Created June 28, 2019 15:19
access the logs of a running container inside a POD
#/bin/bash
# Access the current logs of the provided POD
#
# Parameter 1: the app name, which should match the deployment name (<app name>-deployment) and the container name.
POD_NAME=$(kubectl get pods -n stock --no-headers -o custom-columns=":metadata.name" | grep -m1 "$1-deployment")
echo "Acessing pod $POD_NAME"
kubectl logs "$POD_NAME" -n stock -c "$1" --follow