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
@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; }
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
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 switch-case.js
switch (expression)
{
case label1:
statements1
break;
case label2:
statements2
break;
default:
statements_def
@marceloxp
marceloxp / new_gist_file
Created Jul 11, 2013
Firebug Lite - iOS
View new_gist_file
<script type="text/javascript" src="https://getfirebug.com/firebug-lite-debug.js"></script>
View trycatch.php
try
{
}
catch (Exception $e)
{
echo $e->getMessage();
}
@marceloxp
marceloxp / gist:5800634
Created Jun 17, 2013
Número randômico
View gist:5800634
Math.floor(Math.random()*1980).toString();
@marceloxp
marceloxp / gist:5798580
Created Jun 17, 2013
<script> jQuery 1.8.3
View gist:5798580
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
@marceloxp
marceloxp / FileNameUtils.php
Last active Jun 13, 2016
Captura um nome de arquivo de devolve um array de 2 elementos com o nome e extensão.
View FileNameUtils.php
<?
function GetFileParts($file_name)
{
$tmp = explode("/", $file_name);
$_filename = array_pop($tmp);
$tmp = explode(".", $_filename);
$ext = array_pop($tmp);
$fil = substr($_filename, 0, ((strlen($ext)+1) * -1));
$r = array();
$r["name"] = $fil;
@marceloxp
marceloxp / gist:5759727
Created Jun 11, 2013
setToCenterOfParent
View gist:5759727
function setToCenterOfParent(obj, parentObj)
{
var height = $( obj ).height();
var width = $( obj ).width();
if ( parentObj == window ) {
$( obj ).css( 'top', ( $( parentObj ).height() / 2 ) - ( height / 2 ) );
$( obj ).css( 'left', ( $( parentObj ).width() / 2 ) - ( width / 2 ) );
}
else {
$( obj ).css( 'top', ( $( parentObj ).height() / 2 ) - ( height / 2 ) + $( parentObj ).position().top );
You can’t perform that action at this time.