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 / 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
--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 / check_pessoa.sql
Created March 29, 2017 18:00
constraint para checar o tipo de uma pessoa
create temp table pessoa (tipo char(1), cpf int, cnpj int);
alter table pessoa add constraint pessoa_check check ( (tipo = 'f' and cpf is not null) <> (tipo = 'j' and cnpj is not null) and cpf is null <> cnpj is null);
insert into pessoa values ('f', 1, null); -- true
insert into pessoa values ('f', null, null); -- false
insert into pessoa values ('f', null, 1); -- false
insert into pessoa values ('j', null, 1); -- true
insert into pessoa values ('j', null, null); -- false
insert into pessoa values ('j', 1, null); -- false
<?php
$game = new Game();
while (true) {
$game->cycle();
}
class Game
{
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;
public class Game2048 extends JPanel {
enum State {
start, won, running, over
}
@hevertonfreitas
hevertonfreitas / slowloris.php
Last active February 14, 2017 12:49 — forked from Macuyiko/slowloris.php
PHP based slowloris attack with slow headers or post variants. Adapted from script here: <http://seclists.org/fulldisclosure/2009/Jun/207>
#! /usr/bin/env php
<?php
/* PHP Slowloris
* Adapted from the script found here: http://seclists.org/fulldisclosure/2009/Jun/207
* Contains get based attack (slow headers) and post based attack (long content length)
*
* Author: Seppe vanden Broucke
*/
function usage($argv)
<?php
/**
* Convert Hex Color to RGB
*
* @param string $h
* @return array
*/
function hexrgb(&$h)
{
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html/webroot;
index index.php;
location / {
autoindex on;
nginx:
image: nginx
ports:
- "80:80"
links:
- phpfpm
volumes:
- ./public:/usr/share/nginx/html
- ./nginx/default:/etc/nginx/conf.d/default.conf
@hevertonfreitas
hevertonfreitas / cpf_cnpj.sql
Created November 14, 2016 19:53
Utilidades CPF/CNPJ
CREATE OR REPLACE FUNCTION verifica_cnpj(text)
RETURNS boolean AS
$BODY$
-- se o tamanho for 14 prossiga com o cálculo
-- senão retorne falso
SELECT CASE WHEN LENGTH($1) = 14
THEN
(
-- verifica se os dígitos coincidem com os especificados
SELECT SUBSTR($1, 13, 1) = CAST(digit1 AS TEXT) AND