Pages

Wednesday, February 27, 2013

Sharing files in Linux!

python -mSimpleHTTPServer xxxx (xxxx- port number) to start HTTP Server at current working directory. Quite handy for sharing files/directories.

Friday, February 15, 2013

Pass a PHP array to a JavaScript function


Use JSON.
In the following example $php_variable can be any PHP variable.
<script type="text/javascript">
    var obj = <?php echo json_encode($php_variable); ?>;
</script>
In your code, you could use like the following:
drawChart(600/50, <?php echo json_encode($day); ?>, ...)
In cases where you need to parse out an object from JSON-string (like in an AJAX request), the safe way is to use JSON.parse(..) like the below:
var s = "<JSON-String>";
var obj = JSON.parse(s);

Thursday, February 14, 2013

$('#urlresults .concept-name').each(function(){$(this).html()});

$('#urlresults .concept-name').each(function (){if ($(this).html() === 'tarot readings') {$(this).html("test")}});

$('#urlresults .concept-name').each(function (){if ($(this).html() === 'test') {$(this).next(".block").html("block")}});

$('#urlresults .concept-name').each(function (){if ($(this).html() === 'bikini photos') {$next = $(this).next(".block"); $next.html($next.attr('data-tld'))}});

$('#urlresults .concept-name').each(function (){if ($(this).html() === 'bikini photos') {$next = $(this).next(".block"); $next.html(generateUnblockConceptLink($next.attr('data-tld'), $next.attr('data-basis'), $next.attr('data-admin-id'), $next.attr('data-url')))}});


Saturday, February 9, 2013

Comma Rupees php


<?php
function my_money_format($number)
{
    if(strstr($number,"-"))
    {
        $number = str_replace("-","",$number);
        $negative = "-";
    }

    $split_number = @explode(".",$number);

    $rupee = $split_number[0];
    $paise = @$split_number[1];

    if(@strlen($rupee)>3)
    {
        $hundreds = substr($rupee,strlen($rupee)-3);
        $thousands_in_reverse = strrev(substr($rupee,0,strlen($rupee)-3));
        for($i=0; $i<(strlen($thousands_in_reverse)); $i=$i+2)
        {
            $thousands .= $thousands_in_reverse[$i].$thousands_in_reverse[$i+1].",";
        }
        $thousands = strrev(trim($thousands,","));
        $formatted_rupee = $thousands.",".$hundreds;

    }
    else
    {
        $formatted_rupee = $rupee;
    }

    if((int)$paise>0)
    {
        $formatted_paise = ".".substr($paise,0,2);
    }

    return $negative.$formatted_rupee.$formatted_paise;

}
?>

http://php.net/manual/en/function.number-format.php

Change value of a select list using onclick in href


<form>
      <select id="action">
         <option value="a">Add</option>
         <option value="b">Delete</option>
      </select>
 </form>

<a href="#" onClick="document.getElementById('action').value='a'">Add</a> 
<a href="#" onClick="document.getElementById('action').value='b'">Delete</a> 

Tuesday, February 5, 2013



<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
function fetchKeywords(url,count,impressions){

$.ajax({

'url' : 'getData2.php',
'type' : 'GET',
'data' : {
'count':count,
'impressions':impressions,
'url':url
},

'success' : function(data) {


var div = document.getElementById('urlresults');

div.innerHTML = div.innerHTML + data;
}

});
 
 
   
  }</script>

Ajax Tutorial to fetch data from other URL


  • url - The target of the request.
  • type - The type of HTTP request either: "GET" (Default) or "POST".
    Difference between GET and POST.
  • async - Set asyncronous to TRUE if you want it to load in background and this will allow you to run mutiple AJAX requests at the same time. If you set to FALSE the request will run and then wait for the result before preceeding with the rest of you code.
  • data - Specify data you wish to pass with the AJAX call in "{param1: 'value1'}" format.
  • dataType - Specify the type of data that is returned: "xml/html/script/json/jsonp".
  • success - The function that is fired when the AJAX call has completed successfully.
  • error - The function that is fired when the AJAX call encountered errors.
  • jsonp - Allows you to specify a callback function when making cross domain AJAX calls.
  • timeout - You can also set a timeout on the AJAX call in milliseconds.
//Listen when a button, with a class of "myButton", is clicked
//You can use any jQuery/JavaScript event that you'd like to trigger the call
$('.myButton').click(function() {
//Send the AJAX call to the server
  $.ajax({
  //The URL to process the request
    'url' : 'page.php',
  //The type of request, also known as the "method" in HTML forms
  //Can be 'GET' or 'POST'
    'type' : 'GET',
  //Any post-data/get-data parameters
  //This is optional
    'data' : {
      'paramater1' : 'value'
      'parameter2' : 'another value'
    },
  //The response from the server
    'success' : function(data) {
    //You can use any jQuery/JavaScript here!!!
      if (data == "success") {
        alert('request sent!');
      }
    }
  });
});

Saturday, February 2, 2013

Making xampp to run properly on my windows machine


short_open_tag = On
error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT

Friday, February 1, 2013

php short tags problem

http://stackoverflow.com/questions/435705/why-is-no-longer-working-and-instead-only-php-works