Saturday, July 18, 2009

Thumbnail generation algorithm with out losing image aspect ratio

Referred many thumbnail generation algorithms, but many were about to crop most of the available screen area, if the image to be thumbnail'ed is not aligned with the image's aspect ratio.

Algorithm that I figured out to save more area of the original image is:
Assume the thumbnail dimension should be x':y'.
1. Load the image and get original width(w) and hieght(h).
2. Scale the image to X:Y, such that:
a. if h > w, Y = h * aspect_ratio, X=w
b. if h < w, X = w * aspect_ratio, Y=h
3. Crop the scaled image to x':y' calculating the area from center of the picture.

GdkPixbuf functions used for implementing this algorithms are:
gdk_pixbuf_new_from_file(),
gdk_pixbuf_get_width(),
gdk_pixbuf_get_height(),
gdk_pixbuf_scale_simple(),
gdk_pixbuf_new(),
gdk_pixbuf_copy_area()

strcasestr()

The strcasestr() function is defined in libc on '2.6.24-16-generic #1 SMP Thu Apr 10 13:23:42 UTC 2008 i686 GNU/Linux' machine is defined as:
$nm -AC /usr/lib/libc.*|grep strcasestr
/usr/lib/libc.a:strcasestr.o:00000000 W strcasestr
flag 'W' means weakly defined. If it is linked with normal code without defining the function(), compiler error is observed saying 'strcasestr() undefined'. The function's declaration could be found in . To avoid compilation error, I have written my own strcasestr() function, but altered the expected functionality of the function to suit my requirement.

I need to compare whether a given string is a sub-string(case-insensitive) of the given string. But the string could be found only at the word begining. The code fragment for the strcasestr() is pasted below.

static gchar* my_strcasestr(gchar *source, gchar *target) {
gushort i = 0, len = 0; /* assuming search string length won't be greater than sizeof(gushort) */
guchar after_space = 1;

len = strlen(target);
for (; source[i] != '\0'; i++) {

if(!after_space && source[i] != ' ')
continue;
if(source[i] == ' ') {
after_space = 1;
continue;
}
after_space = 0;
if(!strncasecmp((source+i), target, len))
return (source+i);
}
return NULL;
}
If there is any better way of doing this, pls let me know.

Thursday, November 08, 2007

ntde1ect.com, a big headache

Recently, my system was threaten by one more virus, ntde1ect.com, which spreads through the usb drives(pendrive).

It seems this virus is very intelligent one and it corrupts even the system files 'ntdetect.com' and 'ntldr'.

the associated files coming with this virus are:
ntde1ect.com,
autorun.inf,
avpo.exe,
avp0.exe,
avp0.dll, and
a directory with name hashxxx, containing scripts to block orkut and youtube sites, usually located only on 'drive with label C'.
Indication to find out this virus is, when open a drive, its opening in a new window instead of in the same window. This might be because of autorun.inf.

We may find the instances of ntde1ect.com and autorun.inf in all the root directories of the partitions.

Another indication is we are not able to change the option of show hidden files option.

To remove this virus, no other way except booting the system in recover mode.

After booting the system in recover mode, switch on to respective partitions and try remove all the said files in partition's root directory and in /windows/system32 directory.

One important thing is to change the attributes of these files to readable format using 'attrib'.
ex:
c:/>attrib -r ntde1ect.com
will take out the 'no read' restriction on the files, so that we can delete.

Then have to remove the traces of this virus(avp0.exe, ntde1ect.com, ...) in regedit.

Tuesday, July 17, 2007

XML Talk@twincling


On Last saturday(14th of july), i gave a talk on XML and technologies in Twincling society whose motive is to develop and promote open source software products. You can find the slides here. The session went very good as the response from audience and i covered xml, dtd, schema and namcespaces. But the other technologies like xpath, xlink, xslt, etc are not able to covered due to time limitation. My special thanks to Saifi, Sumit, Namita Iyer and other active members of twincling society to give me an opportunity to share my knowledge.

You can find more information on twincling society here.

Tuesday, July 03, 2007

guruji.com

I heard about this search engine company many days back. Yesterday they have started a contest " search and win". I played the contest my referral link is here.

But i didn't get the idea behind this contest. Do they want to show off their product to the outer world? I still feel that Its relatively impossible to find accurate data particularly for indian(or any country) content. They may have taken assumptions based on geographic, IP based, or content related, or what ever it may be... there is no proper way to categorize the data that its belonging to particular place. A person working in Canada( born and bought up in India) may want to write his daily musings/happenings may be in canada or india or what ever he wants. I am still wondering how many of users would be interested in to search for India related content (especially in this globalized world).

Update:
I won a T-Shirt playing on this contest. Thanks to guruji.com team.

Monday, February 26, 2007

This is how i get free access to ACM Portal, A Security Hole

Yes, its true! I got free access to ACM Portal from a network which is not subscribed. This Portal will allow us to view the abstract of desired paper. But if we want to download the paper we must either have membership account with ACM or our network must be subscribed as most of the educational organizations do. Failing the 2 options we cant get access to download the paper(through the acm portal).

Till now, me and my friends have an illusion that the requests are tracked based on the IP address and if the IP address is not in the subscription list, it would be treated as normal request. But it may not be true. When I type a paper title in google search and selects a result link which is targeted to acm portal, i can get access to the acm portal page as a genuine user from Google, Inc, and can download the desired paper. It gives us full access as a subscribed user. I tested with Firefox and Konqueror browsers and friends working in other companies are tested on windows IE as well. Its only possible with google search, but not with other search engines like Yahoo Search, ASk.

Observe some of the screenshots I got through while experimenting. Sometimes its showing Google,Inc; sometimes CILEA Consortium; and sometimes FUJITSU Ltd. I guess its a security hole. And one more thing is that the search result must contain CFID and CFTOKEN. May be these two attributes are the driving factors for me to get access. Try the Sample search. Select the result which is pointing to acm portal (It would be in the first 10 entries). When i search for those two variables, i came to know that CFID and CFTOKEN are the ColdFusion session variables. They are used to track the user's browser session. By default, all ColdFusion versions write CFID and CFTOKEN as persistent cookies in the client browser. An important security note is: Coding sensitive data such asCFID and CFTOKEN in the URL string is a security risk. Even though they are designed as per-session cookies, its still possible for us to access with Google search.

I am still wondering why its only possible with Google Search and not with any other search engines. May be I need to dig into ColdFusion programming.

Update:
Seems Google Search is not providing such results. But this link would directly allow you to access acm portal under the 'Google Inc' network. The reason is, as i said earlier, the query result should include the CFID and CFTOKEN arguments.

Monday, February 05, 2007

Am i a Dreamer????

Am i a dreamer???, as the title of this post asks, i came across this questions many times, but i eventually supressed that thought upon doing the things and converting my self into a do-er, rather than dreamer.
Few days back, i been to read an article in Times of India, a survey that dwells about the qualities of planner / do-er/ dreamer. According to the survey, a Planner is one who like to have everything in order and spend hours before making decision. A Doer is one who takes the things as they come into and go ahead. But a Dreamer is one who do more planning than doing. The dreamer is one who spent much of his time planning, rather to fail (or lag) at implementation, and a bit idealist and want things to be done perfectly.

But my conception of Dreamer is one who can think of an idea, and plan it for implementation (i mean, a perfect plan), and go ahead with it. A dreamer can only lead the world!. A goal is a dream with a deadline, according to the author, An idea without at least some element of absurdity is not worth further consideration. Small businesses don't grow bigger without a dreamer, planner, risk taker, and doer. Enterprenuer is one who is more a dreamer in addition who can plan, take risks and implement. Today world is renovating more with dreamers, so the start-up boom. Without Dreams, you can not set a goal, without goal, you cannot plan, without plan, you cannot control, and without control you cannot manage either yourself or others. So i continue dreaming...!

Sunday, February 04, 2007

temp2.exe (irc.momma worm) - How i got to remove it successfully

temp2.exe and/or temp1.exe, both these two viruses irritated me for some time yesterday. While i was copying some files using flash drive, my machine got to threaten of this virus. Some anti viruses treated it as worm, though it harms seriously. Mainly it deteriorates the data flow. So its related to network security. I clearly came to evidence that temp2.exe and temp1.exe are running on my system and until i ended them, i cant be able to detach the removable devices. In addition, when i tried to open other windows partitions, they are opened as new window, even though i havnt used that option. I addition it adds autorun option in the context menu explorer.

When i digg into the details, i came to know much about the virus, how its working, and all. If we are copying from infected machine, this virus puts three files along with the data into the disk.
They are: copy.exe, host.exe and autorun.inf
autorun.inf file contains only two lines.
[autorun]
open=copy.exe
when we open the infected disk, autorun will invokes and virus starts acting by running the copy.exe file. It creates a dump of above three files in root directory of each partition and make a copy of copy.exe in system32 directory. Also a copy of temp1.exe and temp2.exe wlould be kept in system32. Along with it corrupts the xcopy.exe and svchost.exe files in system32.exe. It also kept registry entry.

Steps to remove the virus:

So to remove the virus one has to be careful. First off the system restore monitoring. Then delete the three-files from root directory of each partition. Also remove copy.exe, xcopy.exe, temp1.exe, temp2.exe and svchost.exe from system32 directory. And the remaining is deleting the entries in registry. So to do that search in the registry for each of the file entries and manually delete them. After that restart your machine. So u will be out of that little dragon. a old copy of svchost.exe and xcopy.exe will be written back into your machine.

To check whether the virus got cleared or not, by observing the file properties of these two files. They must indicate the company info as 'Microsoft Corporation...'. If they are not from microsoft corporation, and anything which are residing in system32 directory must be from microsoft, else u can suspect of a malicious entry. After successful removal of the virus, u can continue by checking the system restore monitoring.

Monday, December 18, 2006

Another humorous cartoon from Sridhar

నిన్ను మెడిసిన్ చదివించాను, నా ఆస్తిపాస్తులన్నీ ఇచ్చాను, చక్కటి పిల్లను తెచ్చి పెళ్లి చేశాను, రాజకీయంగా కూడా నిలబెట్టాను.
నన్నెందుకురా బద్నాం చేస్తావు.......

Friday, November 24, 2006

Dynamic Memory Allocation in C, C++ - my strange experiences with gcc and g++

Yesterday i learnt few strange things about malloc() in C and new, delete operators in C++.
Compiler referred is gcc for C, and g++ for C++ programs.

First one:
int *a=malloc(sizeof(int) *0); //i am trying to allocate 0 bytes of memory and pointing that location with pointer a.
==> What should happen, Segmentation fault( run time error) , since allocating 0 bytes of memory is absurd and then referencing it through a pointer a is too wrong. It went through compilation and run perfectly on 'dereferencing' as a[0]=5, a[1]=2,... .
==> But i get segfault when i am trying to allocate -ve bytes of memory.

Second one:
int *a= new int[0];
==> the same effect with 0 size memory allocation and runtime error when trying to allocate (-ve)size of memory.

Third one:
This one, i strongly beleive that it sould raise runtime error, as it is mentioned in C++ standards.
int* a=new int[10];
......
delete a; //Here it should be delete[] a;
==> When an array of objects are created with new operator, while deleting all objects, we should use delete[], instead of delete; since delete will only delete that object.

Fourth one:
Do you think that on freeing or deleting the dynamic memory, the contents/memory locations will be deleted permanantly? No, it shouldn't be. The compiler will just cut of those associated links and the memory locations still with the content that we have assigned. If u want to try, assign the locations to other pointer before freeing/deleting.
My experience is:
int *a=malloc(sizeof(int)*4);
a[0]=1;a[1]=2;a[2]=3;a[3]=4;
int *t;
t=a;
free(a);
printf("%d , %d , %d , %d ",t[0],t[1],t[2],t[3]);
//Answer is "0 , 2 , 3 , 4"

int *a=new int[4];
a[0]=1;a[1]=2;a[2]=3;a[3]=4;
int *t;
t=a;
delete(a);
printf("%d , %d , %d , %d ",t[0],t[1],t[2],t[3]);

//Answer is "0 , 2 , 3 , 4"

==> I am not able to figure out the logic behind making the value of base address to 0 upon deleting. If it is to make value of deleted location as '0', then it should be with all the locations that are dynamically created. But it isn't. And also one more thing is 'write' operation is more costly than delinking.

Your comments are appreciated, if you have proper reasons.