Skip to content

Instantly share code, notes, and snippets.

View marceloxp's full-sized avatar
:octocat:
Learning

Marcelo de Souza Lima marceloxp

:octocat:
Learning
View GitHub Profile
@marceloxp
marceloxp / .htaccess
Last active August 29, 2015 14:16
Apache conditional .htpasswd
SetEnvIf Host .*local.yetanothersite.* VAR_LOCAL_SITE
SetEnvIf Host .*yetanothersitehomolog.com.br.* VAR_HOMOLOG_SITE
SetEnvIf Host .*www.yetanothersite.com.br.* VAR_PROD_SITE
Order Deny,Allow
AuthUserFile /var/../.htpasswd
AuthName "Authorized personnel only."
AuthType Basic
Require valid-user
Allow from env=VAR_LOCAL_SITE
@marceloxp
marceloxp / format_cep.php
Created July 2, 2014 15:24
Formatação de dados - Brasil
function formataCEP($cep)
{
$valor = str_replace(array('.','-',','),'',trim($cep));
$tam = strlen($valor);
if($tam == 8)
{
$p1 = substr($valor,0,5);
$p2 = substr($valor,5,3);
$resultado = $p1."-".$p2;
}
@marceloxp
marceloxp / validacao.php
Created July 2, 2014 15:17
Validação de dados - Brasil
function valida_cpf($cpf) {if (empty($cpf)) {return false; } $cpf = preg_replace("/[^0-9]/", "", $cpf); for ($i = 0; $i <= 9; $i++) {if (str_repeat($i, 11) == $cpf) {return false; } } for ($t = 9; $t < 11; $t++) {for ($d = 0, $c = 0; $c < $t; $c++) {$d += $cpf{$c} * (($t + 1) - $c); } $d = ((10 * $d) % 11) % 10; if ($cpf{$c} != $d) {return false; } } return true; }
@marceloxp
marceloxp / new_gist_file.js
Created October 7, 2013 14:14
JavaScript isset()
function isset () {
// http://kevin.vanzonneveld.net
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: FremyCompany
// + improved by: Onno Marsman
// + improved by: Rafał Kukawski
// * example 1: isset( undefined, true);
// * returns 1: false
// * example 2: isset( 'Kevin van Zonneveld' );
// * returns 2: true
@marceloxp
marceloxp / colorAverage.php
Created October 4, 2013 21:34
PHP Color Average
public function colorAverage($rect)
{
//$rect = array(x, y, w, h);
$im = @imagecreatetruecolor($rect[2], $rect[3]);
if (!$im) { return false; }
imagecopy($im, $this->info, 0, 0, $rect[0], $rect[1], $rect[2], $rect[3]);
$imgW = $rect[2];
$imgH = $rect[3];
@marceloxp
marceloxp / switch-case.js
Created July 23, 2013 21:26
JavaScript switch
switch (expression)
{
case label1:
statements1
break;
case label2:
statements2
break;
default:
statements_def
@marceloxp
marceloxp / new_gist_file
Created July 11, 2013 21:09
Firebug Lite - iOS
<script type="text/javascript" src="https://getfirebug.com/firebug-lite-debug.js"></script>
@marceloxp
marceloxp / trycatch.php
Created June 18, 2013 12:50
try -> catch
try
{
}
catch (Exception $e)
{
echo $e->getMessage();
}
@marceloxp
marceloxp / gist:5800634
Created June 17, 2013 21:30
Número randômico
Math.floor(Math.random()*1980).toString();
@marceloxp
marceloxp / gist:5798580
Created June 17, 2013 17:27
<script> jQuery 1.8.3
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>