Thursday, October 29, 2009

Javascript/Firefox: context menu popup

Note: This solution has some side-effects. A better one is provided in my another post here.

The context menu of Firefox behaves differently between the Windows and Linux platform. On Linux, the context menu pops up as soon as you press down the right button of the mouse; While on Windows, it shows after you press down and release the right button.

We can change the Linux style behavior by doing a little hack.

1. Capture the mousedown event and suppress the context menu.

1.1 Capture the mousedown event

addEventListener("mousedown", myMouseDown, true);

function myMouseDown(event)
{
   if (2 == event.button)
   {
      // Capture the pop-up event of the context menu.
      addEventListener("popupshowing", myNoContextMenu, true);
   }
}
1.2 Suppress the context menu

function myNoContextMenu(event)
{
   // Prevent the default action, i.e. popping up
   event.preventDefault();

   // Remove the event handler because we don't want to mess up the
   // popupshowing events triggered by others.
   removeEventListener("popupshowing", myNoContextMenu, true);
}
2. Capture the mouseup event and pop up the context menu.

1.1 Capture the mouseup event

addEventListener("mouseup", myMouseUp, true);

function myMouseUp(event)
{
   if (2 == event.button)
   {
      myShowContextMenu(event);
   }
}
1.2 Pop up the context menu

function myShowContextMenu(event)
{
   if (navigator.platform == "Win32")
      return;  // on Window context menu is already shown on mouseup.

   document.popupNode = event.originalTarget;
   var cm = document.getElementById("contentAreaContextMenu");
   cm.openPopupAtScreen(event.screenX, event.screenY, true);

   // Cancel the event.
   event.preventDefault();
   event.stopPropagation();
}

Tuesday, October 27, 2009

Linux: search pattern in files

If you want to search a string (e.g. "TheString") or a pattern in all the files under the current directory, you know you can use:
        grep TheString *

It will not search the files under the sub-directories.

When I wanted to search all the files under each directories recursively, I don't know why but, I did this:
        find . -type f | xargs grep TheString
     or
        find . -type f -exec grep -H TheString '{}' \;

Until recently I found that I could do much less typing:
        grep -r TheString *

Is it because grep did not have the -r option in the old days?

Thursday, October 22, 2009

Firefox Extension: Take A Break

Addicted to the Web? Don't compromise your health! Continuously staring at the computer can cause headaches, blurred vision, neck pain, fatigue, dry eyes. Take A Break extension tries to help you avoid or reduce these problems. It reminds you when to take a break while you are surfing the Web.

Features
- A little icon on the status bar will be flashing every 15 minutes to remind you a short break. You should sit back and close your eyes, or look outside the window for a while.

- A pop-up dialog will remind you a big break every hour. You should stand up, get a cup of coffee, do some stretching, or go freshen up.

- You can adjust the timers according to your own needs.

Installation
Download and install it here: https://addons.mozilla.org/en-US/firefox/addon/45343

You will need to restart the Firefox browser after the installation.

After the Firefox browser restarts, you will see an icon of a green clock on your status bar. If your status bar is hidden, you could show it by selecting menu View->Status Bar.



How does it work
- The clock icon on the status bar will be flashing in red and yellow every 15 minutes to remind you a short break.
-- Take A Break extension is on.
-- Icon is flashing and reminding you to take a short break.

- A pop-up dialog will remind you a big break every hour. The pop-up window will be automatically closed after 5 minutes. You can click on the colorful text to close it, too. Clicking on the URL will bring you to more Firefox extensions I made.


- A click on the clock icon will switch off and on its function. If the function is turned off, the icon is in gray.
-- Take A Break extension is off.

- Right-click the icon and you can select to open the Options dialog. Here you can adjust the timers to meet your own needs. See the next section for the meanings of the options.

- Move the mouse over the icon and you can see when the next break will come.

- Of course, you can also open the Options dialog through the menu: Tools->Add-ons->Extensions, and click on the Options button of this extension.



Options setting


- Enable Flashing: enable/disable the feature of icon flashing. If it is not checked, the following two timers of Flashing Interval and Flashing Duration are ignored.

- Flashing Interval: the time between two flashing. You can set a value between 1 to 999 minutes.

- Flashing Duration: the duration of the flashing. You can set a value between 1 to 999 seconds.

- Enable Pop-up Reminder: enable/disable the feature of pop-up reminding. If it is not checked, the following two timers of Rest Interval and Rest Duration are ignored.

- Rest Interval: the time between two pop-up reminding. You can set a value between 1 to 999 minutes.

- Rest Duration: after this long, the pop-up window will be closed automatically. You can set a value between 1 to 999 minutes.

- No reminding if idle for XXX min: if checked, you can inform the extension that XXX minutes of no mouse movement means you are not browsing. So that the extension would temporary stop when you had left your desk.

You can click on the Restore defaults button to restore all the timers to their default values.


---
If you think this extension is helpful, please share it with your friends.

Saturday, October 17, 2009

Google Docs - spreadsheet - set formula for a whole column/row

If you want the column C to be the sum of column A and B, i.e.
   C1 = A1 + B1
   C2 = A2 + B2
   C3 = A3 + B3
   ...
you don't have to click on each cell of column C and add the formula repeatedly. Instead, you can:

1. Set formula for cell C1. And press the Enter button.


2. Select cell C1. You can see a little blue square at the bottom-right corner.


3. Move the mouse over the little blue square until it becomes a cross. Click down and hold the left button (or right button if you are left handed). Drag the little blue square all the way down to the last cell of column C.


4. Now you can see that all the cells of column C are correctly set as the sum of the corresponding cells in column A and B.

Tuesday, October 13, 2009

Untrusted Connection error of softmoc.com



If you tried to buy stuff at https://www.softmoc.com with Firefox browser, you might encounter the error saying "This Connection is Untrusted". The Technical Details reveal that --

    www.softmoc.com uses an invalid security certificate.
    The certificate is not trusted because the issuer certificate is unknown.
    (Error code: sec_error_unknown_issuer)

You know SoftMoc is a reputable company that you can trust. But the "Add Exception ..." looks scary and you are not sure about doing it.

Here is the safest way to let you use this site worry-free.

The Reason
(skip this section and go directly to the solution if you don't care about the technical details.)

The reason why you have encountered such an error is that to encrypt their transactions, softmoc.com use a certificate signed by a Chained/Intermediate Certificate from VeriSign (one of the major certificate authorities). This Chained/Intermediate Certificate is named VeriSign Class 3 Secure Server CA - G2. By default, it is not added to Firefox's Certificate Manager. However, if the website were configured properly, it would send the whole certificate chain to Firefox so that Firefox could trust the Chained Certificate. Apparently, softmoc.com is not properly set up.

The good news is that Firefox can automatically add those intermediate certificates it trusts. So if we have ever visited a website which properly uses the certificate of VeriSign Class 3 Secure Server CA - G2, our Firefox would know this certificate is good. Consequently, Firefox would trust softmoc.com. I have done a little search and found the website that correctly uses this missing intermediate certificate.

The Solution

Go to one of the web page of the famous Sun Microsystems company: https://getupdates2.sun.com/. The web page will prompt you a dialogue to ask for user name and password. We don't want to do anything with this website, so just click the Cancel button. After that, the required issuer certificate is known and added by Firefox.

Now you can enjoy your shopping at softmoc.com.