Sunday, November 27, 2011

Sanath starts crawling

Sanath has started crawling since a couple of days. Most kids go backward first, trying to go forward. Sanath directly started going forward

Thursday, September 8, 2011

Sanath Babu turns over

We were lucky to catch the occasion sanath rolled over for the first time. Sanjay is in bangalore, for his onam vacation. Arya as usual is in our room at night, trying out the dresses of Sanath. He was making efforts to roll over for the past 2 days, and I was shooting with veena's mobile. suddenly, he was successful. 

Wednesday, August 24, 2011

Account management script in Python for Android


for this script, you need to download sl4a.  and also install python for android from the download page in this site. 

import android, os , datetime


droid = android.Android()


docdir = "./"
loop = 1
file_name=""


def select_account ():
 dirfile = os.listdir (docdir)
 dirfiles =[]
 for f in dirfile :
  if f[-4:]==".acc":
   dirfiles.append (f)
 if len(dirfiles) == 0:
  droid.makeToast('no accounts')
  return
 d=droid.dialogCreateAlert("select file")
 droid.dialogSetSingleChoiceItems(dirfiles)
 droid.dialogSetPositiveButtonText('ok')
 droid.dialogSetNegativeButtonText('cancel')
 droid.dialogShow()
 r=droid.dialogGetResponse().result
 if r['which']== "negative":
  return (1)
 result = droid.dialogGetSelectedItems().result[0]
 global file_name
 file_name = dirfiles [result] 
 return (0)


def add_dialogue():
 if select_account () != 0:
  return
 f = open (docdir + file_name, "a")
 droid.dialogCreateAlert(None, None)
 droid.dialogSetSingleChoiceItems(["receipt", "payment"], 0)
 droid.dialogSetPositiveButtonText('ok')
 droid.dialogShow()
 r = droid.dialogGetResponse().result
 receipt = droid.dialogGetSelectedItems().result[0] 
 amount= droid.dialogGetInput("amount", None, None).result
 try:
  famount = float (amount)
  if receipt == 1:
   famount = -famount
 except:
  return
 head = droid.dialogGetInput("description", None, None).result 
 out_string = str(datetime.date.today()) + " :: " + head + " :: " + str(famount)
 f.write (out_string +"\n")
 droid.makeToast(out_string)


def show_dialogue():
 if select_account () != 0:
  return 
 f= open ( docdir+ file_name , "r")
 lines = f.readlines ()
 message = ""
 total= 0
 for line in lines:
  values = line.split (" :: ")
  message = '%+6.0f : %-8s : %s\n' % ( float ( values[2]), values[1][:8], values[0][5:]) + message
  total += float (values[2])
 message = "Total = " + str(total)  + "\n\n" + message
 droid.dialogCreateAlert(None, message)
 droid.dialogShow()
 droid.dialogGetResponse()


def create_account ():
 f = droid.dialogGetInput('Account name', None, None).result
 if f == None:
  return
 f = docdir + f +".acc"
 file = open (f, "w")
 file.close ()
 droid.makeToast('created file: ' + f)


while loop:
 droid.dialogCreateAlert(None, None)
 droid.dialogSetSingleChoiceItems(["add transaction", "show accounts", "create account"], 0)
 droid.dialogSetPositiveButtonText('ok')
 droid.dialogSetNegativeButtonText('exit')
 droid.dialogShow()
 r=droid.dialogGetResponse().result
 if r['which']== "negative":
  os._exit (1)
 result = droid.dialogGetSelectedItems().result[0] 
 if result == 0 :
  add_dialogue()
 elif result == 1:
  show_dialogue()
 else:
  create_account ()

Tuesday, July 5, 2011

Why do we sleep

People think we sleep to take rest. But we can rest without sleeping. Not all of us rest while we sleep. Not surely  the heart or respiratory muscles. And if your brain rested, we won't have any dreams.

The purpose of sleep always intrigued me. And I was not alone. At least a few other people were there too. I found these two sites (big think and physorg.com) where the neuroscientists' opinion about the matter is discussed. Basically they think the reason for sleep is either :
  • information processing theory - to sort out the informations that have come in during the day (brain defragmentation?)
  • damage reversal theory - to remove free radicals and other noxious substances generated by 'heated thinking' during the day
  • adaptive inactivity theory - by UCLA neuroscientist Jerome Siegel, which says that sleep optimizes the timing of our activity.
I prescribe to the last POV. Sleep is not a physiologically necessary process. Our body can rest, take care of free radicals and organize memory without sleeping, if it needed to.

Evolutionarily it takes a lot to adapt to a particular environment. So all organisms, are adapted to one or the other kind of environment (called ecological niche). Then, at the same place, the environment changes vastly during the 24 hours a day. Animals behavior is expected to vary greatly during the day and night. For one animal, it may be difficult to be this versatile, so, nature makes it adapted to one of the time period in a day, and sleep during the other.
Pretty neat?

Sunday, July 3, 2011

android scripting using python

Android has a beautiful scripting platform 'sl4a'. You can script using lot of languages perl, python, shell etc in it. It has a good API for system calls like sending sms, making calls etc.

I've written a small script in python to send a group sms with individualised content.



import android, os, re

droid = android.Android()
docdir = "/mnt/sdcard/document"




Android calls are in android module. other modules like sys, os, re are available.



message =droid.dialogGetInput('message', ' extras: 0 name,1 mail', None).result
subject =droid.dialogGetInput('subject', '', None).result


message windows can be created using API calls.



dirfile = os.listdir (docdir)
dirfiles =[]
for f in dirfile :
 if f[-4:]==".sms":
  dirfiles.append (f)
d=droid.dialogCreateAlert("select file")
droid.dialogSetSingleChoiceItems(dirfiles)
droid.dialogSetPositiveButtonText('ok')
droid.dialogSetNegativeButtonText('cancel')
droid.dialogShow()
r=droid.dialogGetResponse().result
if r['which']== "negative":
 os._exit (1)
result = droid.dialogGetSelectedItems().result[0]
selfile = dirfiles [result]

All files in a directory ending with .sms is presented and the user is asked to select one of the files.




file = open (docdir + os.sep+ selfile, "r")
lines = file.readlines ()
contacts = []
numbers =[]
extras =[]
mail =""
for line in lines:
 f = line.split (",")
 if len (f[0])>0 :
  numbers.append (f[0])
  contacts.append (f[1])
  extras.append (f[1:])
 if len (f[1])>0 :
  mail = mail + f[2].replace(" ","").replace ("\n","") + ","

The .sms file is a comma seperated file whose first field is the contact number, second contact name, third his email, and any optional field which can be referred as $n in the message.



d=droid.dialogCreateAlert("select contacts")
n = len (contacts)
droid.dialogSetMultiChoiceItems(contacts, range (n))
droid.dialogSetPositiveButtonText('ok')
droid.dialogSetNegativeButtonText('cancel')
droid.dialogShow()
r=droid.dialogGetResponse().result
if r['which']== "negative":
 os._exit (1)
send_contacts= droid.dialogGetSelectedItems().result

for s in send_contacts :
 m= message
 for d in range(len(extras [s])):
  m = m.replace ("$"+str(d), extras[s][d])
 m=re.sub('\$\d','',m)
 droid.smsSend(numbers [s], m)
 print contacts[s] , m
droid.sendEmail(mail, subject, message, None)

The user is presented  a list of contacts to select from, to whom to send the message. The script also sends an email with the same message (without personalisation)

Friday, June 3, 2011

Evolution of Sexes

Want to know why there are sexes at all? 
Or Why there are two sexes?
Or why the sexes are different?
Read on

As you know, evolution shapes it all. We can refer to this non-existent ethereal concept as a person or object, because it works out things mathematically, and often we can 'predict' in biology with evolutionary theory. We can do some armchair theorizing also, with the help of TOE (Theory of evolution).


How sexes evolved


As you already know, at first there were asexual organisms and asexual reproduction. The progeny just resembled the parent, and the evolution and adaption to the environment was slow. When the gametes of two organisms exchange their genetic material, the offspring carries different combination of the species' genes, and thus, the population comprised individuals with different characters, which let the evolutionary force select the fitter ones. Thus when sexual reproduction appeared in the scene, it had advantage over the asexually reproducing ones, and they out-populated them soon. The advantage was worth the pain of evolving the complex mechanisms for this purpose, but as seen repeatedly, nature (or evolution) can go to any length, for a survival advantage.


Why sexes are different


The sexual reproduction only requires that the offsprings are produced by exchange of genetic material between different individuals. Not between two sexes.
Then why there are two sexes? Because there are different sex chromosomes? The sex chromosomes are different because, they are needed to produce the differences in male and female, not the other way.
In the beginning, indeed there was no different sexes. Any individual could exchange the genetic material with any other of the same species. (You can call all individuals were unisex or that all were true hermaphrodites. All chromosomes were same in all individuals. There were no sex chromosomes.
The advantage of different sexes was in the sea, where life was thriving then. The organisms used to move in the sea, either carried by the current or by swimming with own power. The chance of meeting another individual of same species, and then mating and passing one's genes to next generation before one's death was a big thing then. The organisms adopted all possible strategies to achieve this. One organism could increase it's chance mainly by two strategies. Either moving fast and far, or by becoming big and easily seen. So, different individuals of same species adopted these strategies, and both were mutually exclusive. To move fast, one has to be small, and to be easy target, one has to be big. There cant be intermediate organisms. So all species evolved their members into two distinct sets, one big and one small. They had to have distinct genetics, distinct genetic control mechanisms (steroid hormones control the expression of genes) etc. So, sexes evolved to evolve members of different characters, especially sizes. As the species evolved, and required different characters in different enviornments, the difference between sexes also kept varying, and adopting.


Why the sexes have different characters?


Our steroids make us different not only in sexual organs, but all over physically, on our muscles, shape, psyche etc. These differences are required for the differing needs of the different strategies of two sexes.
To this date, we have retained some of the original characters of sex differences, male gametes are small and fast and female ova are big and non-motile. Only that the original character has moved from the individual to it's gamete!
The individual itself also retains these original characters. The females are stationary, like to attract males, be the target. Males run around, eying any female at sight, and are involved in temporary relationships! We still carry the characters of those small insignificant creates in the sea!

Saturday, April 30, 2011

Does drinking cold water cause soar throat?

People got this wrong idea. Soar throat is an infection, and is not caused by a physical insult (that too just bit cold water). There are few references available. see the link below:

Read these references



Published with Blogger-droid v1.6.8

Friday, April 22, 2011

New member in our family

Veena had her second cesarean yesterday (May 22nd.) Dr Jayakrishnan was the anesthetist. Dr Vinod was Pediatrician. Everything went on smooth, baby cried immediately, Veena was fine afterwards. (Though she was quite apprehensive in the begining)


Wednesday, April 20, 2011

An Introductory guide to Android phones

I was quite skeptical about smartphones, and believed mobile phones are best used as only phones. In the past I had tried windows mobile phones (about which I was quite impressed) and moto rokr linux phone, but still, I thought they will never take over the functions of a computer.

Then iPhone (by Apple computers)  came along, which was quite expensive, and then Google Inc- the company that does everything right- ventured into making smartphone operating system, Android, about two years ago. The company started with its search engine, Google, which became synonymous with data search on the internet, for which computers are primarily used by most of the people. Android phones too, were quite expensive, but recently many mid and lower end androids have come to market, and become quite affordable, which offer almost the same functionalities of an expensive phone.
Samsung Galaxy Android phone

Android or iPhone:
Both phones are quite impressive, and fans argue vehemently on either side. A comment on Youtube best summed up the comparison of two phones as: iPhone is sturdy, impressive in style, and  easy to use, but limited in customisation and the user is confined to what Steve Jobs (Apple founder and CEO. Please see his great speech here) gives him. Android is endless power to end user, runs on sturdy lnux platform, but not so user friendly and easy as iPhone. So, if you want to have a nice cute easy phone, go for iPhone, but if you want endless power of a mini unix computer in your hand, go for Android.


Android Operating system:
Android runs on the famous Linux operating system, which is a Unix derivative. Unix operating system long preceded any other operating system known today, including windows, and still a major operating system, that's amazingly scalable, used from small embedded systems to super computers and satellites. It's underlying idea is so simple and beautiful, that, unix enthusiasts refer to it as Unix Philosophy. Google created a layer on Linux operating system, to make it easy for programmers to write programs in Java, a popular programming language.


Endless Options:
When you install a third party application in android phone, it gets the same privileges of the stock programs (if you grant it). That means, you can replace the dialer interphase, sms application, everything. You can make the phone look and behave like a windows 7 phone or iPhone! Android applications are created as diffferent components, which can be invoked by a particular message (Intent). If you write a particular application to send sms, and you want to use it's second screen (activity, in android lingo) in some other application, it's possible. Android is true multi-tasking environment (which, surprisingly, is not the case with iPhone), and user simply switches the apps. The apps remain open in memory, and android closes them, when memory is to be recovered, user doesn't have to close a program. In iPhone, if you switch apps the first app is immediately closed; and if the first app is to be opened again, it has to be loaded again to memory.

More than a Computer:
Beyond the normal use to browse, email, chat and social networking, androids can be used to make phone calls! LOL.
And beyond these normal functions, the phone has sensors, which sense orientation, acceleration, temperature, pressure, proximity etc. The Google sky is an application that uses sensors in a great way, and when you turn the phone to any direction, the apps shows you the stars in the sky in that direction. Layar is an application that superimposes the location details (such as coffeshops, ATM machines) on the phone camera view. If you just point your phone to a building, you can know what it is, what all interesting places it contains etc! Sensors are used in gaming too, like in car races, where steering done by tilting the phone to either side.

to conclude, I love my Android.

Monday, February 28, 2011

javascript image slideshow

php used to open a directory, select image files in it (even if it contains only images, this check is necessary, otherwise, we'll get '.' and '..' files too. php 'echos' a script which initialises an array of images of these images. the browser just gets the script text from the server, which makes it set the array. 

<?php
if (!$dir=opendir("activities")) echo "could not open dir" ;
$javastr = "<script language=\"javascript\">";
$javastr .= "var d = new Array();";
$num=0;
while ( ($file = readdir($dir)) != false )
{
  if (preg_match ("/.jpg$/i",$file)) {
    $name = preg_replace("/.jpg$/","",$file);
    $javastr .= "d[$num] = new Image();";
    $javastr .= "d[$num].src = 'activities/$file';";
    $javastr .= "d[$num].name = \"$name\"; ";
    $num++;
  }
}
$javastr .= "</script>";
echo $javastr;
?>

a placeholder 'div' defined.

<div id="para">
<div id="activity_div" >
 <div id="slide_caption" ></div>
 <div id="slider"><img name="slide"   /></div>
</div>


In the javascript, a function is iterated to change the slides, passing it the serial number of the slide to be put up. It calls another function which calls itself, till it has finished fading out the current slide, change the image source of the slide, then fading in the slide.   The loop is within the nested function. In javascript, nested function cannot be called within a loop, so, it can't be in the first function.

<script language="javascript" >
 var num=0;
 document.images.slide.src=d[num].src;
 document.getElementById("slide_caption").innerHTML = d[num].name;
 function slideit() {
  var alfa = 0;
  num++;
  if (num==d.length) num=0;
  setalpha(num,alfa);
  setTimeout("slideit()",2500);
 }
 function setalpha(numm, alpha) {
   if (alpha>2) return;
   if (alpha<1) {
     document.getElementById("slider").style.opacity = 0.9-alpha;
   }
   else if (alpha>1.1) {
     document.getElementById("slider").style.opacity = alpha-1;
   }
   else  {
    document.images.slide.src=d[numm].src;
    document.getElementById("slide_caption").innerHTML = d[numm].name;
   }
   alpha += 0.1;
   setTimeout(function() {setalpha(numm,alpha);},50);
 }
 slideit();
</script>

the sample site:
http://midtownpayyanur.orgfree.com/activities.php

Saturday, February 26, 2011

Javascript multiple image fadein

I just got multiple images to fade-in on page load using javascript. I thought, i 'll put down how to do it, since all online helps were bit confusing, at the least.

at first, there's an onLoad event handler for img tag. All tutorials just teach you body tags onLoad event handler.

Then, since we are handling multiple images, you have to pass in the image reference to repeat calls of function to change the alpha of the image. here
setTimeout("function_to_change_alpha("+img+")",interval); 
doesnt work. (for reasons beyond my comprehension about javascript quirks.)
the rightway to do it is, by using closure:
setTimeout(function() {function_to_change_alpha(img);}, interval);

For unknown reasons, i couldn't read the opacity property of the object (image) thus passed.
mOpacity = obj.style.opacity; didn't work.
I had to pass in the current opacity value also, to the function and increment it in the function.

Thus, the final version of the function was:

fadeimage = function (obj, opc) {
 if (opc==undefined) opc=0;
 opc += 0.1;
 obj.style.opacity = opc ;
 if (opc<1){
  setTimeout(function() {fadeimage(obj,opc);},300);
 }
}

I used a php script to dynamically load images in a directory, and assign it's filenames as captions to the images, and assign the above fade-in function to images' onload event.

if (!$dir=opendir("photos")) echo "could not open dir" ;
while ( ($file = readdir($dir)) != false ) {
  if (preg_match ("/.jpg$/i",$file)) {
    $name = $file;
    $name = preg_replace("/.jpg/","",$name);
    $name = preg_replace('/\b(\w)/e', 'strtoupper("$1")', $name);
    
    if ($row ==0) echo "<tr>";
    echo '<td> <img src="photos/'.$file.'" class="fadinimage" onLoad="fadeimage(this);"><br><center>'.$name.'</center></td>';
    $row ++;
    if ($row==2 ) {
      echo "</tr>";
      $row =0;
    }
  }
}

and finally set the alpha of the .fadeimage class to 0 in the css file.

here's the final site:


http://midtownpayyanur.orgfree.com/photos.php

Thursday, February 24, 2011

Paithalmala trip


we had a marvelous trip to Paithalmala, along with Taliparamba Lions club on Feb 19,20. our stay was arranged at Vaithalmala resorts. had a camp fire there on 19th eve.
on 20th we set out to the peak. It was not as tedious, and all members made it easily. we had tapioka biriyani (arranged by the resort) at the pea...k. we were back at resort for lunch, which was a sumptuous kerala meal.
 



Tuesday, February 8, 2011

How to print an online marriage/death/birth certificate in KERALA

The govt of Kerala has made it easy to register the birth/death/marriage events (it takes only few minutes !!) and then obtain a hard copy of the certificate at the convenience, sitting at your home. Its 'information Kerala Mission' makes this possible.


to obtain the cirtificate:

1. visit www.cr.lsgkerala.gov.in
2. click on 'registration search'
3. select the municipality
4. select Birth/Death/Marriage from left side Menu
5. Fill the right side form with details
6. click on 'Search'
7. click on 'View' button
8. click on 'Print'

Wednesday, February 2, 2011

BSNL GPRS settings

had lot of trouble setting up bsnl gprs settings on my android. there are confusing settings given in bsnl and other websites.  but in the end, it turned out to be very simple.

    Connection Name = bnslnet(or anything)
    Data Bearer          = GPRS
    Access point name       = bsnlnet 
    User Name = none
    Password = No

dont enter anything in user name field, but in the password field, enter "No". 

I also installed APNdroid, which lets me switch gprs on and off.




http://nxwiki.blogspot.com/2010/04/bsnl-gprs-settings-for-nokia.html