Friday, March 28, 2008

Unidentifiable error

Came across an interesting error while starting with script.aculo.us A test code was working fine. I moved the same script to the real project code. Then the script started throwing error, 'undefined object'. Spent lot of time in comparing the test code and actual one. Couldn't find any issue.

Then placed few alert statements and narrowed down the issue by applying divide n conquer. What caught was this function :
function $(id){return document.getElementById(id)}

Seems like scriptaculous.js is using prototype.js and the later is defining a function with the same signature as above. After going thru the function defined in prototype.js, I found that to be sophisticated and served my requirement too. I commented my definition and the page flies through without error.

Moral : don't duplicate function names, it is going to be lot difficult to debug.

Wednesday, March 26, 2008

Languages and dialects

I was wondering why we have so many languages in the world. Some ancient, dead and few started recently, growing; some have written form and some dont ..

It is understandable if different languages spurn out at isolated geographical locations. However we see that many languages and dialects co-exist at a close region. One possibility could be that the people migrated and carried their language to an area where people had their own language.

There seems to be more to the story. Looks like socio-economic-political motives might have driven people to create languages. For eg, in a business environment, it is a great advantage for the salesperson to use some secret code words to discuss in front of the customer. Also, a language and a dialect could establish an identity of the customer and hence favor discounts.

Around the world, we are politically charged by emotions. We create artificial borders. These emotions are mainly based on faith or language.

In order to demark the dividing factors among human being, I would love to drop all languages and adapt a single universal language. When people start seeing language as a tool to communicate and not an emotional toy, then we may achieve this idealistic world.

Friday, March 21, 2008

Ladies finger fry

Here is my recipe for preparing deep fried ladies finger.



My wife had cut the vegetable, onions. She started with the initial ceremony of frying mustard and cummin seed in oil. Added onion and stirred them for some time. Once the onion turns light golden color, she put the pieces of ladies finger into the pan. She kept stirring and added little bit of salt, chili powder and garam masala. After mixing these, she stopped at this point.



I took over the control. Kept stirring further. Added some more garam masala for extra taste. While I was stirring this, my wife started shouting that I am spoiling the vegetable. You need to focus on the stove and the preparation. The vegetable and onion combination will become red (just like her face). Go little more so that it is light brownish green and tastes slightly crispy.



Ah, it is an wonderful dish. If you can get it right, your wife would envy about your culinary skills.

When matrimonial sites go down

We know that the successful matrimonial sites are minting money through all means. What happens to sites that are not so successful? Still they manage to pull enough traffic to their site. May be the same type of users may not login. The sites are creative to utilize their resources and spin off a totally new pages that amuses the new customers. What resources they have and how do they use? They got a bunch of photos from matrimonial profiles. Since the site doesn't need them anymore, they allow users to vote on those photos! Sample this

Tuesday, March 18, 2008

Seller's view

When the customers' needs are like this, salesperson perspective are very much aligned. While I was living in the city, I thought of preserving the cloth from insects and dampness. Had to buy some naphthalene for placing in the closet. The near by general store was handy and I approached the shopkeeper. He was in his twenties. He was not the owner, should be a relative of the owner.

I asked him for the naphthalene balls and he showed some local branded one. The white balls were neatly arranged in a plastic sheet and tightly wrapped. A piece of paper announced the local brand name. He was trying to push this piece to me. However, I wanted to compare the price of this packed one and loosely kept naphthalenes. They were placed inside a bottle and he had to weigh any amount I would like to get. That was 50% cheaper than the packed one. I am sure he will get a better deal by selling the packed one than the loose one.

He was trying his sales pitch for the packed one. He commented on the quality, intactness etc. However, I was not convinced that I should spend more money for providing better repellents for the insects. Finally I asked him to weigh the loose ones. He did that, put them into a small paper bag. He liked the smell of the naphthalene. While handling the bag to me, he asked, "what is the purpose of these?"!!!

Monday, March 17, 2008

Gadget for the railways

There is a nice neon board displayed inside the train compartments. The location of the train is constantly displayed. It is very useful to know the approaching station, the distance and the time etc.

It would be nice to extend this facility. How about having a personal alarm when desired station approaches? Like, we set our mobile phone with the city code. The display board keeps sending mobile recognizable signals for each approaching stations. If the station code is same as the one I had set in my mobile, my mobile will wake me with an alarm.

This system needs a download to install in the mobile and the announcement signal to reach the mobiles.

Just a thought occurred in between the sleeps.

Wednesday, March 12, 2008

Mil and dil

Had a chance to know a little bit about the mil and dil equilibrium. My wife prepared potato curry and while having it, she asked what is the better way of preparing the dish. As I know only my mom's way of making it, I suggested my wife to check with my mom.

Ah .. that was the trigger for 30 mins rainfall. All the incidents, events, discussions, dialogs that happened from prior marriage upto now .. that is about 2 yrs of packed drama replayed again at our living room. My wife gave her interpretation of the whole sequence and also as a complimentary, highlighted what could have been others' motive in the game.

That was quite an experience. Not that everything was bad in the 30 mins time. I gained something value. First is patience. And the other is a discovery of a hot button that shouldn't be pressed.

Sunday, March 09, 2008

Bad dreams

It was a lazy, fine Sunday morning. One could feel the freshness, the slow change in color & hue, the chirping of the birds, silence of the morning. It was a nice morning, except for a bad dream I had minutes ago. Still didn't come out the dream+sleep state. I looked at my wife who was still at sleep and about to get up. Slowly I woke her up.

It is our habit of narrating each other's dream. I started telling about the dream where I was chased by a man. While running, I saw my wife shopping on the road side. I pulled her and started running with her.

While talking about this dream, suddenly my wife's face turned pale. She was frightened to the core. I asked her if she is fine; she still couldn't speak. I got a glass of water for her (rare moments). After sipping it she slowly gained herself and with a shaky voice asked, if that was a fruit stall where she was standing by. It was a shock for me! Yes, indeed it was. The dream was etched into my mind and quite clear to play back.

Now she continued the narration. We both ran couple of streets and found ourself surrounded by goons. Yeap, just like movie style. They were pulling out weapons and that is the time I woke up. My wife also got the same dream and woke up at the same point.

What a coincidence! Can there be a meaning to it? Is this a prophecy? To be on a safer side, we thought of not going out for few days, particularly towards the market area. Even then we couldn't come out of spooky incident. Googling gave few cases reported by people but none was authenticate.

Luckily we have a neighbor who is a psychoanalyst. She is our family friend and we move along well. We checked when she will be free and thought of talking out with her. Once we met, we both explained our experience and sounded our concern with such freaky dream. We could see a smile coming out of her. She apologized for what she was trying out. As part of her research, she was working on a alpha ray generator. The project aims at studying the ray's influence on dream. Seems like she can play a particular frequency through the player she has and expect people to react within the range. As the concept is still under study, she didn't reveal more. I asked about the side-effects and health hazards. So far no complains ...

While coming back, I requested her to play some romantic frequencies here after.

PS: this is my first attempt on a short story :-)

Refined RGB color grouping logic

As I mentioned earlier, I had to group colors. I wrote a simple logic where I put zeros in the last n number bits of each color pigment of each color pixel. This gave the required result, but gave distorted colors.
In the quest of minimizing the distorting, I arrived at a better calculation. The line of thought is:
  • if we want to group colors together, we will have to mask the LSB bits of each color
  • Masking can be either making those choosing last n bits as all zeros or all ones
  • choosing either one of the above would lead to distortion
  • Instead of fixing the bits towards 0s or 1s, I tried to find a uniform number that could be placed at the last n bit.
  • This involves scanning all the red pigment of all the pixels. Add the last n bit values from these pixels and find average. Trim this average number to n bit size and paste this n bit at the end of all red pigment for all the pixel colors. Do this for green and blue as well.

After trying this approach, I got a better colors that were grouped together.

grouping the RGB colors

As I mentioned in the image handling utility, ChitraDeepam, I had to club colors together. The need arised due to the vast color range listed out of the given image; whereas the user was expecting to see few basic colors strikingly visible to human eye.

I was thinking about comparing the individual pigment of a particular color, (pigments => red, green, blue), and deciding which band of basic color it, (the given color), will fit into. However this was a complicated logic as we will end up into infinite comparison and may end up where we started.

A simpler logic occurred to me of masking the LSBs (least significant bits). User can have control over how many LSBs to mask. If I make those bits as zero, (for 3 of the pigment in each pixel color) then I am reducing the set of colors. This masking results in distortion of colors. As we are loosing few bits of data, we move from accurate image colors towards inaccurate colors.

Here is the code:

public Color trimColor(Color color, int accuracy)
{

// find the mask to be applied on color
int trimBar = (0xff << accuracy) & 0xff;


int red = color.getRed() & trimBar;
int green = color.getGreen() & trimBar;
int blue = color.getBlue() & trimBar;


return new Color(red, green, blue);
}


I am looking out for reducing the distortion and still achieving the color grouping. A friend had suggested to check with image processing utilities and libs. Seems like there are lots of possibilities for these minor features to have exists for ages. Let me go through.


Update: check the refined approach.

Saturday, March 08, 2008

Programming in local language

A professor at medical college requested me to write a small image processing application. He wanted to analyze any image and identify various color concentration and different ratios. I pitched in a java code that would read the bmp file and go thru pixel colors, count the rgb values etc.

Since the apps is a home-made, free-lanced small utility, I had lots of flexibility in scribbling to my heart's content. While doing so, I wanted to have convenient names for the classes and variables. I started using Indian words in coining class names.

I had to handle each color element and count their occurrences, manipulate the colors etc. The holder for such activities was named Varna which is color in Samskritam. The opposite color fetching function is from this class.
All colors from the image was extracted into a big double dimensional array. The huge volume of such colors prompted me to label it as VarnaSagar, ocean of colors.
A portion of image was handled at a time. So, I had to have some container which fetched colors from the VarnaSagar and processed them. The name for such small container is VarnaKalasam, pot of colors.
Even the screens were not spared. Image displaying modules and panels were termed Chitram, means a picture. The controls that open up the image is called by Darshan .. something to show up or see.



Would you like to guess the utility name? It is ChitraDeepam. Deepam is shine or light or glow. In our context, ChitraDeepam is a tool that illuminates more info about any chitram or image.


It was a nice experience to go thru in writing this utility. Using familiar names or related words made a lot of difference. It improved the way we conceptualize the problem domain. It also shows how powerful over native languages play even at a computer language level.

I remember few concepts I couldn't understand mainly because of the name. For eg, facet is one such topic. I never took time to understand the meaning of this word. Due to that I couldn't fully understand the topic, thou I attempted reading it couple of times. If I had known the meaning of the word, probably I might have been able to understand faster.

Anyway, here is the screen shot of the tool I wrote.

Wednesday, March 05, 2008

Customer needs

It was sunny morning. I was gazing at the empty road and watching petti activity happening at the small shop across the road. A tempo with tender coconut was unloading the coconuts into the shop. A driver and a teen age boy were handling the stuff and the shopkeeper was over-looking the download.

As the coconut looked fresh and nice, I thought of having one. Went to the shop, checked the price, and picked up a good one. Asked the boy if this one was tender and juicy, he affirmed. Sure, it was nice to drink.

The guys were done with their work and about to leave. The boy asked the shopkeeper, "Do you have Pepsi?"

Opposite color in the RGB palette

Recently I was working with a simple java code handling some colors. I had to display all the colors available in an image. I displayed the colors in the background and mentioned the color number as foreground. So, I got a beautiful rainbow of colors. The issue I faced is, to find the right foreground color for each item. I cannot fix a single color as the visibility will be affected when the background and foreground colors are same or similar.

Here I came across an interesting idea from the net, where the individual r,g,b components are bit-wise operated. Each of these three component numbers (ranging from 0 to 255) are toggled bitwise. A new color is formed and that will be complimentary to the original color.

This is what I wrote :


public static Color findOppositeColor(Color color)
{
if (color == null) return null;
int red = color.getRed();
red = findOppositeNumber(red);
int green = color.getGreen();
green = findOppositeNumber(green);
int blue = color.getBlue();
blue = findOppositeNumber(blue);
return new Color(red, green, blue);
}


public static int findOppositeNumber(int num)
{
// toggle the msb
return (num ^ 0x80) & 0xff;
}

Note: earlier I thought xoring all the bits is required, however I found that color #808080 failed to find the true opposite color as the xoring 0xff would return #7f7f7f, which is next color. Hence I had changed the logic to toggle only the most-significant-bit.