Safe Redirect

Safe redirect:

<?php

function Redirect($Str_Location, $Bln_Replace = 1, $Int_HRC = NULL)
{
        if(!headers_sent())
        {
            header('location: ' . urldecode($Str_Location), $Bln_Replace, $Int_HRC);
            exit;
        }

    exit('<meta http-equiv="refresh" content="0; url=' . urldecode($Str_Location) . '"/>'); # | exit('<script>document.location.href=' . urldecode($Str_Location) . ';</script>');
    return;
}

?>

Convert Hex Color to/from RGB

Function to convert Hex Color to RGB

function hex2rgb($hex) {
   $hex = str_replace("#", "", $hex);

   if(strlen($hex) == 3) {
      $r = hexdec(substr($hex,0,1).substr($hex,0,1));
      $g = hexdec(substr($hex,1,1).substr($hex,1,1));
      $b = hexdec(substr($hex,2,1).substr($hex,2,1));
   } else {
      $r = hexdec(substr($hex,0,2));
      $g = hexdec(substr($hex,2,2));
      $b = hexdec(substr($hex,4,2));
   }
   $rgb = array($r, $g, $b);
   //return implode(",", $rgb); // returns the rgb values separated by commas
   return $rgb; // returns an array with the rgb values
}
$rgb = hex2rgb("#cc0");
print_r($rgb);
Array ( [0] => 204 [1] => 204 [2] => 0 )

Function to convert RGB color to Hex

function rgb2hex($rgb) {
   $hex = "#";
   $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);
   $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);
   $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);

   return $hex; // returns the hex value including the number sign (#)
}
$rgb = array( 255, 255, 255 );
$hex = rgb2hex($rgb);
echo $hex;
#ffffff

Pretify with laravel [Screenshots from Flickr]

Laravel Migration Screenshot

Laravel Generator

Screenshots from flickr Part 2

Screenshots from Flickr Part1

Test if jQuery is loaded

So to test if jQuery is loaded or not we can use 2 methods.

Method 1:
[javascript]
if (window.jQuery) {
// jQuery is loaded
} else {
// jQuery is not loaded
}
[/javascript]
Method 2:
[javascript]
if (typeof jQuery == ‘undefined’) {
// jQuery is not loaded
} else {
// jQuery is loaded
}
[/javascript]
Load jQuery:
[javascript]
if (!window.jQuery) {
var jq = document.createElement(‘script’); jq.type = ‘text/javascript’;
// Path to jquery.js file, eg. Google hosted version
jq.src = ‘/path-to-your/jquery.min.js’;
document.getElementsByTagName(‘head’)[0].appendChild(jq);
}
[/javascript]
NOTE:
Here we are checking for jQuery function being defined or not. This is a safe way to check for jQuery library being loaded. In case you are not using any other javascript libraries like prototype.js or mootools.js, then you can also check for $ instead of jQuery.

Angular Filters [Screenshots from Flickr]

.getSript – jquery loaded event

[javascript]
$(document).ready(function()
{
$(‘.table’).tableAddCounter();
$.getScript(“http://code.jquery.com/ui/1.9.2/jquery-ui.js”).done(function(script, textStatus) {
$(‘tbody’).sortable();
$(“.alert-info”).alert(‘close’);
$(“.alert-success”).show();
});
});
[/javascript]