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 / 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>
@marceloxp
marceloxp / gist:5759727
Created June 11, 2013 19:09
setToCenterOfParent
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 );
@marceloxp
marceloxp / switch-case.php
Last active December 18, 2015 08:29
switch case
switch ($i)
{
case 0:
echo "i equals 0";
break;
case 1:
echo "i equals 1";
break;
case 2:
echo "i equals 2";
@marceloxp
marceloxp / log-to-file.php
Created June 7, 2013 20:54
Save log to disk
function Log($texto)
{
$tw = $texto;
if (is_array($texto))
{
ob_start();
print_r($texto);
$tw = ob_get_contents();
ob_end_clean();
}