Get accurate height of iframe of cross domain with no scroll

Create first webpage and include below code into this page

window.addEventListener('message', receiveMessage, false);

function receiveMessage(evt)
{
    alert("got message: "+evt.data);
}

Now create another webpage on other domain that you going to call in iframe inside first page and include below code into this page.

window.parent.postMessage('Hello Parent Frame!', '*');

when you will view first page , a message will be sent by cross domain webpage inside iframe and your first page will receive it and generate a alert.

you can change this alert event to some other even easily by editing first page code.

How to save bandwidth when using Skype

Recently I had a problem with Skype and how it uses bandwidth. If your ISP doesn`t limit your traffic you have no idea how lucky you are. However if your traffic is limited, using Skype and video chat it will probably eat a lot of bandwidth. If you`re using a 3G or 4G Internet Surf stick you`re probably being limited to 1,3,5,10,20 GB – month depending on what plan you`ve selected.

You can save bandwidth with Skype by applying those three methods, I`ve searched on the Internet for others but I couldn`t find any other suggestions, if you have any of them feel free to leave a comment.

1. Whenever you can try to initiate only voice calls, without video, it will save your bandwidth as in video mode, Skype will use up to 6 times more bandwidth. I`ve learned from my experience that if you will use an advanced web camera with a better resolution such as HD ( High Definition ) it will eat even more bandwidth, I don`t know how much exactly but I can give you the following example :

A. You can use a third party application such as CCleaner which allows you to disable programs from startup. If you already have CCleaner installed here`s how do to it :

Open “ CCleaner“ – go to – “Tools“ – select – “Startup“ – locate Skype in that list – click on – “Disable“

B. Do this manually, it should work in Windows 7, Vista and XP.

Click on Windows Start button – in the search box type – msconfig - hit “ENTER“ – go to – “Startup“ tab – locate Skype – make sure that you “UNCHECK“ Skype – click on “Apply“ – Select – “OK“. ( A restart will be required ).

c. Disable Skype Super Nodes. This is an option that allows Skype software to use your computer as a Super-Node. It is not sure how it will give this attribute to your computer but if you have a fast Internet Connection it will probably be enough. Skype will use ports 443 and 80 which will route traffic from other users that can`t access these ports. It`s a system that helps their network but it can seriously damage your bandwidth and you don`t want this if your traffic is limited such as the one from a 3G – 4G Internet Stick. Here`s how you can prevent-disable this feature:

Open “Skype“ – go to “Tools“ tab – select “Advanced“ option – click on “Connection“ – from there – uncheck “Use port 80 and 443 as alternatives for incoming connections“ and click “Save“.

That`s how you can prevent Skype to use a lot of traffic or should I say to limit-minimize the bandwidth usage for this application. Unfortunately I`ve learn all of these things due to fact that I use a 3 G Internet Connection ( mobile ) and as you probably know every MB is important when your bandwidth is limited.

php-frontend-developer-test-v2-answer 2014

Fantastic three sequence

 

The fantastic three sequence is a  series of numbers in which each subsequent number is the sum of the previous three,minus one. The first few numbers in fantastic three sequence are:

0, 1, 1, 1, 2, 3, 5, etc

Write a function that prints the Nth number in the fantastic three sequence to standard output.

 

<?php

function fantastic3($n) {

$series = array(0,1,1,1);

for($i=3 ; $i<=$n ; $i++){

$a = (isset($series[ (int)$i-3 ]))?$series[ (int)$i-3 ]:0;

$b = (isset($series[ (int)$i-2 ]))?$series[ (int)$i-2 ]:0;

$c = (isset($series[ (int)$i-1 ]))?$series[ (int)$i-1 ]:0;

$d = ($a+$b+$c)-1;

if($d<0){

$d = 0;

}

$series[$i] = $d;

}

echo $series[ (int)$n-1 ];

}

// Do NOT call the fantastic3 function in the code

// you write. The system will call it automatically.

?>

 


Question 2 of 4

Counts Days

 

Write a function named countDays which takes a single parameter named dateinstring which is string in the form ”MM.DD.YYY” represent a real date value. The function should print to the console the number of days from the beginning of the year specified in dateInString until the date represented in dateInString. If the value of dateInString is invalid, the function should print ”Bad format”  to the console.

 

 

  1. function countDays($dateInString)
  2. {
  3.     $data = explode(‘.’, $dateInString);
  4.     $begining = date_create($data[2] . ‘-01-01′);
  5.     $data = date_create($data[2] . ‘-’ . $data[0] . ‘-’ . $data[1]);
  6.     $interval = $data->diff($begining);
  7.     echo $interval->format(‘%R%a days’);
  8. }

Change Nickname

 

The following from enable user to change their nickname on their website.

 

 

 

  1. <?php

     

    function changeNickname($oldNickname, $newNickname, $users) {

    <?php

    function changeNickname($oldNickname, $newNickname, $users){

    $valid = preg_match(‘/^(([^0-9])+([A-Za-z0-9$#<>-_]+))$/i’, $newNickname, $matches);

    if($valid == true){

    $old_found = false;

    $new_exists = false;

    foreach($users as $id => $user){

    if($user[‘nickname’] == $oldNickname){

    $old_found = true;

    }

    if($user[‘nickname’] == $newNickname){

    $new_exists = true;

    }

    }

    if($old_found == true && $new_exists == false){

    echo ‘Your nickname has been changed from ‘.$oldNickname.’ to ‘.$newNickname;

    } else {

    echo ‘Failed to update’;

    }

    } else {

    echo ‘Failed to update’;

    }

    }

    }

    // Do NOT call the changeNickname function in the code

    // you write. The system will call it automatically.

    ?>

     

     


Calculate shipping fees

 

A script is required to calculate shipping fees for a store.the store has two types of shipping local shipping and international shipping. they are calculated according to the following formulas.

Local shipping: number of items * distance * .8

international shipping : number of  items * ( local distance * .8 + international distance * 1.2)

 

 

<?php

// Do not modify the Shipping class.

abstract class Shipping

{

private $_itemsCount;

private $_distance;

 

public function __construct($itemsCount, $distance)

{

$this->_itemsCount = $itemsCount;

$this->_distance = $distance;

}

 

abstract public function getFees();

public function getDistance()

{

return $this->_distance;

}

public function getItemsCount()

{

return $this->_itemsCount;

}

}

 

// You can modify code below this comment.

class InternationalShipping extends Shipping

{

private $_internationalDistance;

public function __construct($itemsCount, $distance, $internationalDistance){

parent::__construct($itemsCount, $distance);

$this->_internationalDistance = $internationalDistance;

}

public function getFees(){

$no_of_items = $this->getItemsCount();

$local_distance = $this->getDistance();

$international_distance = $this->_internationalDistance;

 

$fees = $no_of_items * ($local_distance * 0.8 + $international_distance * 1.2);

return $fees;

}

}

 

class LocalShipping extends Shipping

{

public function getFees(){

$no_of_items = $this->getItemsCount();

$local_distance = $this->getDistance();

$fees = $no_of_items * $local_distance * 0.8;

return $fees;

}

}

 

function calculateShippingFees($items) {

 

// To print results to the standard output you can use print

// Example:

// print “Hello world!”;

$total = 0;

foreach ($items as $key => $object) {

# code…

if($object instanceof InternationalShipping || $object instanceof LocalShipping){

$total += $object->getFees();

} else {

$total = 0;

break;

}

}

echo $total;

 

}

 

// Do NOT call the calculateShippingFees function in the code

// you write. The system will call it automatically.

 

?>

How to know the consumed amount of internet data of photon postpaid connection

photon daily consumption enquiry 7208012345

Above is the no if you want to know your tata photone data consumed till the day dial this no from phone no registered during getting the connection.

If, in any case it didn’t work. Just call the customer care no.

Change the title and email id of emails sent by wordpress automatically

Here again a better easy answer.

Mostly when setup WordPress for multi user registration, you will rarely notice that title and email address of mail sent by backed is something like title:  WordPress and sent by wordpress@example.com

But here i have a very easy way to change them with the name and email id of admin user automatically . Whenever you change admin email it up going emails will be sent by new email id set in admin profile.

So the magical code is as below:


/* admin */
function wpc_fromemail($email) {
$wpfrom = get_option( 'admin_email' );
return $wpfrom;
}

function wpc_fromname($email){
$wpfrom = get_option( 'blogname' );
return $wpfrom;
}

add_filter('wp_mail_from', 'wpc_fromemail');
add_filter('wp_mail_from_name', 'wpc_fromname');