Skip to content

Instantly share code, notes, and snippets.

View hevertonfreitas's full-sized avatar

Heverton Coneglian de Freitas hevertonfreitas

View GitHub Profile
--Cria uma tabela de Plano de Contas
CREATE TABLE PlanoContas (
ID INT NOT NULL,
IDSup INT NULL,
Descricao character varying(50)
);
--Adiciona as constraints
ALTER TABLE PlanoContas ADD CONSTRAINT PK_Plano PRIMARY KEY (ID);
@hevertonfreitas
hevertonfreitas / Metronome.php
Last active April 20, 2017 14:37
PHP Metronomme
<?php
/**
* Class Metronome
*
* @see Based on original Java code located at http://rosettacode.org/wiki/Metronome#Java
*
* @author Heverton Coneglian <[email protected]>
*/
class Metronome
@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
@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';
$('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 / 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
@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 / 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 / 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 +
version: "2"
services:
database:
image: mysql:5.5
volumes:
- db_data:/var/lib/mysql
restart: always
ports:
- 3306:3306