Mozilla Plugin Development

February 19th, 2008 by Sajith M.R

Moizlla Plugin Development

Steps to create a mozilla plugin>

1) You need Mozilla Firefox Web Browser (Download from: http://www.mozilla.com/en-US/)

2) Initail steps for a Hello World program is here : http://developer.mozilla.org/en/docs/Building_an_Extension

The package is zip file saved with xpi ( pronounced as zippi ). And the Interfacing language is called XUL

You can edit and test your xul templating using this url: http://ted.mielczarek.org/code/mozilla/xuledit/xuledit.xul

The Browser itself written in XUL format. Its basic structure is called XUL Overlay. We can override any part of that overlay with id. (See: http://developer.mozilla.org/en/docs/XUL_Overlays)

This is how different plugin’s are integrated with already existing mozilla browser. You can Override, Expand, or add separate window for your application.

Since the usage of desktop application are increasing and the need of javascript have more significant nowadays ( Ajax, Flash, Flex, Adobe Air) , We should follow client side developments.

If XUL is for templating , Javascript is action creator here. You can write your code in javascript.

After creating your application , you can showcase it on firefox extension folder. They put your code in sandbox. After testing, if it is an useful one, they will add it to their public package listing so that
everybody can access you extension.

So start your Hello World Application with Mozilla Plugin NOW .

Feel free to contact me in: admin@sajithmr.com or D@OLPH.IN

Dynamic Function Calling in PHP

February 8th, 2008 by Sajith M.R

Dynamic Function Calling in PHP Dynamic Function Calling in PHP

Why php is more flexible ? See this function example:

Class Record

{

public function getMessage()

{

return "Hello world";

}
}

//You can call this function like this:

$function = "getMessage";

$R = new Record;

call_user_func( array($R, $function   )  );

If you want to pass some argument , you can use rest of the parameters of call-user_function;

eg: call_user_func( array($R, $function ) , $param, $param2);

For more info: http://www.php.net/call_user_func

Mount NTFS File System in Ubuntu (debian)

February 6th, 2008 by Sajith M.R

NTFS in UBUNTU

Steps:

1) sudo apt-get install ntfs-3g

Installs ntfs-3g library
2) sudo fdisk -l

Shows all the disk drives
3) sudo mkdir /media/windowsC

Create a directory for mounting your NTFS file system

Ubuntu logo
4) sudo cp /etc/fstab /etc/fstab.bak

Take a backup of old conf file

5) gksudo gedit /etc/fstab

Edit the configuration file

6) /dev/sda2 /media/windowsC ntfs-3g defaults,locale=en_US.utf8 0 0

Add the above line to the end of that file. (Here sda2 is the ntfs partition, getting from fdisk -l )

Restart ubuntu and you can see the ntfs filesystem mounted on /media/windowsC

Symfony (Propel) Pagination on Multiple Tables

February 1st, 2008 by Sajith M.R

If you are a symfony programmer, just read this. Otherwise you can skip this topic. We all know that one of the useful thing in every website creation is the pagination. Symfony uses propel pagination for showing database records page by page.

But suppose the case of showing records from different table . You cannot use normal pager class of propel to show the results form multiple table. For that purpose you need to get the results as result set and have to create custom pagination by adding setLimit to the criteria.

But when i develop mobshare search page, the requirement is that when a key or pattern is search , the first page needed to contain all the results, means mixed results from photos, videos and users. But the data are stored in three different tables : Photos , Videos and Users.

So i created a turing machine like structure. Its geographical structure is like three tapes aligned in parellel and a head and level tracker read the data from these three tapes simultaneously . These tapes represents each pager. Head is the reader and level indicates which tape is currently reading . These tapes are arrange in small to high manner in the order of number of results of each pager.

Propel multiple pager

Click read more:

Read More »

PHP time ago calculation

February 1st, 2008 by Sajith M.R

time ago

The new web 2.0 displays time and date not in old style manner like 12.30 pm Jan 200 7. The new generation need relative time like 2 hours ago, 6 months ago, 4 years ago, very old etc. So if you save the timestamp of a particular content creation in database we can simply show this ‘ago time calculation’ using the following algorithm.

//$datefrom is the timestamp for the content , and you can leave the $dateto value to see the current delay

function TimeAgo($datefrom,$dateto=-1)
{
// Defaults and assume if 0 is passed in that
// its an error rather than the epoch

if($datefrom<=0) { return "A long time ago"; }
if($dateto==-1) { $dateto = time(); }

// Calculate the difference in seconds betweeen
// the two timestamps

$difference = $dateto - $datefrom;

// If difference is less than 60 seconds,
// seconds is a good interval of choice

if($difference < 60)
{
$interval = "s";
}

// If difference is between 60 seconds and
// 60 minutes, minutes is a good interval
elseif($difference >= 60 && $difference<60*60)
{
$interval = "n";
}

// If difference is between 1 hour and 24 hours
// hours is a good interval
elseif($difference >= 60*60 && $difference<60*60*24)
{
$interval = "h";
}

// If difference is between 1 day and 7 days
// days is a good interval
elseif($difference >= 60*60*24 && $difference<60*60*24*7)
{
$interval = "d";
}

// If difference is between 1 week and 30 days
// weeks is a good interval
elseif($difference >= 60*60*24*7 && $difference <
60*60*24*30)
{
$interval = "ww";
}

// If difference is between 30 days and 365 days
// months is a good interval, again, the same thing
// applies, if the 29th February happens to exist
// between your 2 dates, the function will return
// the 'incorrect' value for a day
elseif($difference >= 60*60*24*30 && $difference <
60*60*24*365)
{
$interval = "m";
}

// If difference is greater than or equal to 365
// days, return year. This will be incorrect if
// for example, you call the function on the 28th April
// 2008 passing in 29th April 2007. It will return
// 1 year ago when in actual fact (yawn!) not quite
// a year has gone by
elseif($difference >= 60*60*24*365)
{
$interval = “y”;
}

// Based on the interval, determine the
// number of units between the two dates
// From this point on, you would be hard
// pushed telling the difference between
// this function and DateDiff. If the $datediff
// returned is 1, be sure to return the singular
// of the unit, e.g. ‘day’ rather ‘days’

switch($interval)
{
case “m”:
$months_difference = floor($difference / 60 / 60 / 24 /
29);
while (mktime(date(”H”, $datefrom), date(”i”, $datefrom),
date(”s”, $datefrom), date(”n”, $datefrom)+($months_difference),
date(”j”, $dateto), date(”Y”, $datefrom)) < $dateto)
{
$months_difference++;
}
$datediff = $months_difference;

// We need this in here because it is possible
// to have an 'm' interval and a months
// difference of 12 because we are using 29 days
// in a month

if($datediff==12)
{
$datediff--;
}

$res = ($datediff==1) ? "$datediff month ago" : "$datediff
months ago";
break;

case "y":
$datediff = floor($difference / 60 / 60 / 24 / 365);
$res = ($datediff==1) ? "$datediff year ago" : "$datediff
years ago";
break;

case "d":
$datediff = floor($difference / 60 / 60 / 24);
$res = ($datediff==1) ? "$datediff day ago" : "$datediff
days ago";
break;

case "ww":
$datediff = floor($difference / 60 / 60 / 24 / 7);
$res = ($datediff==1) ? "$datediff week ago" : "$datediff
weeks ago";
break;

case "h":
$datediff = floor($difference / 60 / 60);
$res = ($datediff==1) ? "$datediff hour ago" : "$datediff
hours ago";
break;

case "n":
$datediff = floor($difference / 60);
$res = ($datediff==1) ? "$datediff minute ago" :
"$datediff minutes ago";
break;

case "s":
$datediff = $difference;
$res = ($datediff==1) ? "$datediff second ago" :
"$datediff seconds ago";
break;
}
return $res;
}

PEAR - MIME Mail

February 1st, 2008 by Sajith M.R

When you send mail from php code, you use mail() function for this purpose. Here is another library from PEAR for sending MIME mails including html mails, attachments, inline picture attachment , plain text mail etc.

The steps to install this library is :

pear install http://download.pear.php.net/package/Mail_Mime-1.5.2.tgz
pear install Mail

(you need a pre-installed PEAR library)

From the php code you can create a function for sending mails

public function sendMail($Content,$to,$subject,$from=’no-reply@mysite.com’, $type=’html’,$attachment=false )
{
require_once (”Mail.php”);
require_once (”Mail/mime.php”);

$crlf = “\n”;
$hdrs = array(
           ‘From’ => $from,
            ‘Subject’ => $subject
            );

$mime = new Mail_mime($crlf);

if($type== ‘html’)
     $mime->setHTMLBody($Content); // html content
else
     $mime->setTXTBody($Content); // test content

//you can pass $attachment as array of file paths
if($attachment)
  foreach($attachment as $file)
      $mime->addAttachment($file, ‘image/jpeg’);

//do not ever try to call these lines in reverse order
$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory(’mail’);
$mail->send($to, $hdrs, $body);
}

You can use this link for another example: http://pear.php.net/manual/en/package.mail.mail-mime.example.php

For more examples go : http://pear.php.net/manual/en/package.mail.mail-mime.php

Cetera Algorithm

February 1st, 2008 by Sajith M.R

cetera Brain

3d Sound

New sound algorithm to create 3d effects in sound. You are femiliar with sterio, 5.1 surround etc things. But hear this mp3 using your head phones (head phone is a must). http://www.sajithmr.com/downloads/Barbershop.mp3

From this mp3 , you will get the feeling of a barber shop, and you are setting on the chair. If this mp3 makes you crazy ,it is nothing but cetera algorithm.

Starkey’s Cetera technology makes the hearing aid “invisible” to the brain. Cetera removes the barrier between sound and the brain’s ability to process signals. The Cetera technology is based on an innovative new algorithm- the complex mathematical formula that drives a hearing aid. Cetera’s algorithm can match the exact characteristics of the wearer’s ear. This customization removes the barrier that most hearing aids erect between the incoming sound waves and the data sent to the brain for processing.

See this link for more : http://www.audiologyonline.com/news/news_detail.asp?news_id=6

Cetera Algorithm

Here is the full dialogs of this virtual barber shop:

Manuel - Hello there!Hello there!How are you?Yes, yes…You are here for the virtual haircut? yes, yes…ok… I will go and get Luigi.He will come and cut your hair… I’m Manuel, just stay right there.
Manuel - Luigi? (knock-knock) Oh Luigi? he’s present here for your virtual haircut. You’d better come up…..
Luigi - Grazie* Manuel, I’m coming right now.

Manuel - He’s coming up right now and me I’ll go over here and play music, play the guittar because that’s what I do here at the barbershop.

Luigi - Ah, it’s so nice to see you.Welcome to the Starkey Cetera Barbershop and our virtual haircut. I’d like to start the demonstration by moving over to your right hand side and picking up this bag. If you just hold still for a second I’ll put this bag over your head! Just like that..The bag over the top of the head…

And now, I’ll take the bag off. There we go.

The only reason I did that it’s because all of the fancy barbershop do that.

What you’re listening to is I move to your right here and very quickly wash my hands

Trimmmm-Trimmm (the phone is ring) Manuueeellll could you get that please? Oh, thank you Manuel. Let me finish washing my hands here… just bear with a few more seconds.
Ah, yes… As I was saying, all we are doing is using your head as the listening point… and we have two microphones one on either side of the head, in the same position as where your left and your right ears are.

Your brain is doing all of the work, telling you where the sounds are coming from… ok…I’ll go and get the scissors… Nice sharp

And now as I begin the clipping and I bring the clip close to your ear, very close to the right ear…folow me as I move around the back of the head… to the left ear…and up over the top of the head…okay. Now, you can get the same effect better with the eletric razer, I’ll first bring it to your right ear…And around the back… and on your left. I think that looks wonderful. Manuel, what do you think?

Manuel - Ah? Yes..Ah, yes…It looks wonderful Luigi!You do such nice work

Luigi - Oh, thank you so much Manuel.

Manuel - So fast too.

Luigi - Now, as I walk around I just want to tell you only once more that your ability to hear where I am as I walk around the room is simply the amazing power of your brain, calculating the tinny differences or cues in sound intensity and arrival time from two open ears and unlike any other hearing instrument, only one has the digital algorithm that negates on physical presence in the ear to fully restore those differences.
And that algorithm is called… CETERA.

Oh, thank you, thank you so much for stopping by the Starkey Virtual barbershop

Good bye and arrivederte*

Okay … Some more virtual mp3s

http://www.sajithmr.com/downloads/phon.mp3

http://www.sajithmr.com/downloads/voce.mp3 (sexy girl)

I will let you know when more 3D sounds are published:

Enter your email address: