Feeds:
Posts
Comments

I released a new version of Chrome Nanny that incorporated few requested features. They are:

 

1. Validate regular expressions when they are entered in blockset.

2. More robust error handling inside the extension.

3. Always allow access to Chrome extension links even if you block *.*

4. Disallow *.* from White list.

5. Do not strip www/http from the blocksite. So a block url of www.ft.com will not block www.microsoft.com unless the url is ft.com.

6. Multiple internal changes that will allow implementation of other Chrome Nanny features faster.

 

Let me know how this version works !

In this post, I plan to discuss about two very simple inequalities – Markov and Chebyshev. These are topics that are covered in any elementary probability course. In this post, I plan to give some intuitive explanation about them and also try to show them in different perspectives. Also, the following discussion is closer to discrete random variables even though most of them can be extended to continuous ones.

Inequalities from an Adversarial Perspective

One interesting way of looking at the inequalities is from an adversarial perspective. The adversary has given you some limited information and you are expected to come up with some bound on the probability of an event. For eg, in the case of Markov inequality, all you know is that the random variable is non negative and its (finite) expected value. Based on this information, Markov inequality allows you to provide some bound on the tail inequalities. Similarly, in the case of Chebyshev inequality, you know that the random variable has a finite expected value and variance. Armed with this information Chebyshev inequality allows you to provide some bound on the tail inequalities. The most fascinating this about these inequalities is that you do not have to know the probabilistic mass function(pmf). For any arbitrary pmf satisfying some mild conditions, Markov and Chebyshev inequalities allow you to make intelligent guesses about the tail probability.

A Tail Inequality perspective

Another way of looking at these inequalities is this. Supposed we do not know anything about the pmf of a random variable and we are forced to make some prediction about the value it takes. If the expected value is known, a reasonable strategy is to use it. But then the actual value might deviate from our prediction. Markov and Chebyshev inequalities are very useful tools that allow us to estimate how likely or unlikely that the actual value varies from our prediction. For eg, we can use Markov inequality to bound the probability that the actual varies by some multiple of the expected value from the mean. Similarly, using Chebyshev we can bound the probability that the difference from mean is some multiple of its standard deviation.

One thing to notice is that you really do not need the pmf of the random variable to bound the probability of the deviations. Both these inequalities allow you to make deterministic statements of probabilistic bounds without knowing much about the pmf.

Markov Inequality

Let us first take a look at the Markov Inequality. Even though the statement looks very simple, clever application of the inequality is at the heart of more powerful inequalities like Chebyshev or Chernoff. Initially, we will see the simplest version of the inequality and then we will discuss the more general version. The basic Markov inequality states that given a random variable X that can only take non negative values, then

    Pr(X \geq k E[X]) \leq \frac{1}{k}

There are some basic things to note here. First the term P(X >= k E(X)) estimates the probability that the random variable will take the value that exceeds k times the expected value. The term P(X >= E(X)) is related to the cumulative density function as 1 – P(X < E(X)). Since the variable is non negative, this estimates the deviation on one side of the error.

Intuitive Explanation of Markov Inequality

Intuitively, what this means is that , given a non negative random variable and its expected value E(X)
(1) The probability that X takes a value that is greater than twice the expected value is atmost half. In other words, if you consider the pmf curve, the area under the curve for values that are beyond 2*E(X) is atmost half.
(2) The probability that X takes a value that is greater than thrice the expected value is atmost one third.
and so on.

Let us see why that makes sense. Let X be a random variable corresponding to the scores of 100 students in an exam. The variable is clearly non negative as the lowest score is 0. Tentatively lets assume the highest value is 100 (even though we will not need it). Let us see how we can derive the bounds given by Markov inequality in this scenario. Let us also assume that the average score is 20 (must be a lousy class!). By definition, we know that the combined score of all students is 2000 (20*100).

Let us take the first claim – The probability that X takes a value that is greater than twice the expected value is atmost half. In this example, it means the fraction of students who have score greater than 40 (2*20) is atmost 0.5. In other words atmost 50 students could have scored 40 or more. It is very clear that it must be the case. If 50 students got exactly 40 and the remaining students all got 0, then the average of the whole class is 20. Now , if even one additional student got a score greater than 40, then the total score of 100 students become 2040 and the average becomes 20.4 which is a contradiction to our original information. Note that the scores of other students that we assumed to be 0 is an over simplification and we can do without that. For eg, we can argue that if 50 students got 40 then the total score is atleast 2000 and hence the mean is atleast 20.

We can also see how the second claim is true. The probability that X takes a value that is greater than thrice the expected value is atmost one third. If 33.3 students got 60 and others got 0 , then we get the total score as around 2000 and the average remains the same. Similarly, regardless of the scores of other 66.6 students, we know that the mean is atleast 20 now.

This also must have made clear why the variable must be non negative. If some of the values are negative, then we cannot claim that mean is atleast some constant C. The values that do not exceed the threshold may well be negative and hence can pull the mean below the estimated value.

Let us look at it from the other perspective : Let p be the fraction of students who have a score of atleast a . Then it is very clear to us that the mean is atleast a*p. What Markov inequality does is to turn this around. It says, if the mean is a*p  then the fraction of students with a score greater than a is atmost p. That is, we know the mean here and hence use the threshold to estimate the fraction .

Generalized Markov Inequality

The probability that the random variable takes a value thats greater than k*E(X) is at most 1/k. The fraction 1/k act as some kind of a limit. Taking this further, you can observe that given an arbitrary constant a, the probability that the random variable X takes a value >= a ie P(X >= a) is atmost 1/a times the expected value. This gives the general version of Markov inequality.

    Pr(X \geq a) \leq \frac{1}{a} E[X]

In the equation above, I seperated the fraction 1/a because that is the only varying part. We will later see that for Chebyshev we get a similar fraction. The proof of this inequality is straightforward. There are multiple proofs even though we will use the follow proof as it allows us to show Markov inequality graphically.This proof is partly taken from Mitzenmacher and Upfal’s exceptional book on Randomized Algorithms.

Consider a constant a >= 0. Then define an indicator random variable I which takes value of 1 is X >=a . ie

    \displaystyle I = \begin{cases} 1, & \mbox{if } \mbox{ X} \geq \mbox{a} \\ 0, & \mbox{otherwise } \end{cases}

  Now we make a clever observation. We know that X is non negative. ie X >= 0. This means that the fraction X/a is atleast 0 and atmost can be infinty. Also, if X < a, then X/a < 1. When X > a, X/a > 1. Using these facts,

     I \leq \frac{X}{a}

If we take expectation on both sides, we get

     E[I] \leq \frac{1}{a} E[X]

But we also know that the expectation of indicator random variable is also the probability that it takes the value 1. This means E[I] = Pr(X>=a). Putting it all together, we get the Markov inequality.

    Pr(X \geq a) \leq \frac{1}{a} E[X]

Even more generalized Markov Inequality

Sometimes, it might happen that the random variable is not non-negative. In cases like this, a clever hack helps. Design a function f(x) such that f(x) is non negative. Then we can apply Markov inequality on the modified random variable f(X). The Markov inequality for this special case is :

Pr(f(X) \geq a) \leq \frac{1}{a} E[f(X)]

This is a very powerful technique. Careful selection of f(X) allows you to derive more powerful bounds.
(1) One of the simplest examples is f(X) = |X| which guarantees f(X) to be non negative.
(2) Later we will show that Chebyshev inequality is nothing but Markov inequality that uses f(X) = |X-E(X)|^2
(3) Under some additional constraints, Chernoff inequality uses f(X) = e^{tX} .

Simple Examples

Let us consider a simple example where it provides a decent bound and one where it does not. A typical example where Markov inequality works well is when the expected value is small but the threshold to test is very large.

Example 1:
Consider a coin that comes up with head with probability 0.2 . Let us toss it n times. Now we can use Markov inequality to bound the probability that we got atleast 80% of heads.

Let X be the random variable indicating the number of heads we got in n tosses. Clearly, X is non negative. Using linearity of expectation, we know that E[X] is 0.2n.We want to bound the probability P(X >= 0.8n). Using Markov inequality , we get

    P(X \geq 0.8n) \leq \frac{0.2n}{0.8n} = 0.25

Of course we can estimate a finer value using the Binomial distribution, but the core idea here is that we do not need to know it !

Example 2:
For an example where Markov inequality gives a bad result, let us the example of a dice. Let X be the face that shows up when we toss it. We know that E[X] is 7/2 = 3.5. Now lets say we want to find the probability that X >= 5. By Markov inequality,

P(X \geq 5) \leq \frac{3.5}{5} = 0.7

The actual answer of course is 2/6 and the answer is quite off. This becomes even more bizarre , for example, if we find P(X >= 3) . By Markov inequality,

P(X \geq 3) \leq \frac{3.5}{3} = \frac{7}{6}

The upper bound is greater than 1 ! Of course using axioms of probability, we can set it to 1 while the actual probability is closer to 0.66 . You can play around with the coin example or the score example to find cases where Markov inequality provides really weak results.

Tightness of Markov

The last example might have made you think that the Markov inequality is useless. On the contrary, it provided a weak bound because the amount of information we provided to it is limited. All we provided to it were that the variable is non negative and that the expected value is known and finite. In this section, we will show that it is indeed tight – that is Markov inequality is already doing as much as it can.

From the previous example, we can see an example where Markov inequality is tight. If the mean of 100 students is 20 and if 50 students got a score of exactly 0, then Markov implies that atmost 50 students can get a score of atleast 40.

Note : I am not 100% sure if the following argument is fully valid – But atleast it seems to me :)

Consider a random variable X such that

    X = \displaystyle \begin{cases} k & \mbox{with probability } \frac{1}{k} \\ 0 & \mbox{else} \end{cases}

We can estimate its expected value as

    E[X] = \frac{1}{k} \times k + \frac{k-1}{k} \times 0 = 1

We can see that , Pr(X \geq k E[X]) = Pr(X \geq k) = \frac{1}{k}

This implies that the bound is actually tight ! Of course one of the reasons why it was tight is that the other value is 0 and the value of the random variable is exactly k. This is consistent with the score example we saw above.

Chebyshev Inequality

Chebyshev inequality is another powerful tool that we can use. In this inequality, we remove the restriction that the random variable has to be non negative. As a price, we now need to know additional information about the variable – (finite) expected value and (finite) variance. In contrast to Markov, Chebyshev allows you to estimate the deviation of the random variable from its mean. A common use of it estimates the probability of the deviation from its mean in terms of its standard deviation.

Similar to Markov inequality, we can state two variants of Chebyshev. Let us first take a look at the simplest version. Given a random variable X and its finite mean and variance, we can bound the deviation as

    P(|X-E[X]| \geq k \sigma ) \leq \frac{1}{k^2}

  There are few interesting things to observe here :
(1) In contrast to Markov inequality, Chebyshev inequality allows you to bound the deviation on both sides of the mean.
(2) The length of the deviation is k \sigma on both sides which is usually (but not always) tighter than the bound k E[X]. Similarly, the fraction 1/k^2 is much more tighter than 1/k that we got from Markov inequality.
(3) Intuitively, if the variance of X is small, then Chebyshev inequality tells us that X is close to its expected value with high probability.
(4) Using Chebyshev inequality, we can claim that atmost one fourth of the values that X can take is beyond 2 standard deviation of the mean.

Generalized Chebyshev Inequality

A more general Chebyshev inequality bounds the deviation from mean to any constant a . Given a positive constant a ,

    Pr(|X-E[X]| \geq a) \leq \frac{1}{a^2}\;Var[X]

Proof of Chebyshev Inequality

The proof of this inequality is straightforward and comes from a clever application of Markov inequality. As discussed above we select f(x) = |X-E[X]|^2. Using it we get ,

    Pr(|X-E[X]| \geq a) = Pr( (X-E[X])^2 \geq a^2)
Pr( (X-E[X])^2 \geq a^2) \leq \frac{1}{a^2} E[(X-E[X])^2]

We used the Markov inequality in the second line and used the fact that Var[X] = E[(X-E[X])^2].

Common Pitfalls

It is important to notice that Chebyshev provides bound on both sides of the error. One common mistake to do when applying Chebyshev is to divide the resulting probabilistic bound by 2 to get one sided error. This is valid only if the distribution is symmetric. Else it will give incorrect results. You can refer Wikipedia to see one sided Chebyshev inequalities.

Chebyshev Inequality for higher moments

One of the neat applications of Chebyshev inequality is to use it for higher moments. As you would have observed, in Markov inequality, we used only the first moment. In the Chebyshev inequality, we use the second moment (and first). We can use the proof above to adapt Chebyshev inequality for higher moments. In this post, I will give a simple argument for even moments only. For general argument (odd and even) look at this Math Overflow post.

The proof of Chebyshev for higher moments is almost exactly the same as the one above. The only observation we make is that (X-E[X])^{2k} is always non negative for any k. Of course the next observation is E[(X-E[X])^{2k} gives the 2k^th central moment . Using the statement from Mitzenmacher and Upfal’s book we get ,

    Pr(|X-E[X]| > t \sqrt[2k] {E[(X-E[X])^{2k}]}) \leq \frac{1}{t^{2k}}

It should be intuitive to note that the more information we get the tighter the bound is. For Markov we got 1/t as the fraction. It was 1/a^2 for second order Chebyshev and 1/a^k for k^th order Chebyshev inequality.

Chebyshev Inequality and Confidence Interval

Using Chebyshev inequality, we previously claimed that atmost one fourth of the values that X can take is beyond 2 standard deviation of the mean. It is possible to turn this statement around to get a confidence interval.

If atmost 25% of the population are beyond 2 standard deviations away from mean, then we can be confident that atleast 75% of the population lie in the interval (E[X]-2 \sigma, E[X]+2 \sigma). More generally, we can claim that, 100 * (1-\frac{1}{k}) percentage of the population lies in the interval (E[X]-k. \sigma, E[X]+k \sigma) . We can similarly derive that 94% of the population lie within 4 standard deviations away from mean.

Applications of Chebyshev Inequality

We previously saw two applications of Chebyshev inequality – One to get tighter bounds using higher moments without using complex inequalities. The other is to estimate confidence interval. There are some other cool applications that we will state without providing the proof. For proofs refer the Wikipedia entry on Chebyshev inequality.

(1) Using Chebyshev inequality, we can prove that the median is atmost one standard deviation away from the mean.
(2) Chebyshev inequality also provides the simplest proof for weak law of large numbers.

Tightness of Chebyshev Inequality

Similar to Markov inequality, we can prove the tightness of Chebyshev inequality. I had fun deriving this proof and hopefully some one will find it useful. Define a random variable X as ,

[Note: I could not make the case statement work in WordPress Latex and hence the crude work around]

X = { \mu + C  with probability p

      { \mu – C  with probability p

      { \mu with probability 1-2p

    E[X] = p(\mu +C) + p(\mu -C) + (1-2p) \mu = \mu
Var[X] = E[(X-\mu)^2]
= p (\mu+C-\mu)^2 + p (\mu-C-\mu)^2 + (1-2p)(\mu-\mu)^2
\Rightarrow Var[X] = 2pC^2

If we want to find the probability that the variable deviates from mean by constant C, the bound provided by Chebyshev is ,

    Pr(|X-\mu| \geq C) \leq \frac{Var[X]}{C^2} = \frac{2pC^2}{C^2}=2p

which is tight !

Conclusion

Markov and Chebyshev inequalities are two of the simplest , yet very powerful inequalities. Clever application of them provide very useful bounds without knowing anything about the distribution of the random variable. Markov inequality bounds the probability that a nonnegative random variable exceeds any multiple of its expected value (or any constant). Chebyshev’s inequality , on the other hand, bounds the probability that a random variable deviates from its expected value by any multiple of its standard deviation. Chebyshev does not expect the variable to non negative but needs additional information to provide a tighter bound. Both Markov and Chebyshev inequalities are tight – This means with the information provided, the inequalities provide the most information they can provide.

Hope this post was useful ! Let me know if there is any insight I had missed !

References

(1) Probability and Computing by Mitzenmacher and Upfal.
(2) An interactive lesson plan on Markov’s inequality – An extremely good discussion on how to teach Markov inequality to students.
(3) This lecture note from Stanford – Treats the inequalities from a prediction perspective.
(4) Found this interesting link from Berkeley recently.

In this post , I assume that you use Ubuntu (with English) and want to use it to read or write Tamil stuff. Hence , I discuss steps to view Tamil web pages and also edit files in Tamil. This post will not tell you how to get a localized Tamil version of Ubuntu.

Reading Web Pages in Tamil

This is the most common requirement. You have Ubuntu and you want to visit and read , say, Tamil newspapers or blog posts. To do that install the following packages :

sudo apt-get install language-support-fonts-ta ttf-tamil-fonts ttf-indic-fonts-core

These three packages should solve the problem of Tamil fonts from multiple websites. ttf-indic-fonts-core  adds some popular Tamil fonts (in addition to other fonts for Indian languages) and ttf-tamil-fonts adds some more additional Tamil fonts.

Writing in Tamil

Writing in Tamil is done by adding Tamil keyboard layout to Ubuntu. If you are in a version before Natty (11.04), then use “System -> Preferences –> Keyboard” . If you are using Natty, then click on the power icon on the right hand top of the screen and select “System Settings”. In the settings dialog, choose Hardware tab and then select Keyboard. This will open up keyboard preferences menu.

Select the “Layouts” tab and click on Add . In the “Choose a Layout” dialog, go to the Language tab and select Tamil as the language. Choose your preferred variant . I have chosen “India Tamil Unicode”.  Click “Add” to add the language.

If you notice, the top panel will automatically get the keyboard layout indicator which highlights the currently selected language. This selection is application specific . For eg, if you selected Tamil when typing in gedit and then went to say LibreOffice, you will be typing in your default language in LibreOffice. Initially this behavior is a bit confusing, but usually makes lot of sense in practice.

In the Layouts tab, click on Options and set an appropriate key combination in the entry “Key(s) to change layout”.  I use “Shift+Caps Lock”. This is useful as otherwise , you need to key toggling in the keyboard indicator. If you are keyboard person, this is the best way to switch over all the languages in your layout. If there are multiple, then pressing “Shift+Caps Lock” cycles through your choices. The keyboard applet/indicator will change appropriately.

Unfortunately, most Tamil keyboard layouts are not mnemonic based and it takes quite a while to get used to. But once it starts working, it’s a great liberating feeling to type in another languages.

Using Tamil

Since Linux has a great internationalization support, you can use Tamil for other purposes also. For eg, I use Tamil to name folders ! Or sometimes even write some personal stuff :) . Most applications including Nautilus has multilingual support and things should seamlessly !

R is one of the coolest language designed and I am having lot of fun using it. It has become my preferred language of programming next only to Python. If you are also using Ubuntu, the rate of update of R in Ubuntu’s official repositories is slightly slow. If you want to get the latest packages as soon as possible, then the best option is to add some CRAN mirror to your Ubuntu repository. This by itself is straightforward. I decided to write this post on how to solve the GPG error if you get it.

Steps

(1) Decide on which CRAN repository you want to use. Finding the nearest one usually gives the best speed. Lets say it is http://cran.cnr.berkeley.edu/ . Append "bin/linux/ubuntu". Typically this works. You can confirm this by going to this url in the browser too.
(2) Add this to your Ubuntu repository. There are multiple ways. In the steps, below, replace http://cran.cnr.berkeley.edu/bin/linux/ubuntu with your mirror

(a) Synaptic -> Settings -> Repositories -> Other Software -> Add . In the apt line enter "deb http://cran.cnr.berkeley.edu/bin/linux/ubuntu natty/".
(b) sudo vim /etc/apt/sources.list and add "deb http://cran.cnr.berkeley.edu/bin/linux/ubuntu natty/" at the end. If you are not comfortable with vim, use gedit but instead of sudo , used gksudo.
(c)sudo add-apt-repository deb http://cran.cnr.berkeley.edu/bin/linux/ubuntu natty/

 

(3) Refresh the source repository by using refresh in Synaptic or using  "sudo apt-get update "
(4) Install R or any other package you want. If you are installing R , I suggest you install r-base-dev instead of r-base. If you are installing some R package , check if it exists with the name r-cran-* . Else, install it using install.packages command inside R.
(5) Enjoy :)

Fixing GPG Errors

When I did these steps, I got an error like the following (This occurred when I updated last month, this might be fixed now !):

GPG error: http://cran.cnr.berkeley.edu natty/ Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 51716619E084DAB9

If you get the error, enter the following commands in the terminal.

     gpg –keyserver keyserver.ubuntu.com –recv-key E084DAB9
     gpg -a –export E084DAB9 | sudo apt-key add -

Repeat the steps above and this should fix the key error.

I am not a big fan of Twitter but lot of geeks I respect seem to use it. I used to follow a few Twitter accounts using RSS in Google Reader. Basically, I will go to the Twitter account’s page and there will be a RSS icon. Clicking it will subscribe the feed in your favorite RSS reader. I can follow the accounts from Google Reader as if it is yet another blog.

Unfortunately, Twitter recently announced that they are not planning to support RSS directly. If you go to the latest Twitter page of the account you want to follow, you will not see a RSS icon. This annoyed me to no end as it used to provide a convenient way for me to follow the accounts in the comfort of Google Reader. The following are are some of the hacks that you can use to get the RSS feed url to subscribe in your reader. I have arranged them from easy to hard.

Method 1 : Using Google Reader’s Add Subscription

This seems to work for me as of now and hopefully will work in the near future. If you are using Google Reader, click on "Add Subscription" button. In the textbox, enter the url as "http://twitter.com/username" . Change the username to the actual account name that you want to follow. This will subscribe you to the account’s feed.

Method 2: Using Account Name in Twitter API

If the above did not work or if you are using other RSS reader , there is an alternative. If you know only the account name, use the following as the feed url :

 http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=accountName

This technique uses information from Twitter’s dev wiki of the API that returns the last 20 statuses of the user.

Method 3: Using User ID in Twitter API

This method is slightly more advanced and assumes that you know the user id of the account that you want to follow. This number is not easy to find – especially in the new twitter. The following instructions assume you use Chrome, but the instructions for Firefox must be similar. For other browser users, you can use the overall idea given here and adapt it to your browser.

(1) Go to the account that you want to follow. Click on the "Tweets" tab so that the last few tweets are visible.
(2) Now select few of the initial tweets using the mouse.
(3) Right click -> Inspect Element
(4) In the develop tools that is now shown, enter the account name of the user. Find the instance that comes with the user-id field. A sample might be :

<a class="tweet-screen-name user-profile-link" data-user-id="1234567890" href="/#!/accountname" title="Account Name">Account Name</a>

Alternatively, you can search for  "data-user-id" (without quotes) in the search box. Note that entering part of it (say user-id) will not work. It has to be exact. Find the element that corresponds to the user profile.
(5) In the list of elements that are matched, find the number whose length is between 8-10 – eg 1234567890.
(6) This is the user id of the account.

Once you get the user id, there are two methods to subscribe. One uses the variation of previous method. Enter the feed url as (replace 1234567890 with the actual one)

  http://api.twitter.com/1/statuses/user_timeline.rss?user_id=1234567890

The other alternative is to use the following as the feed url (replace 1234567890 with the actual one)

  https://twitter.com/statuses/user_timeline/1234567890.rss
   

I hope one of the methods works for you and helps you to follow your favorite Twitter accounts using your greatest RSS reader :)

Hamster is one of my favorite apps in Linux. I use it so much that I had previously written a post on it at Time Tracking in Linux using Hamster. One of the problems, I faced when I installed Natty was that it does away with the notification area (or systray). This means that the hamster applet will not be loaded in the panel automatically.

In the Launchpad, there exists a bug that discusses ways to add indicator support to Hamster. The author of Hamster has indicated that ,for now, he is not going to write a version for GNOME 3.0 (using GNOME Shell). I took a look at the code and it seems interesting – although I am not fully familiar with hamster graphics methods. If Unity support is not built into hamster in the near future, I will take a stab at it. In this article, I discuss some workarounds to still use Hamster in Ubuntu Unity or GNOME Shell  . They range from the easiest to hardest.

Method 1

If you are using Ubuntu Unity, the best alternative is to use the hamster version developed by Alberto Milone. The description of his work is this page – Appindicator for Hamster . Basically, he created a child class of HamsterApplet which has appindicator support. Pretty neat ! I browsed through the code and it seems straightforward. Hopefully, it will go into the upstream.

The instructions to use it are given in the linked page. Basically, you download the python code from hamster-appindicator’s github page. If you do not know how to use git , then just download the raw Python file . Put it in some folder and invoke it as "python hamster-indicator.py &". You can also add it to your Ubuntu startup applications !

Method 2

Since hamster applet is nothing but a Python app, you can technically invoke it as a standalone application instead of an applet. Most of the time, the utility must be in your path. You can invoke it as "hamster-time-tracker &" (or "python /usr/bin/hamster-time-tracker &") and by default, it will open a new stand alone window for the tracker. One thing to notice is that, this view does not have the "Add earlier activity" button. So this is only useful , if you want to add tasks starting now. Or you can muck around with Hamster’s use of negative time (-x a@b,c means I have been doing activity a of category b with description c for the last x minutes).

If you want to add earlier activities, invoke hamster as ,

    hamster-time-tracker toggle

  There are other options also. The entire list is overview|statistics|edit|preferences|about|toggle . The overview mode opens the "Overview" window that allows you to browse your activities for this week/month etc. The statistics mode shows a chart of your activities. The edit mode opens a new window that usually shows up when you click on "Add new activity". It allows you to enter activity,category, description, tags starting at arbitrary time.

The only catch is that it does not always visible and hence you might forget that it even exists ! If you are not as absent minded, then this is the best way to go (especially in GNOME 3.0 or GNOME Shell).

Method 3

Use this method, if none of the above works. This is only for masochistic hardcore geeks. The basic idea is to use the hamster-service that runs in the background and use the hamster’s command line utility. Just invoking the command line tool "hamster-cli" will give you a list of options. They are :

(1) list-activities : You can invoke this option to list all the activities and their respective categories. The format of output is activity@category . This is useful if you want to add a category using command line. The invocation is
    hamster-cli list-activities
(2) list-categories : This will show a list of all available categories. Usually this is superfluos as list-activities gives you the categories also.
(3) stop : This stops the task that is currently being tracked by hamster.
(4) list : This , by default(without arguments) , shows all the activities tracked for today. You can also give hh:mm-hh:mm option to display activities between specific time.

    hamster-cli list
    hamster-cli list 00:00-12:00

   
The first shows all of today’s tracked tasks while the second shows till 12 PM.

(5) start : The most important switch. This allows you to add a new activity – This can start now or at an earlier time. The format of entry is to give a activity with its category, optionally start time and description.

Currently, you cannot add new category or activity types using hamster-cli. You can only add/track a task using existing activity/category. If you want to add new activity/category use "hamster-time-tracker preferences" command to open Hamster’s preferences dialog which will allow you to do that .

    hamster-cli start "Blogging@Blogging"
    hamster-cli start "Blogging@Blogging,Hamster Post" 19:00-21:00
    hamster-cli start "Blogging@Blogging,Hamster Post" -00:40:00

The first invocation starts a new ongoing task of activity type Blogging and category type "Blogging" (after the @). The second invocation adds an earlier task of blogging between 7-9 PM. The third invocation starts a new task of blogging that started 40 minutes ago and still ongoing.

Hamster allows a more sophisticated time specification mechanism for start. I will put the details verbatim from the help of hamster-cli.

Time formats:
    * ‘YYYY-MM-DD hh:mm:ss’: Absolute time. Defaulting to 0 for the time
            values missing, and current day for date values.
            E.g. (considering 2010-03-09 16:30:20 as current date, time):
                2010-03 13:15:40 is 2010-03-09 13:15:40
                2010-03-09 13:15 is 2010-03-09 13:15:00
                2010-03-09 13    is 2010-03-09 00:13:00
                2010-02 13:15:40 is 2010-02-09 13:15:40
                13:20            is 2010-03-09 13:20:00
                20               is 2010-03-09 00:20:00
    * ‘-hh:mm:ss’: Relative time. From the current date and time. Defaulting
            to 0 for the time values missing, same as in absolute time.
           

To see other information, type "hamster-cli" without any arguments in the command line. It will show a helpful list of commands.

Method 4

One of the comments in the Launchpad asked for Hamster to behave like a docky helper. If thats your thing, follow the instructions at  this page . I have not personally tried it but hopefuly it will work.

Method 5

This is something I tried but did not work. Basically, I tried to add hamster to the whitelist of applications that are allowed to use notification area in Unity. You can find the details of how to enable any application to use systray at this askubuntu question.

I tried entering various incantations like hamster,Hamster,Time Tracker,hamster-time-tracker, hamster-tracker and so on. Somehow none of these worked. If anyone got it to work please let me know in the commands.

 

In conclusion, Hamster is one of the coolest apps in Linux and this post discusses some workaround for using it in Unity or GNOME 3.0 /GNOME Shell. Hopefully, indicator support will be built in the upstream itself soon. Have fun with Hamster !

In this post, I plan to talk about Ubuntu Unity. There has been hundreds of post on Unity . I will try to refrain from posting yet another Unity review. I assume that by choice or force, you are currently a Unity user. I plan to discuss how to make your life more productive by mastering it. So I will discuss various shortcuts, configurations and other cool stuff that I found in my 3 months(From Mar 2011) of active usage. Hence, this post will be slightly more technical. If you want an introductory post/review on Unity, check out the exceptional post by Ryan Paul here   .

Introduction

Unity has been one of the most controversial products released recently and the reaction has been surprisingly polarized. Lot of people hate it and lot of people love it. Whatever be your position, it is a good idea to learn to use the Unity paradigm because this is the direction that most of Linux community is moving. For eg, GNOME Shell, which is another popular alternative for Unity , also has similar design vision. So, it is safe to say Unity is a harbinger of a potential UI revolution in Linux. Whether this will cause more users to come to Linux is yet another matter :)

Terminology

Before we discuss about Unity, I think it is a good idea to give an orientation of various Unity components. This will help you when you read other posts or when you ask questions in some forums.

Unity :  Unity is nothing but a desktop “shell” to GNOME. GNOME Shell is yet another alternative. One of the key things to understand is that Unity was designed as lightweight shell as it was focused towards netbooks running Ubuntu. Understanding this will provide an appreciation of Unity’s design decisions. Since  it is targeted towards netbooks, it tries to conserve screen space as much as possible. Unity was ported to desktop in Natty. It is internally written as plugin for Compiz.

Ayatana : This is another name that you will come across. Ayatana can be considered as an umbrella project primarily focusing on UI and design stuff in Ubuntu. Some of the notable projects are Unity, Unity 2D,  MultiTouch, App indicators, Me-Menu and Notify OSD. See their launchpad page for more of the projects they run.

Unity-2D : Unity 2D can be considered as poor man’s Unity.  If your computer does not have the necessary hardware capabilities to run Unity, Unity-2D will act as the fallback. In Natty, the classic GNOME was provided as the fallback. Starting from Oneiric, Unity-2D will be the fallback. It is primarily written in QML and uses Metacity. Even Unity-2D replaces panel, launcher and other stuff.

Mutter , Clutter , Compiz and other stuff : Unity is primarily written as a plugin for Compiz window manager. The toolkit uses in Nux which is claimed to be faster than Clutter. Nux acts as an interface between Compiz and Unity. GNOME Shell uses Mutter (Metacity Clutter) as the window manager. Metacity is yet another window manager used in GNOME 2.2+ . Clutter is the toolkit. Both Nux and Clutter are opengl toolkits that provide convenient hardware based acceleration if available. This is the reason why both Unity and GNOME Shell uses a toolkit that has this support. For Unity 2D, the window manager is Metacity (even though Compiz can be used). If all of this confuses you , ignore it. Other than hard core geeks, nobody cares about these.

Wayland : This is a development that I am excited about. Wayland is primarily a display management system (also a protocol), just like X Window system. Instead of making some assumptions about Network and stuff, Wayland allows you to use native opengl to provide great graphics. The vision is quite fascinating and I hope it will turn out great.

Now that you know the overall big  picture, lets dive down to specific UI elements in Unity. The following text is based on my interpretation of Canonical’s design blog and this excellent AskUbuntu question  .

Ubuntu Button : This is the big button on the left top of the screen.

Launcher : This is the entire strip on the left that comes up when you hover over the left side of your screen. This will contain multiple types of icons. Icons that act as launcher icons for other applications, icons that show the currently running applications , lenses and workspace switcher.

Accordion : If you open lot of applications such that the launcher does not fit,  the icons are displayed in an accordion fashion – Basically, few of the icons are vertically stacked and if you hover your mouse over them it expands to show the icons that are present there.

Sigil : As said before, Launcher may contain some icons always – even if the application is not running. If the corresponding application is launched (or some other application), the icon in the launcher will contain a small white arrow called the sigil. It denotes that the application is currently running. The number of sigils denotes the number of instances of the same application.

Quicklist : Quicklists are another really cool idea in Unity. Although not as polished as Windows 7, it shows lot of promise. Quicklists are the common tasks that you do in an application that is accessible to you when you right click the application’s launcher item. Quicklists can be anything – For eg quicklist for a browser might be to open a new instance, open in incognito mode, go to specific site etc.  Alternatively, if you use Banshee/Rhythmbox, you can have all the music controls (Play/Pause/Next/Previous) in the right click.

Dash : The full screen black translucent overlay that appears when you press Super. Alternatively, you can click on the Ubuntu button. It contains a search option and also broadly classifies applications like Media, Internet etc.

Lenses : Lenses are one of the coolest ideas in Unity. Even though Dash allows you to search , its use is fairly limited to items in your computer. Lenses take the idea of the dash and extend it in such a way that it can search arbitrarily anything. You can kinda consider “Files and Folders” and “Applications” on the launcher as a special kind of lenses. They are currently called Places but their usage will be deprecated. There are lot of other cool lenses – For eg, one which searches sub-reddits , one that searches contacts , Amazon , Youtube etc. The API is also pretty awesome. I was able to code a lens to show the latest tweets of a user just by typing their name within couple of hours. If no one writes, I will write Lens tutorial sometime soon !

Panel : The strip that is at the top. The panel has been thoroughly given a facelift in Unity. It now performs lot of tasks. By default, it shows the title of the current active applications. When you hover your mouse over it , it shows the menu items of the applications. On the right hand side are the app indicators.

Global Menu : Also called as Application menu. When an application is active, this part of the panel will show the window controls  (Maximize/Minimize/Close) and the window title. If you hover over the panel or press Alt key, it changes to the menu of the application.

App Indicators : These are the icons on the right side for the panel.  By default it contains Sound, Network, Mail/Chat indicator, time , Me-Menu etc. You also add other indicators if you wish. To see the potential of these indicators, check out the sound indicator. It contains all the buttons to control playing and also allows you to select other playlists.

Overlay Scrollbar : Overlay scrollbar is one of the innovations in Unity designed to save space. In a typical application that needs scrolling, the scrollbars appear taking up valuable pixels. In Unity, the scroll bar appears as a thin strip. If you move your mouse over it, the classical scrollbar appears.

Keyboard Shortcuts for Accessing Unity Items

Exhaustively discussing all the features of Unity is beyond the scope of this blog post. If you are interested, see Ryan Paul’s article linked above. I will discuss the most important stuff and will intersperse mouse and keyboard based access. If you are a keyboard junkie, all of Unity’s keyboard shortcuts are here  .

Launcher : This can be activated by hovering over the left end of the screen. Alternatively, you can class keep pressing Super key for couple of seconds to make it visible. The initial delay is to prevent accidental invocation. If you are not comfortable with the default behavior, you can change it . See the section of unity configuration below. Since Unity removed the bottom panel that used to show active windows in the current workspace,  viewing the launcher is one way to see all the open applications.

Launcher Items : Once the launcher is visible , you can click on any launcher item to launch the application (if not already running) or bring it to the foreground. If you are a keyboard person, keep pressing the Super key. The launcher will appear with a character appearing on each of the icon. Pressing the character along with Super key will launch the application. For eg, Super+a starts the application places and Super+1 launches the application corresponding to the first icon in the launcher. Pressing Shift or using middle click will start a new instance.

Operations on Launcher Items : The default set of launcher items are not ideal and you many want to do some personalization. The simplest is reordering of icons. You can do it by either clicking on an icon and moving it up. Or you can click on it, pull it to the right and then place it at the right place.

If you want to remove a launcher item,you can drag the icon to the trash. Unfortunately, the obvious action of pulling the icon out of the launcher does not seem to remove the icon. If you have used any docks like docky or AWN , this might seem unintuitive.  If you want the icon to never appear in launcher, launch the application and right click on the icon and unselect ‘Keep in launcher’ option.

If you want to add a new application,the easiest way is to launch it by other means. Once the icon shows up in the launcher, right click it and select ‘Keep In Launcher’. Putting arbitrary application is a bit tricky. See the ‘Advanced’ section for details.

Lenses : Super+A opens the application places (lens) and Super+F opens the the Files and Folders lens. Super+T opens the trash.

Dash : Pressing Super and releasing it immediately brings the dash. If you use Alt+F2, it brings out Dash version of “Run” dialog.

App Indicators : Pressing F10 highlights the first app indicator menu which you can use keyboard navigation keys to select. To move to the other indicators press left or right arrow keys. For eg, pressing F10 for me opens the network indicator. Pressing right opens the volume indicator applet and so on. Of course, pressing Esc removes the focus from indicators.

Show Desktop : Pressing Super+D minimizes all the windows and shows the desktop. Pressing it again restores the windows.

Workspaces : If you press Super+W , it will create an Expose like effect showing all non minimized windows in all workspaces. If you want only for current workspace, type Shift+Alt+Up arrow. Moving a window to another workspace is not obvious as the bottom panel is removed. There are two ways : Press Super+S and it shows all the workspaces with the current window highlighted in current workspace. You can now use mouse to move window across the workspaces. If you want to move using keyboard, press Ctrl+Alt+Shift+ Arrow keys. You can may recognize that Ctrl+Alt+Arrow is the key combination to move across workspaces. Adding a shift, moves the window to the appropriate workspace.

Configuration and Personalization

One of the nicest things about is that it is highly configurable – Especially, if you do not mind getting your hands dirty with terminal stuff. In this section, I will discuss basic configuration of Unity and how to personalize it using quicklists and additional lenses.

To do the basic configuration, you would have to install “CompizConfig Settings Manager” (ccsm) from Synaptic. Once you have installed it press “Alt+F2” and enter “about:config” to access it. If you typed “ccsm” instead, search for Unity in the search box and get the “Ubuntu Unity Plugin” dialog.

 

My favorite settings are :
(1) Hide Launcher to “Dodge Windows”
(2) In Experimental tab, set “Backlight Mode” to “Backlight Toggles” . This will help you identify active and inactive launcher icons from their backlights.
(3) Launcher Icon size to 32 pixels.

 

Custom Launchers:
You might custom applications to your launcher. There are multiple ways to do that – The easiest is the following :
(1) Right click the desktop and select “Create Launcher”
(2) Set the launcher type – typically it is Application
(3) Enter the name of the launcher. This will be the name the Launcher icon will show if you hover over it or right click it.
(4) Enter the full command line path in Command field.
(5) Optionally enter a comment. You can also edit the icon by clicking on the icon’s icon :)
(6) Click ok and save the item. This will be saved in your desktop.
(7) Now drag this item on to the launcher.
(8) Voila ! The item is added to the launcher !

 

Custom QuickLists :
You can also create custom quicklists. The method is not very hard but involves editing configuration files manually.  The basic idea is as following :
(1) Find a similar .desktop file from /usr/share/applications/ and copy it to ~/.local/share/applications/ with the name as per your wish. Of course, you can keep it in any folder you wish but ~/.local/share/application is customary.
(2) If your .desktop file has a line like “OnlyShowIn=GNOME;”, change it “OnlyShowIn=GNOME;Unity;”
(3) At the end of the file , add the following line “X-Ayatana-Desktop-Shortcuts=shortcut1;shortcut2” . Replace shortcutx with your name of shortcuts. Each of them , except the last, must be separated by semicolon. It is better to have each shortcut name to be a single word.
(4) For each of the shortcut, add a section like this :

[shortcut1 Shortcut Group]
Name=Blah
Exec=Command to run
TargetEnvironment=Unity

(5) Things to note above are that the name of the shortcut at the beginning and in each section must match exactly.
(6) Go to this folder using Nautilus. If you want to see hidden files, press Ctrl+H. Or type “xdg-open ~/.local/share/applications/” in the command line. Now drag and drop the file you modified into Launcher.
(7) Remember, if you delete this desktop file, the launcher icon will also go !

One thing to realize is that to get access to these quicklists, the launcher icon need not always be in the Launcher. For eg, I want the quicklists for Banshee but I do not want Banshee’s icon cluttering up my space. If you are like me, make the change to the desktop file and put it in ~/.local/share/applications but do not drag and drop to Launcher. When you start the application, then Unity will automatically show the quicklist options. If the application is closed, the icon also goes away !

If you are too lazy to do all these, check out this link  for lot of awesome custom launchers and quick lists.

 

GNOME Applets :
Every Gnome user will have their own share of Gnome applets. Unfortunately, Gnome applets by themselves are not possible to be used directly in Unity. This is not just a Unity . The same holds for Gnome Shell too ! In Unity, they have to be adapted to use the indicator api to showup on the panel.

Systray Access :
You may use lot of applications that lands up in Systray. In Unity, you many notices that they are not shown at all. Most of the time , it does not really matter. But if you really wish to make the application show up, you need to add the application to a whitelist. The details are given in the following link  .

Lenses :
It is not very easy to create custom lenses without knowing programming. Some of the currently popular ones are given in the link  . I really like the Gwibber based lens. I am looking for a lens that uses tracker for better file search though.

Tips

This is a random collection of tips that I found useful. Some of them are discussed elsewhere in this post too !

(1) To launch a new instance of an application, middle click the launcher icon . Pressing Shift will also start a new instance.
(2) To move an application another workspace, make sure the application has the focus. Press Super+S and move the application to appropriate workspace. Alternative press Ctrl+Alt+Shift+ Arrow key to move it.
(3) If you like global menu bar and want Chrome to have it, enter “about:flags” in Chrome. Search and enable the “Experimental GNOME menu bar support” .
(4) To access the Unity settings manager, press Alt+F2 and type “about:config”. This directly gives the dialog to change Unity’s settings. To go to Compiz settings,  use “ccsm”. 
(5) If you mess up your Unity settings, try “unity –reset” .
(6) If you want to access special quicklist for an application but do not want the application taking up valuable space in Launcher when not active, there is a way to do that. Create the desktop file and put it in ~/.local/share/applications but do not drag and drop to Launcher. When you start the application, then Unity will automatically show the quicklist options. If the application is closed, the icon also goes away !
(6) If you were a hamster time tracking applet user and lost it in Unity, there is a hack that makes it work ! Check out this link for details http://albertomilone.com/wordpress/?p=502 . This works perfectly for my use !

Resources

There are lot of excellent links that helped me compile this list.
(1)  Ryal Paul’s in depth Unity review : http://arstechnica.com/open-source/reviews/2011/05/riding-the-narwhal-ars-reviews-unity-in-ubuntu-1104.ars .
(2) Power user’s guide to Unity : http://castrojo.tumblr.com/post/4795149014/the-power-users-guide-to-unity
(3) Unity Lens Architecture document : https://wiki.ubuntu.com/Unity/Lenses
(4) Unity place sample  : https://code.launchpad.net/~unity-team/unity-place-sample/unity-place-python

Follow

Get every new post delivered to your Inbox.

Join 78 other followers