Replacement sorting algorithm

$a = array(45,12,35,5,9);

print ”

";
print_r($a);

for($i=0;$i<=3;$i++)
{
   for($j=$i+1;$j<=4;$j++)   
   {     
      if($a[$i] > $a[$j])
      {
        $temp   = $a[$j];
        $a[$j]  = $a[$i];
        $a[$i]  = $temp;
      }
    }
}

print "
";
print_r($a);

Leave a comment

TinyEmce editor remove paragraph tag

forced_root_block : false,
force_p_newlines : ‘false’,
remove_linebreaks : false,
force_br_newlines : true,
remove_trailing_nbsp : false,
verify_html : false,

Leave a comment

Jquery Select option Manupulate.

$(“#SuperStartclaimForm_bill_city option”).each(function(i){
if($(this).val()== $(“#info_city”).val())
{
$(“#SuperStartclaimForm_bill_city option:eq(“+i+”)”).attr(‘selected’, ‘selected’);
}
});

Leave a comment

Git Tips

mahmud@XXX $ git branch
theme
master
* site
mahmud@XXX $ git checkout theme
error: You have local changes to ‘htdocs/static/images’; cannot switch branches.
mahmud@XXX $ git checkout -f
mahmud@XXX $ git checkout theme

Leave a comment

Dynamic field add and reorder.

$(document).ready(function(){

$(“input[name=labelInfo]”).click(function(){
var totalearnedAmount = parseFloat($(this).val())*-1;
$(“#totalearnedAmount”).val(totalearnedAmount);

});

$(“.close”).live(“click”,function(){
$(this).parent().parent().remove();
reordertable();
});

function reordertable()
{
$(“#infotable tr.count”).each(function(i){
$(this).find(“td:eq(2)”).find(“input”).attr(“name”,”product[“+i+”][qty]”);
$(this).find(“td:eq(3)”).find(“input”).attr(“name”,”product[“+i+”][sku]”);
$(this).find(“td:eq(4)”).find(“input”).attr(“name”,”product[“+i+”][product_name]”);
$(this).find(“td:eq(5)”).find(“input”).attr(“name”,”product[“+i+”][size]”);
$(this).find(“td:eq(6)”).find(“input”).attr(“name”,”product[“+i+”][color]”);
$(this).find(“td:eq(7)”).find(“input”).attr(“name”,”product[“+i+”][unit_retail_price]”);

});
}

var html;
var row;

$(“#addrow”).live(“click”,function(){
row = $(“#infotable tr.count”).length+1;
html = “

“;
$(“#infotable tr:last”).after(html);
});

});

//html

    Qty Item No Item Name Size Color Price

Leave a comment

Itune Api

itune.php

class ITune
{
private $itune_url;
private $apple_app_id;
private $itune_api_call;
private $data;

public function __construct($itune_url)
{
$this->itune_url = $itune_url;

if (preg_match(“/\/id(\d+)\?mt/”, $this->itune_url, $matches))
$this->apple_app_id = $matches[1];

$this->fetchInfo();
}

private function fetchInfo()
{
$this->itune_api_call = “http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsLookup?id=$this->apple_app_id&country=us&#8221;;

$context = stream_context_create(array(‘http’ => array(‘header’=>’Connection: close’)));
$content = file_get_contents($this->itune_api_call);
$content = json_decode($content);

$this->data = $content->results[“0”];
}

public function setVersion()
{
return $this->data->version;
}

public function setTrickName()
{
return $this->data->trackName;
}

public function setArtistName()
{
return $this->data->artistName;
}

public function setArtworkUrl512()
{
return $this->data->artworkUrl512;
}

}

Example

include (‘itune.php’);

$itune_url = “http://itunes.apple.com/us/app/air-wings/id496386846?mt=8&#8221;;
$content = new ITune($itune_url);

print $content->setVersion();

print “
“.$content->setTrickName();

print “
“.$content->setArtistName();

print “
“.$content->setArtworkUrl512();

Leave a comment

Facebook api

<div id =”fb-root”> </div >

<script type=”text/javascript” src=”http://connect.facebook.net/en_US/all.js&#8221; > </script >

<script type=”text/javascript”>
var fb_appid = <?php echo “303842489698334”; ?>
FB.init({appId:fb_appid,cookie:true,status:true,xfbml:true});
</script >

$(document).ready(function()
{
var user_photo;

// If user is already logged in via facebook
if (readCookie(‘fb_user_id’))
{
return false;
}

// Otherwise do FB login
/*
FB.Event.subscribe(‘auth.login’, function(response)
{

FB.api
(
{
method: ‘fql.query’,
query: ‘select uid,name,first_name,last_name,email,sex,hometown_location,current_location from user where uid=’+response.authResponse.userID
},
function (response)
{
data = “uid/”+response[0].uid;
data = data+”/name/”+response[0].name;
data = data+”/first_name/”+response[0].first_name;
data = data+”/last_name/”+response[0].last_name;
data = data+”/email/”+response[0].email;
data = data+”/sex/”+response[0].sex;
data = data+”/hometown_location/”+response[0].hometown_location;
data = data+”/current_location/”+response[0].current_location;

// window.location.href =”http://mh-jbplcanada.folsom.evoknow.com/auth/login/facebookLogin/”+data;
window.location.href =”http://mh-jbplcanada.folsom.evoknow.com/auth/signup/index/”+data;
}
);

});
*/

var data1;
var hometown;
var location;

FB.Event.subscribe(‘auth.login’, function(response)
{
FB.api
(
{
method: ‘fql.query’,
query: ‘SELECT pic_big_with_logo FROM user WHERE uid=’+response.authResponse.userID
},
function (response)
{
user_photo = response[0].pic_big_with_logo;
hometown=”;
location = ”;
}
);

$.getJSON(‘https://graph.facebook.com/me?access_token=’+response.authResponse.accessToken+’&callback=?&#8217;,
function (data)
{
data.fb_photo = user_photo;

// alert(data.name);
// alert(data.hometown.name);
// alert(data.location.name);

data1 = “uid/”+data.uid;
data1 = data1+”/name/”+data.name;
data1 = data1+”/first_name/”+data.first_name;
data1 = data1+”/last_name/”+data.last_name;
data1 = data1+”/email/”+data.email;
data1 = data1+”/sex/”+data.sex;

if(typeof(data.hometown)==”undefined”)
data1 = data1+”/hometown_location/”+”;
else
data1 = data1+”/hometown_location/”+data.hometown.name;

if(typeof(data.location)==”undefined”)
data1 = data1+”/current_location/”+”;
else
data1 = data1+”/current_location/”+data.location.name;

window.location.href =”http://mh-jbplcanada.folsom.evoknow.com/auth/signup/index/”+data1;

/*
$.ajax
({
type: ‘POST’,
url: ‘/auth/login/facebookLogin’,
data: data,
dataType: ‘json’,
success: function(signup_response)
{
if(signup_response.success == true)
{

createCookie(‘fb_user_id’, response.authResponse.userID );
var curDate = new Date();
location.href = signup_response.referrer;
}
}
});
*/

});
});

})

Leave a comment

Jquery slug option

$(“#Restaurant_Name”).keyup(function(){
var Text = $(this).val();
Text = Text.toLowerCase();
Text = Text.replace(/[^a-zA-Z0-9]+/g,’-‘);
$(“#Restaurant_Slug”).val(Text);
});

Leave a comment

Git log

Git log check from date(since) to date(before)

$git log –author=’Mahmud Hasan’ –since=”yyyy-mm-dd” –before=”yyyy-mm-dd”

Leave a comment

Watermark Image

function watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile) {
list($width, $height) = getimagesize($SourceFile);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($SourceFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height);
$black = imagecolorallocate($image_p, 0, 0, 0);
$font = ‘arial.ttf’;
$font_size = 15;

$grey= imagecolorallocate($image_p, 128, 128, 128);
imagettftext($image_p, $font_size, 0, 11, 21, $grey, $font, $WaterMarkText);
}

Leave a comment