Skip to content

Instantly share code, notes, and snippets.

View hevertonfreitas's full-sized avatar

Heverton Coneglian de Freitas hevertonfreitas

View GitHub Profile
@hevertonfreitas
hevertonfreitas / paises.sql
Created May 15, 2019 19:45
Lista dos paises do bacen
INSERT INTO paises (codigo, nome, status, created, modified) VALUES('132', 'Afeganistão', TRUE, NOW(), NOW());
INSERT INTO paises (codigo, nome, status, created, modified) VALUES('7560', 'África do Sul', TRUE, NOW(), NOW());
INSERT INTO paises (codigo, nome, status, created, modified) VALUES('153', 'Aland, Ilhas', TRUE, NOW(), NOW());
INSERT INTO paises (codigo, nome, status, created, modified) VALUES('175', 'Albânia, República da', TRUE, NOW(), NOW());
INSERT INTO paises (codigo, nome, status, created, modified) VALUES('230', 'Alemanha', TRUE, NOW(), NOW());
INSERT INTO paises (codigo, nome, status, created, modified) VALUES('370', 'Andorra', TRUE, NOW(), NOW());
INSERT INTO paises (codigo, nome, status, created, modified) VALUES('400', 'Angola', TRUE, NOW(), NOW());
INSERT INTO paises (codigo, nome, status, created, modified) VALUES('418', 'Anguilla', TRUE, NOW(), NOW());
INSERT INTO paises (codigo, nome, status, created, modified) VALUES('420', 'Antártica', TRUE, NOW(), NOW());
INSERT INTO paises (codigo,
@hevertonfreitas
hevertonfreitas / cloudflare-update-ip-ranges.sh
Created March 19, 2019 14:18
Script to update Nginx list of Cloudflare ips
#!/usr/bin/env bash
#/scripts/cloudflare-update-ip-ranges.sh
# Taken from https://marekbosman.com/site/automatic-update-of-cloudflare-ip-addresses-in-nginx/
# Location of the nginx config file that contains the CloudFlare IP addresses.
CF_NGINX_CONFIG_FILE="/etc/nginx/cloudflare"
LOG_FILE="/var/log/messages"
# The URLs with the actual IP addresses used by CloudFlare.
version: "2"
services:
database:
image: mysql:5.5
volumes:
- db_data:/var/lib/mysql
restart: always
ports:
- 3306:3306
@hevertonfreitas
hevertonfreitas / dv_ibge.sql
Created December 12, 2017 16:55
Digito verificador do código do IBGE (6 digitos)
create or replace function ibge_dv(codigo char(6))
returns char(1) as $$
select ((10 - resto) * (resto != 0)::int)::char(1)
from (
select
(
a135 +
left(a2, 1)::int + right(a2, 1)::int +
left(a4, 1)::int + right(a4, 1)::int +
@hevertonfreitas
hevertonfreitas / estados_cidades.sql
Last active February 16, 2022 19:35
Todas cidades do Brasil
CREATE TABLE estados (
id serial NOT NULL,
nome character varying(255) NOT NULL,
sigla character(2) NOT NULL,
populacao integer NOT NULL,
ibge character(2) NOT NULL,
CONSTRAINT estados_pkey PRIMARY KEY (id)
);
INSERT INTO estados (id, nome, sigla, populacao, ibge) VALUES (1, 'Acre', 'AC', 829619, '12');
@hevertonfreitas
hevertonfreitas / gist:5d3ec6f841e6ce74cf2074af7b1708b9
Created October 9, 2017 17:28
Recortar arquivo entre strings
grep -n -m 1 SEARCH_TERM FILE_PATH | sed 's/\([0-9]*\).*/\1/'
sed -n 16224,16482p filename > newfile
@hevertonfreitas
hevertonfreitas / psql_naturalsort
Created August 23, 2017 13:02 — forked from veob/psql_naturalsort
PostgreSQL natural sort
//sql
create or replace function naturalsort(text)
returns bytea language sql immutable strict as
$f$ select string_agg(convert_to(coalesce(r[2],length(length(r[1])::text) || length(r[1])::text || r[1]),'SQL_ASCII'),'\x00')
from regexp_matches($1, '0*([0-9]+)|([^0-9]+)', 'g') r; $f$;
//author: github.com/RhodiumToad
$('button[type="submit"]').click(function () {
$('input:invalid').each(function () {
// Find the tab-pane that this element is inside, and get the id
var closest = $(this).closest('.tab-pane');
var id = closest.attr('id');
// Find the link that corresponds to the pane and have it show
$('.nav a[href="#' + id + '"]').tab('show');
// Only want to do it once
@hevertonfreitas
hevertonfreitas / rename.sql
Created May 26, 2017 17:21
Rename Columns
SELECT CONCAT_WS(' ', 'ALTER TABLE', table_name, 'CHANGE', column_name, 'new_name DATETIME;')
FROM information_schema.columns
WHERE table_schema = 'database' AND column_name = 'old_name';
@hevertonfreitas
hevertonfreitas / gerador_cpf.sql
Created May 3, 2017 14:55
Gerador de CPF para plpgsql
CREATE OR REPLACE FUNCTION gerar_cpf()
RETURNS VARCHAR AS
$BODY$
-- ROTINA DE GERAÇÃO DE CPF SEM LOOP
-- Retorna string com CPF aletório correto.
DECLARE
vet_cpf INTEGER [11]; --Recebe o CPF
soma INTEGER; -- Soma utilizada para o cálculo do DV
rest INTEGER; -- Resto da divisão
BEGIN