Skip to content

Instantly share code, notes, and snippets.

View rdemorais's full-sized avatar
🏠
Working from home

Rafael de Morais rdemorais

🏠
Working from home
View GitHub Profile
@rdemorais
rdemorais / table_size.sql
Created June 15, 2019 13:29
Tamanho das tabelas - Postgres
SELECT
schemaname,
relname as "Table",
pg_size_pretty(pg_total_relation_size(relid)) As "Size",
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "External Size"
FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;
select count(*) from
tb_lotacao le where le.ctid <> (select min(li.ctid) from tb_lotacao li
where li.co_pessoa = le.co_pessoa and li.ds_mes_ano = le.ds_mes_ano and li.co_unidade = le.co_unidade)
public static <T> Collector<T, ?, List<T>> lastN(int n) {
return Collector.<T, Deque<T>, List<T>>of(ArrayDeque::new, (acc, t) -> {
if(acc.size() == n)
acc.pollFirst();
acc.add(t);
}, (acc1, acc2) -> {
while(acc2.size() < n && !acc1.isEmpty()) {
acc2.addFirst(acc1.pollLast());
}
return acc2;
@rdemorais
rdemorais / web-serv-deployment.yaml
Created January 26, 2020 22:10
Serviço web simples
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: web
namespace: default
spec:
selector:
matchLabels:
run: web
template:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-ih
namespace: default
spec:
rules:
- host: web.meudominio.com.br
http:
paths:
@rdemorais
rdemorais / git-remove-branches.txt
Created August 8, 2020 16:06
Remover local branches
git branch -D `git branch --merged | grep -v \* | xargs`
@rdemorais
rdemorais / copy_text_to_pod.sh
Created November 1, 2021 16:03
kubectl copy without cp
#!/usr/bin/env bash
function copy_text_to_pod() {
namespace=$1
pod_name=$2
src_filename=$3
dest_filename=$4
base64_text=`cat $src_filename | base64`
kubectl --kubeconfig=conasems-config.yml exec -n $namespace $pod_name -- bash -c "echo \"$base64_text\" | base64 -d > $dest_filename"
@rdemorais
rdemorais / time_dim.sql
Created February 20, 2022 14:35
Create time dimension
INSERT INTO dm_time (co_dm_time, epoch, day_suffix, day_name, day_of_week, day_of_month, day_of_quarter, day_of_year, week_of_month, week_of_year, week_of_year_iso, month_actual, month_name, month_name_abbreviated, quarter_actual, quarter_name, year_actual, first_day_of_week, last_day_of_week, first_day_of_month, last_day_of_month, first_day_of_quarter, last_day_of_quarter, first_day_of_year, last_day_of_year, mmyyyy, mmddyyyy, weekend_indr)
SELECT datum AS date_actual,
EXTRACT(EPOCH FROM datum) AS epoch,
TO_CHAR(datum, 'fmDDth') AS day_suffix,
TO_CHAR(datum, 'TMDay') AS day_name,
EXTRACT(ISODOW FROM datum) AS day_of_week,
EXTRACT(DAY FROM datum) AS day_of_month,
datum - DATE_TRUNC('quarter', datum)::DATE + 1 AS day_of_quarter,
EXTRACT(DOY FROM datum) AS day_of_year,
TO_CHAR(datum, 'W')::INT AS week_of_month,
@rdemorais
rdemorais / transformer.py
Created July 23, 2022 12:31
Import transformer model into spacy v3
from thinc.api import Config
import spacy
DEFAULT_CONFIG_STR = """
[transformer]
max_batch_items = 4096
[transformer.set_extra_annotations]
@annotation_setters = "spacy-transformers.null_annotation_setter.v1"
@rdemorais
rdemorais / progress.py
Created July 23, 2022 12:43
Get download progress with boto3
import sys
import threading
class ProgressPercentage(object):
''' Progress Class
Class for calculating and displaying download progress
'''
def __init__(self, client, bucket, filename):
''' Initialize