Skip to content

Instantly share code, notes, and snippets.

Marcelo de Souza Lima marceloxp

Block or report user

Report or block marceloxp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View switch-case.js
switch (expression)
{
case label1:
statements1
break;
case label2:
statements2
break;
default:
statements_def
View colorAverage.php
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];
View new_gist_file.js
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 / validacao.php
Created Jul 2, 2014
Validação de dados - Brasil
View validacao.php
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 / format_cep.php
Created Jul 2, 2014
Formatação de dados - Brasil
View format_cep.php
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 / .htaccess
Last active Aug 29, 2015
Apache conditional .htpasswd
View .htaccess
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 / youtube_events.html
Created Mar 6, 2015
Capture Youtube events.
View youtube_events.html
<!-- <iframe width="500" height="306" src="//www.youtube.com/embed/xpto?rel=0" frameborder="0" allowfullscreen></iframe> -->
<div id="player"></div>
<script>var ytVideoId = "xpto";</script>';
<script type="text/javascript">
var player;
var timer1 = null;
var video_length = 0;
var video_percent_curr = 0;
var video_percent_last = 0;
@marceloxp
marceloxp / cakephp_log.php
Created Oct 26, 2015
Log SQL queries on CakePHP
View cakephp_log.php
$log = $this->Model->getDataSource()->getLog(false, false);
debug($log);
@marceloxp
marceloxp / httpd-vhosts.conf
Last active Jul 5, 2016
Apache Virtual Host
View httpd-vhosts.conf
<VirtualHost 127.0.0.1>
ServerAdmin webmaster@www.cake3.local.com.br
DocumentRoot "C:/um/xampp/projetos/git/job0003_cakephp3"
ServerName www.cake3.local.com.br
ErrorLog "logs/www.cake3.local.com.br-error.log"
CustomLog "logs/www.cake3.local.com.br-access.log" common
<Directory "C:/um/xampp/projetos/git/job0003_cakephp3">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
@marceloxp
marceloxp / git filters.txt
Last active Jan 8, 2018
Git Extensions Filters
View git filters.txt
- Ignores.
.(rar$|gz$|zip$|exe$|pdf$|log$)
- Text files.
.(php$|ctp$|mustache$|js$|css$|scss$|htm$|html$|less$|md$|txt$|yml$|map$|htaccess$|rb$|)
- No extension files.
(LICENSE|COPYING|empty)
- Languages files.
You can’t perform that action at this time.