Tuesday, May 25, 2010

Firefox Extension: Take A Break version 1.1


Click here for the online help of the old version 1.0.x.

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. The extension can also keep beeping while the icon is flashing if you enable the sound option.

- 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 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
Click here to see how to open the "Options" dialog.




- 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.

- Enable Sound: You can enable sound for the short break. When it is enabled, the extension will keep beeping while the icon is flashing, and stop beeping when the short break ends. So you can know when to open your eyes if you close your eyes during the short break. It is also useful for those users who focus too much on the content to notice the changing of the icon on the status bar, or those who does not show the browser's status bar at all. The Sound Option is off by default -- some people may find it annoying.

- Use My Text in Reminder: A more fancy reminder window pops up to remind you a rest. It gives some suggestions -- with graphics -- of what you could do during the long break. If you like a simple and clean dialog instead, you can use this option to show only the text you choose.

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

Thursday, May 20, 2010

Linux: print OS version and information


The uname command prints certain system information. With the -a option, it prints all information about the Linux OS.

   $ uname -a

The version number in the print-out is the kernel release.

A Linux distribution usually has it own release versions. For example, the Ubuntu distribution may have a release version of 8.04. To see the version of a distribution, run command --

   $ lsb_release -a

or just view the file /etc/lsb-release.

There is an interesting directory named /proc. It reveals some system information. Just use the cat command to print them, such as:

   $ cat /proc/cpuinfo
   $ cat /proc/meminfo
   $ cat /proc/version

Tuesday, May 11, 2010

Firefox Extension: Keylogger Beater's More Features


To know the basic usage and features of Keylogger Beater, please read this post first.

Context Menu

Besides Ctrl-Shift-k, you can also activate Keylogger Beater via the context menu.

Right click on a text area or a password box and you can find a new menu item "Keylogger Beater". Click on it to turn on the Virtual Keyboard and start your private input.




Options

There are some options you can set to change how Keylogger Beater works. You can open the Options dialog via the menu Tools|Add-ons


Keyboard and mouse

If it is selected, you can use both the keyboard and mouse on the Virtual Keyboard to input characters.

Keyboard only

If it is selected, you can hit the Shadow Key to input the Real Key. Hovering the mouse over the Virtual Keyboard will have no effect.

Mouse only

If it is selected, the "Shadow Key to Real Key" mapping function is disable. That means you should only use the mouse on the Virtual Keyboard, because whatever you hit on the physical keyboard will be entered into the browser intact -- they can be captured by a keylogger. And the Virtual Keyboard will only show the Real Keys because there would be no Shadow Keys. The Virtual Keyboard will be in black and white.


If you use the computer at home and do not worry about peeking over the shoulder, you can use only the mouse with the Virtual Keyboard. Turning the "Use keyboard to input" option off gives you a clean Virtual Keyboard.

Random keyboard layout

When you use the mouse only input method, you can enable the this option to use a random layout. This adds one more secure level to the input method. It is not totally random, the keys are grouped by uppercase letters, lowercase letters, numbers and punctuations to make them easy to find.


Alphanumeric characters only

By default, this option is off. Some people may find that the Virtual Keyboard have too many keys, and it is difficult to find a specific punctuation key because they are in no official order. You can check this option to make the Virtual Keyboard contains alphanumeric characters only. That does not mean you can not input a punctuation mark. It just means a punctuation will be input directly from the physical keyboard to the browser without being encoded/decoded by the Virtual Keyboard. It is less secure because a keylogger can capture it.


Colorful virtual keyboard

By default, this option is on. The color of a key in the Virtual Keyboard is determined by the Shadow Key. If a Shadow Key is an uppercase letter, the color is green; if lowercase, it is blue; if number, it is yellow; and if punctuation, it is red.

If you uncheck this option, they are all in black and white.

As we state in the earlier section, if you uncheck "Use keyboard to input", this option has no effect and the keys are all in black and white because there are no Shadow Keys.

Use shortcut key (since version 3.1)

Check this option to enable shortcut key. You can choose your own shortcut key combination.

Rearrange Virtual Keyboard

Each time you press the shortcut key of Keylogger Beater, the Virtual Keyboard will be re-arranged. So you do not need to worry that a keylogger could steal the mapping rule of the Virtual Keyboard.

Invert Input

Invert Input is another Firefox extension I wrote. You can install it if you want an extra layer of secure input. Here is how -- First input your password backwards with Keylogger Beater. Then use Invert Input to reverse it. In this case, even somebody use a camera to record your screen and keystrokes, they would not be able to break your account.

Firefox Extension: Keylogger Beater


The online help of the old version 1 can be found here
The online help of the old version 2 can be found here


If you are worried about keylogging programs in your system, you can try this extension. There are two different ways to input with this extension. With the help of Keylogger Beater, a keylogger running in the background can never capture what you have really input, and you will be more confident to do online shopping or online banking.

The input method is different from any traditional ones, so please give a little patience and read the following help carefully before jumping into it.

The default shortcut combination conflicts with a shortcut of Firefox 4.0 itself. If you use Firefox 4.0, please choose your own shortcut on the Options dialog of this extension.

After you have installed the extension and restart Firefox. You can activate Keylogger Beater by pressing Ctrl-Shift-k (I just found out some other Firefox extensions may use this combination as the shortcut, if that is the case in your system, you can right-click on the input text box to activate Keylogger Beater through the context menu.) when the cursor is inside a text box and you are ready to make some input. You will see a pop-up right below the text box you are about to input into. I will call the pop-up "Virtual Keyboard" hereinafter. To hide the Virtual Keyboard, just press the ESC key.


Input Method 1: By Keyboard

You can see that each key in the Virtual Keyboard consists of two characters. e.g. [K b]. I call the first character "Real Key" (the upper and larger one) and the second one "Shadow Key" (the lower and smaller one). It is simple to use the Virtual Keyboard -- when you press the Shadow Key on your physical keyboard the Real Key is inserted to the cursor position in the text area of the browser.


For example, if the Virtual Keyboard looks like this:
   [A s] [B n] [C v] [D f] [E r] [F g] [G h] [H j] ...
and you want to input "HEAD", you hit "jrsf" on your physical keyboard. A background keylogger will capture "jrsf" as your input while your browser receives "HEAD" correctly.

The Virtual Keyboard is arranged in an alphabetical order of the Real Keys. When you have the Real Key (to input) in your mind, you can easily find the corresponding Shadow Key (to hit). Then you hit the Shadow Key on your physical keyboard to input the Real Key into your browser. The first two rows of the Virtual Keyboard are uppercase letters of the Real Keys; the 3rd and 4th rows are lowercase letters; the 5th row is numbers; and the last three rows are punctuations.

Some characters may look similar, e.g. 1 and l, 0 and O. You will not be confused with the Real Key because they are in the alphabetical order. But you might not distinguish the Shadow Keys sometimes. So I use the background color to give you a hint. If the Shadow Key is a uppercase letter, the background is green; if lowercase, the background is blue; if number, the background is yellow; and if punctuation, the background is red.


Input Method 2: By Mouse

You may want to read the first paragraph of "Input Method 1" to know the definition of "Real Key".

When your mouse hovers over a key of the Virtual Keyboard for 1 second, the "Real Key" of that key will be inserted into the text area of the browser.

Please note that clicking on the Virtual Keyboard has no effect. And I would discourage you to do that because some keyloggers tries to log the screenshot when you click your mouse. With Keylogger Beater, there is no mouse click event that can be captured by a keylogger. Keylogger Beater listens to the mouseover event from the Virtual Keyboard instead.

Download/Install

You can download and install this extension from the official Firefox Addons website: https://addons.mozilla.org/en-US/firefox/addon/161736/

Please report bugs and give suggestions on this page instead of on Firefox Addons website because I do not often go there.

Why is Keylogger Beater special?

Keylogger Beater works inside Firefox as an extension. A third party keylogger can capture the events sent from the input devices to an application, but it can not capture anything happens inside an application. If you run Keylogger Beater, a keylogger can only record random inputs of Shadow Keys (from the keyboard to Keylogger Beater), but can not discover what the Real Keys (from Keylogger Beater to the browser) are.

It may be a little bit difficult to use in the beginning. With a little practice, you will find it much easier than texting with a cell phone. :)

Certainly, you will want to review the source code to make sure Keylogger Beater itself is not a spyware. You can do so online at the download site. Just login there to view them.

Next -> More features and options of Keylogger Beater.

Thursday, May 6, 2010

C++ exercise: Recursion example -- sum up numbers


Q: Given a Sum and a string of numbers, add minimum operator "+" to make the sum of numbers equal to Sum. e.g. Sum=9, numbers: 101124, we get 9=1+01+1+1+2+4; Sum=88, numbers: 2112331453, we get 88=21+12+33+14+5+3.

#include <string>
#include <stack>
#include <iostream>

using namespace std;
 
// Returns: 0 -- Got a solution.
//         -1 -- No solution.
int Calculate(int sum, string numbers,
            int& best_op_count, string& best_solution)
{
   //cout << " Enter: " << sum << " " << numbers <<  endl;;
 
   bool gotone = false;
   int pow10 = 1;
   stack<char> tail_nums;
 
   // Pop maximum digits from tail of "numbers".
   // All the digits form a "num".
   int last_num;
   int num = 0;
   while (num < sum && numbers.size() > 0)
   {
      char last_ch = *(numbers.rbegin());
      last_num = last_ch - '0';
      if (num + last_num * pow10 > sum)
         break;
 
      tail_nums.push(last_ch);
      numbers.erase(numbers.size() - 1);
      num += last_num * pow10;
      pow10 *= 10;
   }
 
   if (numbers.size() == 0 && num == sum)
   {
      // Got one solution done.
      best_op_count = 0;
      best_solution = "";
      while (tail_nums.size() > 0)
      {
         best_solution += tail_nums.top();
         tail_nums.pop();
      }
      return 0;
   }
 
   // loop_1:
   int op_count;
   int temp_best_op_count = -1;
   string solution;
   string temp_best_solution = "";
   while ( pow10 > 0 && num > 0 && tail_nums.size() > 0)
   {
      //cout << " ... " << sum << "(=)" << numbers << "(+)" << num << endl;
 
      // Calculate result from the rest heading numbers as "subres".
      int subres = Calculate((sum - num), numbers, op_count, solution);
 
      // If "subres" == 0, we have a solution.
      if ( ! subres )
      {
         gotone = true;
 
         op_count++;  // one more op for "num" + Calculate(subsum);

         //cout << "Got one solution: " << sum << "=" << solution << "+" << num 
         //     << " <=============================" << op_count << "(+)s" << endl;
 
         // If it is a better solution, save it.
         if (op_count < temp_best_op_count || temp_best_op_count < 0)
         {
            temp_best_op_count = op_count;
            temp_best_solution = solution + "+";
            stack<char> temp_tail_nums = tail_nums;
            while (temp_tail_nums.size() > 0)
            {
               temp_best_solution += temp_tail_nums.top();
               temp_tail_nums.pop();
            }
         }
      }
                                                                                                                              
      // Remove the most significant digit from "num" back to "numbers".
      if (tail_nums.size() > 0)
      {
         char most_sig_char = tail_nums.top();
         tail_nums.pop();
         numbers += most_sig_char;
 
         pow10 /= 10;
         num -= (most_sig_char - '0') * pow10;
      }
 
      // Go to loop_1.
   }
 
   best_solution = temp_best_solution;
   best_op_count = temp_best_op_count;
 
   //cout << " Exit: " << sum << " " << numbers << " gotone?" << gotone 
   //     << "(" << best_solution << ")" << " count(" << best_op_count << ")" << endl;;
 
   if (gotone)
      return 0;
   else
      return -1;
}
 
 
int main()
{
   int mysum;
   string mystr;
   int op_cnt;
   string solution;
 
   while (cin)
   {
      cout << "Input sum: ";
      cin >> mysum;
      cout << endl;
 
      cout << "Input string: ";
      cin >> mystr;
      cout << endl;
 
      int res = Calculate(mysum, mystr, op_cnt, solution);
      if (res)
         cout << "No solution." << endl;
      else
         cout << "Solution: " << solution << endl;
 
      cout << endl;
   }

   return 0;
}

Wednesday, May 5, 2010

C++ exercises: read file with fstream and count punctuation marks


Q: Write a program that reads a text file and prints a count of the number of occurrences of the punctuation marks (.,!?).

#include <iostream>
#include <fstream>
#include <string>
 
using namespace std;
 
int main(int argc, char *argv[])
{
   if (argc < 2)
   {
      cout << "Usage: " << argv[0] << " <input_file>" << endl;
      return -1;
   }
 
   string s;
   string chs = ",.!?";
   int count = 0;
 
   fstream f(argv[1]);
   while (f)
   {
      getline(f, s);
 
      for (unsigned int i = 0; i < s.size(); i++)
      {
         if (chs.find(s[i]) != string::npos)
         {
            count++;
         }
      }
   }
 
   cout << "count: " << count << endl;

   return 0;
}

Monday, May 3, 2010

C++ exercises: swap two variables


Q: Swap a and b without using a third variable.

Algorithm:
1. a(new) = a(old) + b(old);
2. b(new) = a(new) - b(old) = (a(old) + b(old)) - b(old) = a(old)
3. a(final) = a(new) - b(new) = (a(old) + b(old)) - a(old) = b(old)


#include <iostream>

using namespace std;

int main()
{
   int a = 123;
   int b = 200;

   cout << "a: " << a << ", b: " << b << endl;

   a = a + b;
   cout << "a: " << a << ", b: " << b << endl;

   b = a - b;
   cout << "a: " << a << ", b: " << b << endl;

   a = a - b;
   cout << "a: " << a << ", b: " << b << endl;

   return 0;
}
 
Get This <