Monthly Archives: January 2008

Bringing A Marker To The Top

In maps and charts, where there are several markers, there is a likelihood of a overlap depending on how dense the data is. In such cases, it would be good to be able to bring the marker that has been selected using the mouse to the top and display the details and push the rest of the neighboring points to the bottom. And then when a mouse is placed over one of those neighboring points, then the current point should go down and the other point should come up.

So, how to achieve this in HTML using Javascript? Below is a way to do this.

Say each marker is a div element. You can do the following. First have a depth variable.

var depth = 1001;

Now, have the following code for the div.

div.onmouseover = function(event) { = depth++; }

That’s it! What this does is, every time the mouse is placed over a div, it sets it’s depth to be one more than the current maximum depth ensuring that the element is the top-most element. Isn’t this simple and elegant?

Leave a comment

Filed under DHTML, javascript, Maps

Vote No For Aggressive Viral Marketing

I received an invitation to, a website trying to reshape the job market. I don’t have a problem with them trying to reshape the way we fundamentally have been doing things. What really annoyed me though is the fact that, even if I don’t want to be part of this network, some other friend of mine (and many others who I have never met in life but ended up my linkedin links and I wish I could upgrade/downgrade my links) can import all of his linkedin contacts so that gets access to my information, without my permission! And why would anyone want to import their trusted friends list to So that they could earn 10% of what their friends earn by interviewing for the first one year. While I may certainly have a few good friends who won’t be tempted to giving away my information for that kind of a deal, I can’t trust everyone to have the same level of aversion towards this kind of practices.

Based on recent news about Plaxo mining data from LinkedIn in a similar fashion, I don’t know if there is a fundamental flaw in LinkedIn that is exposing the data or if that’s inevitable. The real problem is, unlike most security issues where there are 2 or 3 parties involved, in this there are 4 parties. LinkedIn, NotchUp, my link on LinkedIn and there is me. If the first three are doing things knowingly/unknowingly that gives them access to my information, however little that might be, without my consent, then forget Open Social. I value privacy more than portability.


Filed under linkedin, NotchUp, Open Social, Plaxo, Viral Marketing

User Input Sanitizing Before Using In Regular Expression

Say you want to take the input from a user and filter any set of text (titles/descriptions) and show the reduced list to the user. Assuming the users are not sophisticated enough to write regular expressions, the requirement is simply to ensure that whatever the user typed in is available some where within the text.

A simple way to do this is just look for the exact substring and see if the index is greater than or equal to 0 (something like str.indexOf(input) >= 0).

Say, you want to return a match that is case-insensitive. Then the substring approach will not work. So, you need to jump to using regular expressions. In JavaScript, this would become,

var re = new RegExp(input,"i"); // the flag i indicates case insensitive
if(re.test(str)) { /* do-some-thing-here */ }

So far, so good. Now, what happens if the user types in some special characters that are typically used in regular expressions as some special control characters? For example,

‘(‘ and ‘)’ are used for grouping and variable capturing
‘[‘ and ‘]’ are used for character set
‘{‘ and ‘}’ are used to indicate the cardinality
‘\’ is escape character
‘*’ is used to indicate 0 or more
‘+’ is used to indicate 1 or more
‘?’ is used to indicate 0 or 1

In this scenario, if someone types in a string with any of the above characters, then the above javascript will fail. So, in order to fix this, the user input string should be first fixed to make it a valid regular expression. This can be done using

var rere = new RegExp("[({[^$*+?\\\]})]","g"); /* you need 2 '\' s to mean 1 '\' and another '\' to treat ']' as special character instead of the characters ending bracket */
var reinput = input.replace(rere,"\\$1"); /* replace the special characters with a \ before them */
var re = new RegExp(reinput,"i");
if(re.test(str)) { ... }

Now if you are generating the above JavaScript code in perl, it gets a bit more complicated. Why? Because, ‘\’s are themselves have escape semantics. Also, $ symbol has special meaning in perl. So, for each ‘\’ above, it would be doubled and also, $ would be escaped as well.

Yes, it gets confusing, but it’s doable. You can see this in action at Flat Panel Plasma/LCD HDTVs. It contains a search box on the top of the image cloud and lets the user to input a string such as Panasonic, Samsung, Sony etc or even product numbers with special characters like TH-42PZ700U to find the corresponding product on the image.

Leave a comment

Filed under javascript, perl, regular expressions, Tech - Tips

PageRank Drop

My blog pagerank dropped from 5 to 4 with the recent update. I wonder why.

Leave a comment

Filed under pagerank