Skip to content

Instantly share code, notes, and snippets.

@brunoleles
brunoleles / Utils.java
Last active April 8, 2017 17:11
Calcula o HASH de uma string e retorna o valor em uma HEX String
/**
* Returns the HexString of a String
* eg.: hashDigest("hello") == "5d41402abc4b2a76b9719d911017c592"
*
* @param input input string
* @param algorithm algorithm to be used to compute the hash ( eg.: "MD5", "SHA1", "SHA-256" )
* @return the hash of the input string
*/
public static String hashDigest(String input, String algorithm)
{
@brunoleles
brunoleles / Access-Control-Allow-Origin.php
Last active May 23, 2017 17:54
Access-Control-Allow-Origin Snipet
<?php
// tells the CDN that the content 'Vary' depending on 'Origin' request header
header('Vary: Origin', true);
// allowed origins
$allowed_http_origins = array(
'http://example.com',
'http://www.example.com',
'http://127.0.0.1',
@brunoleles
brunoleles / validate_cnpj.php
Last active September 11, 2018 15:05 — forked from guisehn/gist:3276302
Validar CNPJ (PHP)
<?php
function validate_cnpj($cnpj) {
$cnpj = preg_replace('/[^0-9]/', '', (string) $cnpj);
$cnpj = str_pad($cnpj, 14, '0', STR_PAD_LEFT);
// Validar cnpj
if ($cnpj === '00000000000000') {
return false;
}
@brunoleles
brunoleles / validate_cpf.php
Last active September 11, 2018 15:05 — forked from guisehn/gist:3276015
Validar CPF (PHP)
<?php
function validate_cpf($cpf) {
$cpf = preg_replace('/[^0-9]/', '', (string) $cpf);
$cpf = str_pad($cpf, 11, '0', STR_PAD_LEFT);
// CPF Invalido
if ($cpf === '00000000000') {
return false;
}
@brunoleles
brunoleles / apn_p12_to_pem.sh
Last active February 21, 2017 23:19
Convert Apple Push Notification .p12 files to .pem for use on PHP
# not tested
openssl pkcs12 -in aps_cert.p12 -out aps_cert.pem -nodes -clcerts -passin pass:**** -passout pass:****
# "semi" - tested :]
openssl pkcs12 -in aps_cert.p12 -out aps_cert.pem -nodes -clcerts
# worked
openssl pkcs12 -in aps_cert.p12 -out aps_cert.pem
@brunoleles
brunoleles / readme.md
Last active April 8, 2017 17:07
PHP : URL safe base64 functions

Snippet para "url safe" base64 functions

function base64_url_decode($input)
{
    return base64_decode(strtr($input, '-_,', '+/='));
}

function base64_url_encode($input)
{
@brunoleles
brunoleles / run_lumen_on_sub_folder.md
Last active April 6, 2017 16:26
Run Lumen On Sub Folder

How to run Lumen on sub folder

Add this lines after the initialization of the $app variable on public/index.php file.

$SCRIPT_NAME = str_replace(['\\', '/index.php'], ['/', ''], array_get($_SERVER, 'SCRIPT_NAME', array_get($_SERVER, 'PHP_SELF', '')));
$_SERVER['REQUEST_URI'] = preg_replace('|' . $SCRIPT_NAME . '|', '', $_SERVER['REQUEST_URI'], 1);

That's it. 😎

@brunoleles
brunoleles / 001-default.conf
Last active April 13, 2019 11:29
Apache + Tomcat ( UTF-8 encoding AND @RequestParam( ) )
<VirtualHost *:80>
...
AddDefaultCharset utf-8
JkOptions +ForwardURIProxy
...
</VirtualHost>
@brunoleles
brunoleles / rm_docker_containers_imagens.sh
Created April 3, 2017 21:25
delete all docker containers and imagens
#!/bin/bash
#SOURCE: https://techoverflow.net/2013/10/22/docker-remove-all-images-and-containers/
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
# Source
# https://gist.github.com/scottnonnenberg/fefa3f65fdb3715d25882f3023b31c29
# About
# Better Git configuration
# https://blog.scottnonnenberg.com/better-git-configuration/
#
[user]
email = scott@nonnenberg.com
name = Scott Nonnenberg