Sunday, March 8, 2015

JavaScript Object.observe()

Object.observe() is a part of  ECMA7Script7 ,is now landed in chrome36+. This is a method for asynchronously observing changes to javaScript objects.
Let's look at an example,


In the above code , the changes to the object "example" is observed , and it outputs the change type, change name , old value etc. The code is pretty much simple and self  explanatory.Just go through and you will understand it.
With this feature, two way data binding can be implemented without any MVC framework like Angular.
Sources:
http://www.html5rocks.com/en/tutorials/es7/observe/
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/observe

Thursday, June 2, 2011

A Counter Script In PHP


Below given script can be used as a counter.The value of the counter variable($dat) will be incremented each time it executes..


if (file_exists('count_file.txt'))
{
$fil = fopen('count_file.txt', r);
$dat = fread($fil, filesize('count_file.txt'));
echo $dat+1;
fclose($fil);
$fil = fopen('count_file.txt', w);
fwrite($fil, $dat+1);
}

else
{
$fil = fopen('count_file.txt', w);
fwrite($fil, 1);
echo '1';
fclose($fil);
}


Tuesday, May 31, 2011

php script to count the no of days to a date in the future

The below given php script count and display the no of days to a specific date in the future...
< ? php
         $d=date("d");
         $m=date("m");
         $y=date("Y");
 // Change this to the day in the future    
 $dd = 13;
 // Change this to the month in the future
 $mm = 05;
 // Change this to the year in the future
 $yy =2011;

/*COUNT THE NO OF DAYS TO THE DATE IN THE FUTURE */

 $dy=$yy - $y;
 if ($dy ==0)
   { $dm = $mm - $m;
     $days=(($dm-1)*30)+(30-$d)+$dd+($dm/2);
     echo "\r\n There are $days days remaining \r\n";
   }
 else
   {
     $days=(($dy-1)*365)+(30-$d)+((12-$m)*30)+(($mm-1)*30)+$dd+($dy*4);
     echo " There are $days days remaining ";
   }
?>

Monday, April 18, 2011

Python script to get the webpage source

Here is the python script to get the source code of any web page..all you need is to edit the url in the script.

import urllib

filehandle = urllib.urlopen('http://www.techyupdates.blogspot.com')

for lines in filehandle.readlines():
   print lines

filehandle.close()