chmod 600 foobar") is not enough in such cases as it can still be read by those with super-user access or with physical access to your storage media (e.g. when your laptop gets stolen or you misplace your backup media). It is also ineffective when you use on-line back-up solutions like SkyDrive, Google Docs or Dropbox. Fortunately Linux provides several tools to help you here depending on your needs.
Showing posts with label gyaan. Show all posts
Showing posts with label gyaan. Show all posts
2010-09-07
Protecting Your Privacy on Linux
Some times you need to protect your documents containing sensitive information from prying eyes. Simply enforcing access-control on a document (e.g. "
2009-11-23
Google Chrome on Slackware
Google Chrome has been out for a while now, but only on Windows. There are pre-release Linux builds of Chrome, but they work out-of-the-box only on Ubuntu or Debian. As a Slackware 12.1 user, I couldn't therefore check out this browser and I was too lazy to build it myself. Fortunately for me, it turns out that the available builds can be made to work on Slackware with a little effort. Chrome turns out to be surprisingly usable and fast on Linux. That said, I'm not shifting from Firefox to Chrome yet, at least not right away.
2009-09-23
PDF Manipulation Tools
I wanted to manipulate a few PDF files recently and was on the lookout for suitable tools. More specifically, I wanted to convert a few double-page PDF files (containing two pages of text on a single page) into single-page PDF files. I also wanted to drop some of the pages in order to have the files contain just the text that I was interested in. Fortunately for me, there are several freely-available tools that do the job well.
2008-12-20
Decision Tables
I still see a lot of code with complicated
if-then-else conditions that can be simplified quite a bit by the simple technique of using decision tables. A decision table is a compact yet exhaustive way of encoding conditions and the actions to be taken under those conditions. The rows and columns of a decision table denote the conditions and the cells denote the actions. Since it simplifies complicated conditional logic, it can make your code a lot easier to maintain and a lot less error-prone.
Labels:
gyaan,
programming
2007-10-19
Lossy Marvels
JPEG and MP3 are very popular formats for storing photographs and music respectively. They are both lossy formats and yet achieve amazing compression ratios without a loss of quality that is easily perceptible by normal people. I have always wondered how this is achieved.
The respective technical specifications are unfortunately too complicated to follow for a layman. Purportedly "explanatory" articles elsewhere gloss too much over the important points leaving me quite unsatisfied. I have fortunately come across two articles recently that seem to strike the perfect balance between these extremes.
"The Audiofile: Understanding MP3 Compression" was published in Ars Technica some time back and very nicely explains the compression algorithm behind MP3 as well as shedding some light over some of the apparent idiosyncrasies of this format. "Image Compression: Seeing What's Not There" was published by the American Mathematical Society and does a similar service for JPEG, including its successor JPEG 2000. (Come to think of it, these articles are "lossy" marvels in their own right.)
Now let us see if I can find an article with a similar depth that explains the MPEG video formats.
The respective technical specifications are unfortunately too complicated to follow for a layman. Purportedly "explanatory" articles elsewhere gloss too much over the important points leaving me quite unsatisfied. I have fortunately come across two articles recently that seem to strike the perfect balance between these extremes.
"The Audiofile: Understanding MP3 Compression" was published in Ars Technica some time back and very nicely explains the compression algorithm behind MP3 as well as shedding some light over some of the apparent idiosyncrasies of this format. "Image Compression: Seeing What's Not There" was published by the American Mathematical Society and does a similar service for JPEG, including its successor JPEG 2000. (Come to think of it, these articles are "lossy" marvels in their own right.)
Now let us see if I can find an article with a similar depth that explains the MPEG video formats.
2007-08-20
Calculating Interest Rates
You want to buy that fancy LCD TV that costs Rs 60,000 but you do not have that much money with you. You see an advertisement in a newspaper for the TV from a dealer who offers to sell it to you if you make a down-payment of Rs 10,000 and pay Rs 4,380 every month for one year. You see another advertisement in the newspaper for the same TV from another dealer who offers to sell it to you if you make a down-payment of Rs 20,000 and pay Rs 1,330 every month for three years. How do you calculate the rate of interest each dealer is charging you for what is, in effect, a loan?
In "Calculating EMIs", we derived the formula for calculating the "Equated Monthly Installment" (EMI) on a loan. If "E" represents the EMI, "P" represents the principal amount in the loan, "r" represents the monthly rate of interest (one way of arriving at it is to divide the annual rate of interest, quoted as a percentage, by 1,200) and "n" represents the number of months in the tenure of the loan, then:
E = P × r × (1 + r)n / ((1 + r)n - 1)
In the current example, we know the values for "E", "P" and "n" and wish to calculate "r". Unfortunately it is not that simple to calculate "r" using just the high-school algebra that most of us manage to remember. Fortunately there is a simple algorithm that can help us in this situation.
Let us first rewrite the formula above as an equation:
P × r × (1 + r)n / ((1 + r)n - 1) - E = 0
Our task now is to find the roots of this equation - that is, the values of "r" that will make the left-hand-side (LHS) of this equation evaluate to zero.
To find the roots of a given equation "f(x) = 0", the algorithm in question can be described as follows:
Note that this is just a binary search algorithm. By "close enough to zero", we mean that the absolute value of "f(c)" is less than some value, usually called "epsilon", that can be as small as we please. The algorithm given above can be rewritten as a function in a pseudo-language as follows:
You can implement this in your favourite programming language along with a function that calculates the LHS of the equation given earlier. You can choose a value of "epsilon" according to your preference - the smaller the value of "epsilon", the more accurate is the result and the longer it takes to compute it. The time taken for the computation is also affected by how wide is the range between "a" and "b". Note that Newton's method is a much faster way of computing the roots of such equations, though it involves calculating derivatives.
How do you arrive at the values for "a" and "b"? This differs for each function. For our example, we can start with a low guess of "0.001%" ("0%" gives an undefined result) as the annual rate of interest and a high guess of "100%" and this gives us a negative and a positive value for the LHS respectively. With an "epsilon" of "0.00001", a C programme computes the answer in around 25 iterations.
In our example, the first dealer is offering us an effective loan of Rs 50,000 for 12 months with an EMI of Rs 4,380 and the effective annual rate of interest comes to about 9.32%. The second dealer is offering us an effective loan of Rs 40,000 for 36 months with an EMI of Rs 1,330 and the effective annual rate of interest comes to about 12.08%. In terms of the interest rates being charged by the dealers, you should now be able to tell that the first dealer has a better proposition for you when compared to the second dealer.
In "Calculating EMIs", we derived the formula for calculating the "Equated Monthly Installment" (EMI) on a loan. If "E" represents the EMI, "P" represents the principal amount in the loan, "r" represents the monthly rate of interest (one way of arriving at it is to divide the annual rate of interest, quoted as a percentage, by 1,200) and "n" represents the number of months in the tenure of the loan, then:
E = P × r × (1 + r)n / ((1 + r)n - 1)
In the current example, we know the values for "E", "P" and "n" and wish to calculate "r". Unfortunately it is not that simple to calculate "r" using just the high-school algebra that most of us manage to remember. Fortunately there is a simple algorithm that can help us in this situation.
Let us first rewrite the formula above as an equation:
P × r × (1 + r)n / ((1 + r)n - 1) - E = 0
Our task now is to find the roots of this equation - that is, the values of "r" that will make the left-hand-side (LHS) of this equation evaluate to zero.
To find the roots of a given equation "f(x) = 0", the algorithm in question can be described as follows:
- Find a value "a" for which "f(a)" evaluates to a negative value.
- Find a value "b" for which "f(b)" evaluates to a positive value.
- Let "c" be the average of "a" and "b".
- If "f(c)" is close enough to zero, "c" is the desired root.
- Otherwise, if "f(c)" is a negative value, substitute "c" for "a" and repeat the procedure from step #3 and if "f(c)" is a positive value, substitute "c" for "b" and repeat the procedure from step #3.
Note that this is just a binary search algorithm. By "close enough to zero", we mean that the absolute value of "f(c)" is less than some value, usually called "epsilon", that can be as small as we please. The algorithm given above can be rewritten as a function in a pseudo-language as follows:
guessRoot( f, a, b)
{
c := (a + b) / 2;
if( absoluteValue( f( c)) < EPSILON)
return c;
else if( f(c) < 0)
return guessRoot( f, c, b);
else
return guessRoot( f, a, c);
}
You can implement this in your favourite programming language along with a function that calculates the LHS of the equation given earlier. You can choose a value of "epsilon" according to your preference - the smaller the value of "epsilon", the more accurate is the result and the longer it takes to compute it. The time taken for the computation is also affected by how wide is the range between "a" and "b". Note that Newton's method is a much faster way of computing the roots of such equations, though it involves calculating derivatives.
How do you arrive at the values for "a" and "b"? This differs for each function. For our example, we can start with a low guess of "0.001%" ("0%" gives an undefined result) as the annual rate of interest and a high guess of "100%" and this gives us a negative and a positive value for the LHS respectively. With an "epsilon" of "0.00001", a C programme computes the answer in around 25 iterations.
In our example, the first dealer is offering us an effective loan of Rs 50,000 for 12 months with an EMI of Rs 4,380 and the effective annual rate of interest comes to about 9.32%. The second dealer is offering us an effective loan of Rs 40,000 for 36 months with an EMI of Rs 1,330 and the effective annual rate of interest comes to about 12.08%. In terms of the interest rates being charged by the dealers, you should now be able to tell that the first dealer has a better proposition for you when compared to the second dealer.
Labels:
economics,
gyaan,
math,
programming
2007-06-23
Data Visualisation with Gnuplot
Visualisation of data using charts and other types of plots is immensely helpful in getting a feel for it without carrying out detailed analyses. Gnuplot is a freely-available tool for data visualisation that is also very simple to use. The article "Visualize your data with gnuplot" is a nice introduction to this tool. Gnuplot proved to be quite handy for me recently.
I wanted to find out whether the Unit Price of a particular fund varies in line with the popular equity market indices in India, the NSE S&P CNX Nifty and the BSE Sensex. The current values of these indices are always readily available in the newspapers and on television channels, while I have to use the web-site of the fund to get its current Unit Price. If the Unit Price of the fund varied in line with the values of the equity market indices, it would save me some effort in determining its current worth.
The portfolio of the fund in question is almost entirely based on equities. It holds the shares of some of the biggest and the most stable companies across a variety of industry sectors. It was therefore reasonable to suspect that its Unit Price would vary in line with the values of the indices. However, it is not as diversified as the indices and it might not have invested across sectors in the same proportion as that represented by either of the indices.
It was easy to obtain the historical closing prices of the two indices and the Unit Prices of the fund. To keep things simple, I only considered the current month for making this comparison. To simplify things further and to improve the visualisation, I normalised the first value in each series to "100" by scaling all the values appropriately. (This is a technique that I have often seen put to good use in The Economist.)
Using Gnuplot, I obtained the following chart:

This gave me the desired answer right away!
In case you're curious, here are the Gnuplot commands I used for creating the chart above:
By the way "Junk Charts" seems to be a blog devoted to criticising charts that appear in various magazines and web-sites in general and in The Economist in particular.
I wanted to find out whether the Unit Price of a particular fund varies in line with the popular equity market indices in India, the NSE S&P CNX Nifty and the BSE Sensex. The current values of these indices are always readily available in the newspapers and on television channels, while I have to use the web-site of the fund to get its current Unit Price. If the Unit Price of the fund varied in line with the values of the equity market indices, it would save me some effort in determining its current worth.
The portfolio of the fund in question is almost entirely based on equities. It holds the shares of some of the biggest and the most stable companies across a variety of industry sectors. It was therefore reasonable to suspect that its Unit Price would vary in line with the values of the indices. However, it is not as diversified as the indices and it might not have invested across sectors in the same proportion as that represented by either of the indices.
It was easy to obtain the historical closing prices of the two indices and the Unit Prices of the fund. To keep things simple, I only considered the current month for making this comparison. To simplify things further and to improve the visualisation, I normalised the first value in each series to "100" by scaling all the values appropriately. (This is a technique that I have often seen put to good use in The Economist.)
Using Gnuplot, I obtained the following chart:

This gave me the desired answer right away!
In case you're curious, here are the Gnuplot commands I used for creating the chart above:
# We want PNG output.
set terminal png
set output "plot.png"
# Specify how and where the key (legend) for the chart should
# appear.
set key bottom right
set key width 2 box
# Tweak the look of the chart.
set title "Fluctuations in Unit Prices Relative to Market Indices"
set xlabel "June 2007"
set ylabel "Normalised Value"
set grid
# The data on the X axis represent time values.
set format x "%d"
set xtics "01-Jun-2007", 3600*24
set xdata time
set timefmt "%d-%b-%y"
set xrange ["01-Jun-2007":"22-Jun-2007"]
set yrange [95:100]
# Plot the chart using data files normalising the values in
# each case.
plot \
'nifty.dat' using 1:($5)/42.9705 \
title 'NIFTY' with lines linewidth 2, \
'sensex.dat' using 1:($7)/145.7075 \
title 'SENSEX' with lines linewidth 2, \
'fund.dat' using 1:($2)*100.00/57.0337 \
title 'FUND' with lines linewidth 2
By the way "Junk Charts" seems to be a blog devoted to criticising charts that appear in various magazines and web-sites in general and in The Economist in particular.
2007-05-26
Indic Scripts and Linux
If you have the fonts for Indic scripts (for example, the Lohit fonts), Firefox on Linux is able to display the Devanagari text on sites like BBC Hindi and Google News in Hindi. (Devanagari is the primary writing system for languages like Hindi, Sanskrit, etc.) However, if you are using the builds released by mozilla.com, you would notice that the matras (diacritics) are not applied properly to form the correct ligatures. For example, the word "हिन्दी" ("Hindi") itself is not rendered properly. Konqueror does not suffer from such problems.
It turns out that Firefox does not support complex text layout because it doesn't use Pango in the officially-released builds (Firefox 3 will support it by default). You have to either compile it yourself from the source and enable the support for Pango by using --enable-pango, or use a build that has Pango enabled - for example, the builds provided by the Fedora Project. (Setting the environment variable MOZ_ENABLE_PANGO to "1" had no effect for me with Firefox 2.0.0.3.)
On Fedora Core 6 (FC6), it is very simple to get this working:
By the way, I recently came across Omniglot, a site about the writing systems of almost all known human languages, existing or extinct, naturally-evolved or artificially-created. I found it extremely fascinating and insightful. For example, I did not know that Devanagari was not considered to be an "alphabet" but an "abiguda". Check out the International Phonetic Alphabet (IPA) that can represent almost all spoken languages. How about Loglan (and its freer derivative, Lojban) that claims to be a "logical" language? (I first came across the IPA on Wikipedia, where it is used to provide the pronunciation for some terms. xkcd is where I first read about Lojban.)
It turns out that Firefox does not support complex text layout because it doesn't use Pango in the officially-released builds (Firefox 3 will support it by default). You have to either compile it yourself from the source and enable the support for Pango by using --enable-pango, or use a build that has Pango enabled - for example, the builds provided by the Fedora Project. (Setting the environment variable MOZ_ENABLE_PANGO to "1" had no effect for me with Firefox 2.0.0.3.)
On Fedora Core 6 (FC6), it is very simple to get this working:
- Install the fonts for the Indic scripts you are interested in. For example, "sudo yum install fonts-hindi" , "sudo yum install fonts-malayalam", "sudo yum install fonts-kannada", etc.
- Install a Firefox build for Fedora using "sudo yum install firefox". Note that FC6 installs Firefox 1.5 by default - if you prefer Firefox 2.0 instead, you can install it using "sudo yum --enablerepo=development install firefox".
By the way, I recently came across Omniglot, a site about the writing systems of almost all known human languages, existing or extinct, naturally-evolved or artificially-created. I found it extremely fascinating and insightful. For example, I did not know that Devanagari was not considered to be an "alphabet" but an "abiguda". Check out the International Phonetic Alphabet (IPA) that can represent almost all spoken languages. How about Loglan (and its freer derivative, Lojban) that claims to be a "logical" language? (I first came across the IPA on Wikipedia, where it is used to provide the pronunciation for some terms. xkcd is where I first read about Lojban.)
2007-04-13
Running Java Applets in Internet Explorer on Linux
One of the unfortunate things about the current state of the internet is that some web sites refuse to work with anything other than Internet Explorer (IE). Some of these also require you to run Adobe Flash Player and/or Sun's JVM within IE. Most of these sites can be happily avoided, but some of them just can't, especially when they run important applications within a corporate intranet. This can seriously dampen the enthusiasm of people willing to try out Linux as their primary desktop.
WINE allows you to run many a Windows application natively on Linux, including IE (albeit with a few tweaks). IEs4Linux makes it really simple to install one or more versions of IE on your Linux system, something that is very difficult on Windows itself, if not impossible! You can also view Flash content and run Java applets within such an IE. The latter requires a bit of tweaking with the current release of WINE (0.9.34), if you want to use Sun's JVM instead of that provided by Microsoft, as explained below.
Install a version of IE using IEs4Linux into, say, $HOME/.ies4linux (the default). Assuming that you choose to install only IE 6.0 SP1, IEs4Linux will create a WINE "bottle" named "ie6" within "$HOME/.ies4linux", separate from your regular WINE bottle (which is present by default in "$HOME/.wine"). IEs4Linux can also automatically install Adobe Flash Player along with IE. Run IE at least once to verify that it is working.
Now install the Java Runtime Environment (JRE) making sure that you correctly specify the WINEPREFIX environment variable by pointing it to the IE WINE bottle. For example:
For some reason, RegUtils.dll is not correctly copied during the installation of the JRE and therefore you must copy this file from a Windows machine that has exactly the same version of the JRE. This file is usually found in the "bin" sub-folder of the JRE installation folder. Without this file, the Java Control Panel applet will not be able to register Sun's JRE with IE.
Now run the "javacpl" programme found in the "bin" sub-folder of the JRE installation folder. With the current WINE release, this would cause your display to flicker or black out since it does not yet fully support DirectX-based acceleration (but where the maximum development effort currently seems to be directed). To avoid this, you can also invoke the Java Control Panel applet alternatively like this in the "lib" sub-folder of the JRE installation folder:
Go to the "Advanced" tab and uncheck the check-box for "<APPLET> tag support" for "Internet Explorer", apply your changes and close the applet. Restart the applet once again and this time check the check-box, apply your changes and close the applet. You should now be able to see Java applets within IE using Sun's JRE.
If you wish to avoid the flicker/blacking-out of the display whenever you run Java GUI applications, you can either pass the JVM option -Dsun.java2d.noddraw to Java applications and applets or disable DirectX-based acceleration for Java 2D completely by looking for a registry key like:
and setting the value of "DXAcceleration" to "0". (WINE includes a "regedit" programme just like its Windows counterpart.)
With IE, Flash and Java Applets with you, you are now ready to savour the worst of the internet first-hand on your Linux desktop instead of hearing about it from your friends who use Windows.
(The method outlined here seems to work with WINE 0.9.34 on Fedora Core 6, IE 6.0 SP1 as installed by IEs4Linux 2.0.5 and Sun's JRE 1.5.0_11 - your mileage might vary.)
Update (2007-07-03): With WINE 0.9.40 on Fedora 7 and Sun's JRE 1.5.0_12, I don't see the problem with "RegUtils.dll" and the JRE installs just fine. Another way of avoiding the blackening of the entire desktop while using Java Swing applications (and for getting a much more accurate display) is to enable a "virtual desktop" that will hold your Windows applications. To do this, invoke "winecfg", select "Enable a virtual desktop" under the "Graphics" tab and provide a size for the virtual desktop (say, 800 by 600 or 1024 by 768).
Update (2007-10-31): The default location used by IEs4Linux is $HOME/.ies4linux (notice the period in front of the directory name). Changed the post to use this location instead as people were getting confused by the location used earlier.
WINE allows you to run many a Windows application natively on Linux, including IE (albeit with a few tweaks). IEs4Linux makes it really simple to install one or more versions of IE on your Linux system, something that is very difficult on Windows itself, if not impossible! You can also view Flash content and run Java applets within such an IE. The latter requires a bit of tweaking with the current release of WINE (0.9.34), if you want to use Sun's JVM instead of that provided by Microsoft, as explained below.
Install a version of IE using IEs4Linux into, say, $HOME/.ies4linux (the default). Assuming that you choose to install only IE 6.0 SP1, IEs4Linux will create a WINE "bottle" named "ie6" within "$HOME/.ies4linux", separate from your regular WINE bottle (which is present by default in "$HOME/.wine"). IEs4Linux can also automatically install Adobe Flash Player along with IE. Run IE at least once to verify that it is working.
Now install the Java Runtime Environment (JRE) making sure that you correctly specify the WINEPREFIX environment variable by pointing it to the IE WINE bottle. For example:
export WINEPREFIX=$HOME/.ies4linux/ie6
wine jre-1_5_0_11-windows-i586-p.exe
For some reason, RegUtils.dll is not correctly copied during the installation of the JRE and therefore you must copy this file from a Windows machine that has exactly the same version of the JRE. This file is usually found in the "bin" sub-folder of the JRE installation folder. Without this file, the Java Control Panel applet will not be able to register Sun's JRE with IE.
Now run the "javacpl" programme found in the "bin" sub-folder of the JRE installation folder. With the current WINE release, this would cause your display to flicker or black out since it does not yet fully support DirectX-based acceleration (but where the maximum development effort currently seems to be directed). To avoid this, you can also invoke the Java Control Panel applet alternatively like this in the "lib" sub-folder of the JRE installation folder:
java -classpath deploy.jar \
-Dsun.java2d.noddraw com.sun.deploy.panel.ControlPanel
Go to the "Advanced" tab and uncheck the check-box for "<APPLET> tag support" for "Internet Explorer", apply your changes and close the applet. Restart the applet once again and this time check the check-box, apply your changes and close the applet. You should now be able to see Java applets within IE using Sun's JRE.
If you wish to avoid the flicker/blacking-out of the display whenever you run Java GUI applications, you can either pass the JVM option -Dsun.java2d.noddraw to Java applications and applets or disable DirectX-based acceleration for Java 2D completely by looking for a registry key like:
HKEY_CURRENT_USER\Software\JavaSoft\Java2D\1.5.0_11
and setting the value of "DXAcceleration" to "0". (WINE includes a "regedit" programme just like its Windows counterpart.)
With IE, Flash and Java Applets with you, you are now ready to savour the worst of the internet first-hand on your Linux desktop instead of hearing about it from your friends who use Windows.
(The method outlined here seems to work with WINE 0.9.34 on Fedora Core 6, IE 6.0 SP1 as installed by IEs4Linux 2.0.5 and Sun's JRE 1.5.0_11 - your mileage might vary.)
Update (2007-07-03): With WINE 0.9.40 on Fedora 7 and Sun's JRE 1.5.0_12, I don't see the problem with "RegUtils.dll" and the JRE installs just fine. Another way of avoiding the blackening of the entire desktop while using Java Swing applications (and for getting a much more accurate display) is to enable a "virtual desktop" that will hold your Windows applications. To do this, invoke "winecfg", select "Enable a virtual desktop" under the "Graphics" tab and provide a size for the virtual desktop (say, 800 by 600 or 1024 by 768).
Update (2007-10-31): The default location used by IEs4Linux is $HOME/.ies4linux (notice the period in front of the directory name). Changed the post to use this location instead as people were getting confused by the location used earlier.
2007-03-11
Investing For Retirement
(Note: This post might not be of interest to those not from India.)
Most of us do not even think about planning for retirement until we reach the age of 30. Some of us "live for the moment" and don't care for the future, some of us feel uncomfortable thinking about retirement and pretend like the proverbial cat that closing our eyes to the problem will make it go away and some of us just do not know how to assess our financial requirements three decades into the future.
Unfortunately for us, there is not much of a government-provided social security in India for old folks, we cannot realistically expect our children to take care of all our expenses, inflation constantly lessens the value of our savings and interests on assured-return investments (fixed-deposits, EPFs, etc.) keep falling. We must have some idea of our needs at the time of our retirement and know how much to invest now to be able to afford the same lifestyle that we are currently used to.
The good news is that we can use basic mathematics to calculate these figures. We will make use of two equations. The first equation (call it "E1") tells us the final amount "S" that an initial amount "P" grows to if it grows at a compounded rate of "r" over "n" years:
The second equation (call it "E2") tells us the final amount "S" that a regular annual investment of "P" over "n" years gives if it grows at a compounded rate of "r":
Note that since the rates are usually quoted as percentages, you need to divide them by 100 to get the value of "r" usable in these equations. For example, a quoted rate of 8% translates to "r" equal to 0.08.
Now assume that you are aged 30 years, plan to retire at the age of 60 years, have a montly expenditure of 20,000 rupees and the rate of inflation is about 5% on the average. Using E1, you can see that at the time of your retirement 30 years hence, your monthly expenditure would become about 86,438.85 rupees simply because of inflation! That translates to about 10,37,266 rupees in annual expenditure. With old age come many an ailment for which you would need to spend money - at about 1,00,000 rupees per year at today's rates, you would need about 4,32,194 rupees at the time of your retirement to meet medical expenses. So you would need an annual income of at least 14,69,460 rupees at the time of your retirement just to sustain your current lifestyle and cope with the inevitable medical expenses!
How will you generate an income like this at that time? It is very likely that your appetite for risk would have considerably diminished at that time and you would only be willing to invest for assured-returns and thus lower rates of interest, say, about 5%. This in turn means that you would need a sum of 2,93,89,200 rupees (5% of which is the amount you need per year) at the time of your retirement. You need to have raised about 3 crore rupees by the time you retire just to be able to afford your current lifestyle!
To raise this kind of money, you either need to invest a certain amount annually till the time you retire or do a one-time investment. If you assume an annual return of 8% on your investments, you either need to invest about 2,59,431 rupees annually for the next 30 years (using E2) or about 29,20,620 rupees at a single shot (using E1). If you assume a more aggressive (though riskier) annual return of 15% on your investments, the amounts change to about 67,601 rupees and about 4,43,867 rupees respectively.
If you had started at the age of 25 years, you would have had 35 years to raise the money. At a per-annum return of 8%, you would have either invested about 1,70,533 rupees annually or about 19,87,725 rupees at a single shot. At a per-annum return of 15%, these figures become about 33,352 rupees and about 2,20,680 rupees respectively.
If you postpone investing for your retirement by another five years, you would have 25 years to raise the money. At a per-annum return of 8%, you would need to either invest about 4,02,008 rupees annually or about 42,91,349 rupees at a single shot. At a per-annum return of 15%, these figures become about 1,38,112 rupees and about 8,92,774 rupees respectively.
So the earlier you start investing for your retirement, the better it is for you. The folks at Personalfn.com have a report titled "Retirement Planning and You" that provides a more detailed analysis of this situation as well as the available investment options suitable for retirement planning.
Of course, these are simplified calculations. They do not take into account the fact that you will very likely have to pay income tax on the returns from this investment. They also do not take into account the fact that because of inflation, you would need slightly more and more every year after you retire instead of the fixed amount assumed here. Hopefully the average rate of inflation for India for the next 30 years will be less than the 5% assumed here.
Most of us do not even think about planning for retirement until we reach the age of 30. Some of us "live for the moment" and don't care for the future, some of us feel uncomfortable thinking about retirement and pretend like the proverbial cat that closing our eyes to the problem will make it go away and some of us just do not know how to assess our financial requirements three decades into the future.
Unfortunately for us, there is not much of a government-provided social security in India for old folks, we cannot realistically expect our children to take care of all our expenses, inflation constantly lessens the value of our savings and interests on assured-return investments (fixed-deposits, EPFs, etc.) keep falling. We must have some idea of our needs at the time of our retirement and know how much to invest now to be able to afford the same lifestyle that we are currently used to.
The good news is that we can use basic mathematics to calculate these figures. We will make use of two equations. The first equation (call it "E1") tells us the final amount "S" that an initial amount "P" grows to if it grows at a compounded rate of "r" over "n" years:
S = P × (1 + r)n
The second equation (call it "E2") tells us the final amount "S" that a regular annual investment of "P" over "n" years gives if it grows at a compounded rate of "r":
S = P × ((1 + r)n - 1) / r
Note that since the rates are usually quoted as percentages, you need to divide them by 100 to get the value of "r" usable in these equations. For example, a quoted rate of 8% translates to "r" equal to 0.08.
Now assume that you are aged 30 years, plan to retire at the age of 60 years, have a montly expenditure of 20,000 rupees and the rate of inflation is about 5% on the average. Using E1, you can see that at the time of your retirement 30 years hence, your monthly expenditure would become about 86,438.85 rupees simply because of inflation! That translates to about 10,37,266 rupees in annual expenditure. With old age come many an ailment for which you would need to spend money - at about 1,00,000 rupees per year at today's rates, you would need about 4,32,194 rupees at the time of your retirement to meet medical expenses. So you would need an annual income of at least 14,69,460 rupees at the time of your retirement just to sustain your current lifestyle and cope with the inevitable medical expenses!
How will you generate an income like this at that time? It is very likely that your appetite for risk would have considerably diminished at that time and you would only be willing to invest for assured-returns and thus lower rates of interest, say, about 5%. This in turn means that you would need a sum of 2,93,89,200 rupees (5% of which is the amount you need per year) at the time of your retirement. You need to have raised about 3 crore rupees by the time you retire just to be able to afford your current lifestyle!
To raise this kind of money, you either need to invest a certain amount annually till the time you retire or do a one-time investment. If you assume an annual return of 8% on your investments, you either need to invest about 2,59,431 rupees annually for the next 30 years (using E2) or about 29,20,620 rupees at a single shot (using E1). If you assume a more aggressive (though riskier) annual return of 15% on your investments, the amounts change to about 67,601 rupees and about 4,43,867 rupees respectively.
If you had started at the age of 25 years, you would have had 35 years to raise the money. At a per-annum return of 8%, you would have either invested about 1,70,533 rupees annually or about 19,87,725 rupees at a single shot. At a per-annum return of 15%, these figures become about 33,352 rupees and about 2,20,680 rupees respectively.
If you postpone investing for your retirement by another five years, you would have 25 years to raise the money. At a per-annum return of 8%, you would need to either invest about 4,02,008 rupees annually or about 42,91,349 rupees at a single shot. At a per-annum return of 15%, these figures become about 1,38,112 rupees and about 8,92,774 rupees respectively.
So the earlier you start investing for your retirement, the better it is for you. The folks at Personalfn.com have a report titled "Retirement Planning and You" that provides a more detailed analysis of this situation as well as the available investment options suitable for retirement planning.
Of course, these are simplified calculations. They do not take into account the fact that you will very likely have to pay income tax on the returns from this investment. They also do not take into account the fact that because of inflation, you would need slightly more and more every year after you retire instead of the fixed amount assumed here. Hopefully the average rate of inflation for India for the next 30 years will be less than the 5% assumed here.
2007-01-21
"Concepts, Techniques, and Models of Computer Programming"
I just finished reading "Concepts, Techniques, and Models of Computer Programming" by Peter Van Roy and Seif Haridi. If you are the kind of person who thinks that "The Art of Computer Programming" and "Structure and Interpretation of Computer Programs" are good books, then you owe it to yourself to check this book out.
There is a slightly-dated version of the book available online (PDF, 3.4 MB), if you want to preview some of the content before buying it. There is also an Indian edition of the book published by Prentice Hall of India (ISBN: 81-203-2685-7) and priced at Rs 450. The book's web site links to some reviews and you can also read my review of the book.
There is a slightly-dated version of the book available online (PDF, 3.4 MB), if you want to preview some of the content before buying it. There is also an Indian edition of the book published by Prentice Hall of India (ISBN: 81-203-2685-7) and priced at Rs 450. The book's web site links to some reviews and you can also read my review of the book.
Labels:
books,
gyaan,
programming
2007-01-20
Local Variables in Java
The other day I was reviewing some Java code written by a colleague. I noticed that he was in the habit of declaring all the variables used by a method at the beginning of the method body rather than in the places where they were first used. I pointed out that declaring a variable only when it is first required makes the code more readable.
While he agreed to change the style of his code, he was still reluctant to move the declaration of a variable used only within a loop from outside it to inside it. For example, he was reluctant to change:
to:
He believed that only one variable is created in the former case while 10 variables are created in the latter - clearly it is more efficient to declare a single variable outside the loop and keep reusing it inside the loop!
I then pointed out the section in the JVM specification that says that a JVM uses a fixed-size array for storing the values of local variables used in a method and each local variable maps to an index in this array. A Java compiler calculates the size of this array during the compilation of a method and declares it in the generated bytecode for the method.
Since he was still sceptical, I compiled both the variants to bytecode, used

He was finally convinced.
On the other extreme, I have another colleague who is in the masochistic habit of introducing new scopes to isolate the local variables used only in a section of a method's body. That is, something like:
While he agreed to change the style of his code, he was still reluctant to move the declaration of a variable used only within a loop from outside it to inside it. For example, he was reluctant to change:
String s;
for( int i = 0; i < 10; i++)
{
s = String.valueOf( i);
}
to:
for( int i = 0; i < 10; i++)
{
String s = String.valueOf( i);
}
He believed that only one variable is created in the former case while 10 variables are created in the latter - clearly it is more efficient to declare a single variable outside the loop and keep reusing it inside the loop!
I then pointed out the section in the JVM specification that says that a JVM uses a fixed-size array for storing the values of local variables used in a method and each local variable maps to an index in this array. A Java compiler calculates the size of this array during the compilation of a method and declares it in the generated bytecode for the method.
Since he was still sceptical, I compiled both the variants to bytecode, used
javap -c to produce the dissassembled code and used diff to show that the generated code was the same in both the cases (except for the indices used for s and i). I then used a simple modification of using the JVM Emulator Applet written by Bill Venners as a standalone application to show the bytecode variants in execution and demonstrate that the size of the local variables array really remains constant throughout.
He was finally convinced.
On the other extreme, I have another colleague who is in the masochistic habit of introducing new scopes to isolate the local variables used only in a section of a method's body. That is, something like:
{
Foo x = wombat.snafu( );
// Use x here.
...
}
{
Bar y = new Bar( a, b, c);
// Use y here.
...
}
Labels:
gyaan,
programming
2007-01-11
Generics in Java and Return Types
Consider a class
While the following is allowed:
the following is not:
In the first case, callers expect to get an object implementing the interface
Consider what happens if the compiler were to allow such code to compile. Callers can then add objects of another class
A better way to define the second case is:
(You can also return an
Thanks to Steve for clearing up my muddied thinking.
C that implements an interface I.While the following is allowed:
I foo( )
{
return new C( );
}
the following is not:
ArrayList<I> foo( )
{
return new ArrayList<C>( );
}
In the first case, callers expect to get an object implementing the interface
I and therefore it is correct for foo( ) to return an object of class C. In the second case, callers expect to get an ArrayList containing objects implementing the interface I and therefore it should again be correct for foo( ) to return an ArrayList containing objects of class C, right?Consider what happens if the compiler were to allow such code to compile. Callers can then add objects of another class
X, which also implements the interface I, to the returned ArrayList with the result that the original ArrayList, which is only supposed to contain objects of class C, now also contains objects of an incompatible class X!A better way to define the second case is:
ArrayList<? extends I> foo( )
{
return new ArrayList<C>( );
}
(You can also return an
ArrayList<I> instead, but that loosens up the definition of the returned object.)Thanks to Steve for clearing up my muddied thinking.
Labels:
gyaan,
programming
2006-09-15
Terminal Sickness
I have a simple requirement: I want my programme to be able to spawn another programme on the same machine and talk to it using the simplest possible means of communication, that is, via the spawned programme's standard input and output streams.
The driving programme is written in C and the spawned programme could have been written in any programming language (hence the need for using as simple a form of communication as possible). The messages exchanged between the programmes are terminated by newline characters.
This should have been a relatively simple task with code somewhat like the following (error-handling has been omitted for clarity):
However, running this with a test programme (written in C) revealed a problem: messages sent by the spawned programme were not reaching the driving programme!
The reason is that
My knee-jerk reaction was to insert a call to
A possible solution is to mandate that the spawned programme force a line-buffered mode for
So it seems the only solution left is to use a pseudo terminal to fool the spawned programme's runtime into thinking that it is attached to a terminal. A glance through the sample code given in my copy of Stevens's "Advanced Programming in the UNIX Environment" reveals that some ugly code is needed to make it work properly. It also makes my programme even less portable than it currently is. I am therefore a bit loath to take this approach.
Does anyone know of a better solution to this problem?
Update (2006-09-16): Thanks to all who responded. Using a pseudo terminal solved my problem. The
One of the problems with using a pseudo terminal that initially stumped me was the fact that the spawned programme seemed to send the driver programme all the messages it was sent by the latter in addition to sending messages of its own. It took me a while to realise that this was because of terminal echo. Switching terminal echo off resolved this problem.
Update (2007-10-18): Here is the relevant portion of the programme that finally worked for me:
The driving programme is written in C and the spawned programme could have been written in any programming language (hence the need for using as simple a form of communication as possible). The messages exchanged between the programmes are terminated by newline characters.
This should have been a relatively simple task with code somewhat like the following (error-handling has been omitted for clarity):
/* File descriptors for pipes connecting driver and inferior
processes. */
int drv2inf[2], inf2drv[2];
/* Create communication pipes. */
pipe (drv2inf); pipe (inf2drv);
if (fork () == 0) {
/* In child process - close "other" ends of pipes first. */
close (drv2inf[1]); close (inf2drv[0]);
/* Redirect stdin and stdout. */
close (0); dup (drv2inf[0]); close (drv2inf[0]);
close (1); dup (inf2drv[1]); close (inf2drv[1]);
/* Spawn inferior process - should never return. */
char *args[] = { prog, NULL};
execv (prog, args);
} else {
/* In parent process - close "other" ends of pipes first. */
close (drv2inf[0]); close (inf2drv[1]);
}
However, running this with a test programme (written in C) revealed a problem: messages sent by the spawned programme were not reaching the driving programme!
The reason is that
stdout is normally "line-buffered" - i.e. output is buffered till either the buffer becomes full or till a newline character is encountered. When stdout is not connected to a terminal however (for example, when output is redirected to a file), it becomes "block-buffered" - i.e. output is buffered till the buffer becomes full. Of course, you can force the output buffer to be flushed out using fflush() at any time. This behaviour of the C runtime is a reasonable tradeoff that seeks to optimise throughput and response under different conditions. In my case the C runtime determined that stdout was not connected to a terminal and therefore should be block-buffered. The messages sent by the spawned process were therefore still sitting in its output buffer while the driving process waited to hear from it.My knee-jerk reaction was to insert a call to
setvbuf() with a mode of _IOLBF just before the call to execv() in order to force a line-buffered mode for the spawned process. Of course, this does not work for the simple reason that the C runtime is re-initialised after the call to execv().A possible solution is to mandate that the spawned programme force a line-buffered mode for
stdout using something like setvbuf(). Another solution is to mandate that the spawned programme always use the equivalent of fflush() to flush its output buffers after every message. However, these just work around the problem rather than solving it. I also do not want to place unnecessary restrictions on spawned programmes.So it seems the only solution left is to use a pseudo terminal to fool the spawned programme's runtime into thinking that it is attached to a terminal. A glance through the sample code given in my copy of Stevens's "Advanced Programming in the UNIX Environment" reveals that some ugly code is needed to make it work properly. It also makes my programme even less portable than it currently is. I am therefore a bit loath to take this approach.
Does anyone know of a better solution to this problem?
Update (2006-09-16): Thanks to all who responded. Using a pseudo terminal solved my problem. The
forkpty() function from libutil provided by the GNU C Library (thank you Scott) conveniently wraps everything I need into a single function. The only problem is that it also redirects stderr to the newly-created pseudo terminal and this robs the spawned programme of a simple method of debugging. To work around this issue, I had to save the stderr stream using a dup() before calling forkpty() and then restore it using a dup2() in the child process.One of the problems with using a pseudo terminal that initially stumped me was the fact that the spawned programme seemed to send the driver programme all the messages it was sent by the latter in addition to sending messages of its own. It took me a while to realise that this was because of terminal echo. Switching terminal echo off resolved this problem.
Update (2007-10-18): Here is the relevant portion of the programme that finally worked for me:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <termios.h>
#include <pty.h>
/* Spawns a process with redirected standard input and output
streams. ARGV is the set of arguments for the process,
terminated by a NULL element. The first element of ARGV
should be the command to invoke the process.
Returns a file descriptor that can be used to communicate
with the process. */
int
spawn (char *argv[]) {
int ret_fd = -1;
/* Find out if the intended programme really exists and
is accessible. */
struct stat stat_buf;
if (stat (argv[0], &stat_buf) != 0) {
perror ("ERROR accessing programme");
return -1;
}
/* Save the standard error stream. */
int saved_stderr = dup (STDERR_FILENO);
if (saved_stderr < 0) {
perror ("ERROR saving old STDERR");
return -1;
}
/* Create a pseudo terminal and fork a process attached
to it. */
pid_t pid = forkpty (&ret_fd, NULL, NULL, NULL);
if (pid == 0) {
/* Inside the child process. */
/* Ensure that terminal echo is switched off so that we
do not get back from the spawned process the same
messages that we have sent it. */
struct termios orig_termios;
if (tcgetattr (STDIN_FILENO, &orig_termios) < 0) {
perror ("ERROR getting current terminal's attributes");
return -1;
}
orig_termios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
orig_termios.c_oflag &= ~(ONLCR);
if (tcsetattr (STDIN_FILENO, TCSANOW, &orig_termios) < 0) {
perror ("ERROR setting current terminal's attributes");
return -1;
}
/* Restore stderr. */
if (dup2 (saved_stderr, STDERR_FILENO) < 0) {
perror ("ERROR restoring STDERR");
return -1;
}
/* Now spawn the intended programme. */
if (execv (argv[0], argv)) {
/* execv() should not return. */
perror ("ERROR spawning programme");
return -1;
}
} else if (pid < 0) {
perror ("ERROR spawning programme");
return -1;
} else {
close (saved_stderr);
}
return ret_fd;
}
Labels:
gyaan,
programming
2006-08-17
Good Math, Bad Math
I came to know of Mark Chu-Carroll's "Good Math, Bad Math" blog via a post in "Programming Musings", the blog of José Antonio Ortega Ruiz. Mark writes mostly about mathematics, the theoretical foundations of programming, debunking bad use of mathematics in popular and not-so-popular media, etc.
I find many of Mark's articles very interesting to read, though many others go way over the top of my head. Some of his recent articles that I found really interesting include one that shows how absurd arithmetic with Roman numerals can be, one on Poincaré Conjecture, some in the "Friday Pathological Programming Language" series, one on zero, one on i, one on e, one on φ, one on Ω, one on π, one on continued fractions, etc. The old home for the GM/BM blog contains many more interesting and insightful articles on math and programming theory. What an amazing guy!
Highly recommended.
I find many of Mark's articles very interesting to read, though many others go way over the top of my head. Some of his recent articles that I found really interesting include one that shows how absurd arithmetic with Roman numerals can be, one on Poincaré Conjecture, some in the "Friday Pathological Programming Language" series, one on zero, one on i, one on e, one on φ, one on Ω, one on π, one on continued fractions, etc. The old home for the GM/BM blog contains many more interesting and insightful articles on math and programming theory. What an amazing guy!
Highly recommended.
Labels:
gyaan
2006-08-03
Optimising Linker Load Times
Last week's LWN.net Weekly Edition had a nice article on optimising linker load times by John Richard Moser. It was based on some recent features added to the linker in GNU binutils. It explains the kind of things that most of us never bother to learn about, but which can affect the loading times of our applications and shared libraries. As someone noted in the comments, an informative read even by LWN.net's usually high standards.
Labels:
gyaan,
programming
2006-07-21
Validating XML Documents
I was writing a couple of XML documents conforming to certain XML Schemata the other day. I was looking for a simple command-line tool that would take an XML document and an XML Schema and check if the document was well-formed and really conformed to the given XML Schema (I did not want to use web-based validation). I could have written a tool like this myself but I was feeling rather lazy and just wanted to quickly download a tool from somewhere to do this.
It turned out to be a surprisingly frustrating task and eventually took more time than what I would have taken to write it myself. Perhaps my Google queries were not good enough, perhaps people are just happy with their respective IDEs, perhaps everyone just writes their own little tool around the usual XML parsing libraries, perhaps people are not so anal about writing XML documents that strictly conform to the applicable XML Schema, etc. - I don't know why, but it took me a while to locate such a tool.
I first used Sun's Multi-Schema XML Validator (MSV) and it worked for me for a while but then tripped with a StackOverflowError on a particular XML Schema that I had to use so I had to abandon it. I next tried XMLStarlet but the error messages it spewed were a bit confusing and it did not fully support XML Schemata so I abandoned it as well. I am now using a little tool called "DOMCount" that is included with Apache Xerces and that ostensibly parses a document and prints out the number of DOM elements it has encountered but that also works fairly well as a document validator. The error messages shown by this tool, while better than those from XMLStarlet, can still confuse some times but I can live with it for the moment.
While creating these documents from the appropriate XML Schemata, I found xs3p [link currently seems broken] to be really useful. This is a stylesheet that takes an XML Schema and generates a pretty HTML document from it that you can use to understand the original XML Schema and easily navigate through its structure. I used Apache Xalan to generate the HTML documents.
It turned out to be a surprisingly frustrating task and eventually took more time than what I would have taken to write it myself. Perhaps my Google queries were not good enough, perhaps people are just happy with their respective IDEs, perhaps everyone just writes their own little tool around the usual XML parsing libraries, perhaps people are not so anal about writing XML documents that strictly conform to the applicable XML Schema, etc. - I don't know why, but it took me a while to locate such a tool.
I first used Sun's Multi-Schema XML Validator (MSV) and it worked for me for a while but then tripped with a StackOverflowError on a particular XML Schema that I had to use so I had to abandon it. I next tried XMLStarlet but the error messages it spewed were a bit confusing and it did not fully support XML Schemata so I abandoned it as well. I am now using a little tool called "DOMCount" that is included with Apache Xerces and that ostensibly parses a document and prints out the number of DOM elements it has encountered but that also works fairly well as a document validator. The error messages shown by this tool, while better than those from XMLStarlet, can still confuse some times but I can live with it for the moment.
While creating these documents from the appropriate XML Schemata, I found xs3p [link currently seems broken] to be really useful. This is a stylesheet that takes an XML Schema and generates a pretty HTML document from it that you can use to understand the original XML Schema and easily navigate through its structure. I used Apache Xalan to generate the HTML documents.
Labels:
gyaan,
programming
2006-07-10
Presentation Skills
Most of us geeks seem to think that presentation skills are something for the marketroids or the suits to worry about. Even if we do have to present something, we only have fellow geeks in the audience who ought to be able to understand what we are talking about. However, geeks are humans too and humans need you to take care of certain things in your presentation for them to be able to fully appreciate and understand what you are talking about.
For example, in FOSS.in/2005 most of the talks were about cool stuff but in my opinion many a presentation left a lot to be desired. Among the talks that I attended, Jim Zemlin's talk about the Linux Standards Base was one of the precious few where the speaker seemed to understand and care about the basics of presentation.
Here are a few suggestions for speakers based on personal observations:
Finally, here are a few suggestions for presentation attendees:
For example, in FOSS.in/2005 most of the talks were about cool stuff but in my opinion many a presentation left a lot to be desired. Among the talks that I attended, Jim Zemlin's talk about the Linux Standards Base was one of the precious few where the speaker seemed to understand and care about the basics of presentation.
Here are a few suggestions for speakers based on personal observations:
- Keep the points in your slides short - avoid verbiage. Use the points to drive your talk - do not expect the audience to read everything off the slides. You can annotate your slides with explanatory notes if you want to upload the slides somewhere for people who were not able to make it to your talk.
- Find out how much time you will have for your presentation, factor in the time usually taken up for questions from the audience and possible delays due to the previous talk and structure your presentation appropriately. You can have "checkpoint" slides in your presentation that you can use to gauge how well you are doing with respect to your plan.
- Use clear fonts (I personally prefer scalable sans-serif fonts) and use a relatively large point size. People in the back should be able to make out what is written on your slides.
- Spread your points evenly across a slide. Try not to list more than seven points per slide; use continuation slides to break up long lists of points.
- Use foreground and background colours that have create good contrast. Remember that what looks good on your computer under ordinary lighting might look quite different when projected on a big screen in a darkened room.
- Fancy transitions get pretty distracting pretty fast. Avoid them as much as possible except for things like progressively introducing the layers of a system, the phases of a handshake in a communication protocol, etc.
- Do not keep your hands in your pockets all the time (a worse habit is to move them about in there). Gesticulate while talking - it's sometimes hard to know what gestures to use, so observe good speakers while they talk.
- Make eye contact with the audience. Do not stare at a single person or throw fleeting glances at everyone. Hold eye contact with some random person for a little while, move on to another random person and so on.
- Try an ice-breaker in the beginning to make your audience comfortable with you instead of just diving into your presentation. Humour is the best ice-breaker in my opinion but it takes talent to pull it off well. Some speakers use a quick show-of-hands kind of surveys. For one of his talks in FOSS.in/2005, Andrew Cowie put on his DJ hat and played various high-tempo tracks from his playlist while the organisers arranged various things for the talk.
- It is usually not a good idea to declare "Feel free to interrupt me when you have a question". You will quickly discover that this ruins your flow and that there are several jerks out there who would ask a question just for the sake of it and to make their presence felt. You can pause your presentation at various "milestone" points instead and check if anyone in the audience has any questions to make sure that they understand the stuff being presented before moving on to other things.
- The people in the front row might just shout a question across to you instead of using a microphone. For the benefit of everyone else, repeat the question before answering it (possibly rephrasing it) so that they know what is being discussed.
- Ask someone to record your presentation and watch the video later. You will discover a lot of things you were saying or doing that you were not even aware of and some obvious areas for improvement. For example, the first time I saw a video of my own presentation I was dismayed by the fact that I had put on a pretentious accent for some reason, that I kept saying "Ok?" irritatingly often and that I kept my hands in my pockets almost all the time.
- Do not stand between the audience and the projection of the presentation slides obscuring their view.
- Depending on the nature of the presentation, it might be a good idea to distribute supporting material (brochures, printouts of the slides, etc.) before the presentation so that the people in the audience have a little background information or a take-home refresher. Printouts of slides can also be used by people (given enough space) to write notes corresponding to the slides.
- If you can help it, do not talk about something that you are not excited about yourself. You will very likely give a better presentation about something that you genuinely believe in and care for than otherwise.
Finally, here are a few suggestions for presentation attendees:
- Please arrive on time. The cavalier attitude of most people towards punctuality causes unnecessary delays in starting a presentation and this has a cascading effect on the presentations following the presentation.
- Please do not ask questions merely for the sake of asking a question. Before you ask a question, ask yourself if the question makes sense, if the question is relevant to the current talk, if the question would require an answer that would be better off discussed in a post-talk chat with the speaker, etc.
- When you do ask a question, please use a microphone so that everyone else is able to make out what you are trying to ask. Please talk clearly and at a reasonable pace.
- When using a microphone, do not ask a question seated on your seat - it becomes very difficult for people to locate you. Stand up while you ask the question.
- Please do not come to a presentation merely to check emails, chat with friends, browse the web, etc. on your laptop using the wireless network made available by the organisers. It is being rude to the speaker and distracting to your neighbours.
- Please switch off your mobile phones during the talk or at least switch it to vibrating mode. If you absolutely must take a call, please leave the room and take it outside so that you do not disturb others.
- Try to be a bit discreet before walking out of a presentation - try not to walk out at all if you can help it. It is disheartening for a speaker to see people walk out of his presentation.
- Try to hold off on that urge to talk to your neighbour. It disturbs everyone else.
Labels:
gyaan
2006-07-06
Pricing Your Time
We often hear clichés like "Time is Money" or "Lost Time is Lost Money". Most of us generally agree with these assertions but do not actually try to quantify the money associated with our time. We therefore rely on our intuition or mood to decide whether it is worth it to do something ourselves or pay someone else to do it on our behalf.
For example, does it make sense for us to fill out the relevant form and file our income tax returns ourselves or should we just pay the fees to an agent who will do it for us?
Suppose the agent charges 200 rupees for this service, you drive a motorcycle that gives you about 48 kilometres per litre of petrol in city traffic conditions, the price of petrol is 55 rupees per litre, the distance to the income tax office is about 15 kilometres and the parking attendant there charges 2 rupees. If you were to file the returns yourselves (filing income tax returns online is not yet fully available in India), you will directly incur a cost of about 36 rupees in fuel and parking charges. Assuming that it takes about 15 minutes for you to fill the form yourself and about 60 minutes for the trip to the income tax office and back, is it worth saving this time and pay the agent an extra 164 rupees for his service?
A couple of my friends and I used to amuse ourselves by trying to calculate our time's worth using our salary as a guide. Assume that your annual salary is about 4,00,000 rupees, your employer expects you to work about 8 hours every day from Monday to Friday and grants you a leave of 15 days in a year. With about 52 weeks in a year, that is about 246 working days or 1,968 working hours. This means that your employer is willing to pay you about 203 rupees for every working hour.
So in this particular case, at least from your employer's perspective, it is better for you to pay the agent the extra 164 rupees that he is asking for rather than waste about 254 rupees in lost (hopefully productive) time.
Technically we should also consider other factors like the price we are willing to pay to save ourselves the effort (in addition to the time) involved in the task, the amount of trust we place in the agent to do the job correctly and on time, our willingness to share the information about our income with a third party, the amount of masochistic desire we have to do our job ourselves, etc. This is therefore a very crude measure of the monetary value of your time.
A professor of Economics has come up with another formula to calculate the monetary value of your time and you might have your own method of calculating this value. Whatever method you use, these methods can be used to quickly tell if it could be worthwhile to do something ourselves or pay someone else to do it for us.
(I wrote this piece purely for its amusement value - it should not be taken too seriously and should merely be used as an indicator in the spirit of Burgernomics.)
For example, does it make sense for us to fill out the relevant form and file our income tax returns ourselves or should we just pay the fees to an agent who will do it for us?
Suppose the agent charges 200 rupees for this service, you drive a motorcycle that gives you about 48 kilometres per litre of petrol in city traffic conditions, the price of petrol is 55 rupees per litre, the distance to the income tax office is about 15 kilometres and the parking attendant there charges 2 rupees. If you were to file the returns yourselves (filing income tax returns online is not yet fully available in India), you will directly incur a cost of about 36 rupees in fuel and parking charges. Assuming that it takes about 15 minutes for you to fill the form yourself and about 60 minutes for the trip to the income tax office and back, is it worth saving this time and pay the agent an extra 164 rupees for his service?
A couple of my friends and I used to amuse ourselves by trying to calculate our time's worth using our salary as a guide. Assume that your annual salary is about 4,00,000 rupees, your employer expects you to work about 8 hours every day from Monday to Friday and grants you a leave of 15 days in a year. With about 52 weeks in a year, that is about 246 working days or 1,968 working hours. This means that your employer is willing to pay you about 203 rupees for every working hour.
So in this particular case, at least from your employer's perspective, it is better for you to pay the agent the extra 164 rupees that he is asking for rather than waste about 254 rupees in lost (hopefully productive) time.
Technically we should also consider other factors like the price we are willing to pay to save ourselves the effort (in addition to the time) involved in the task, the amount of trust we place in the agent to do the job correctly and on time, our willingness to share the information about our income with a third party, the amount of masochistic desire we have to do our job ourselves, etc. This is therefore a very crude measure of the monetary value of your time.
A professor of Economics has come up with another formula to calculate the monetary value of your time and you might have your own method of calculating this value. Whatever method you use, these methods can be used to quickly tell if it could be worthwhile to do something ourselves or pay someone else to do it for us.
(I wrote this piece purely for its amusement value - it should not be taken too seriously and should merely be used as an indicator in the spirit of Burgernomics.)
2006-06-30
Separating Debugging Information
Debugging information in an executable usually takes up a lot of space so developers usually "strip" an executable before shipping it. This however makes it difficult to diagnose problems in your programme reported by the users, especially when a problem is only reproducible in the reporting user's environment.
Microsoft's development tools support creating a separate "Program Database" (PDB) file for an executable containing debugging information for the executable. Its diagnostic tools support reading a PDB file for an executable , if one is available, to generate a more usable diagnostic report for a fault. You ship stripped executables to your users and when they report a fault, you ask them to install the corresponding PDB files to help you get a better diagnostic report. I think that this is a nice idea and I used to wonder if the GNU toolchain would ever support something like this.
Danny Smith pointed out to me that something similar is already supported by recent versions of GDB and binutils. You can use the --only-keep-debug option of objcopy for this purpose. For example:
a.dbg now has the debugging symbols and a.out has been stripped of debugging symbols. When you want to debug a.out you can use:
Simple.
Microsoft's development tools support creating a separate "Program Database" (PDB) file for an executable containing debugging information for the executable. Its diagnostic tools support reading a PDB file for an executable , if one is available, to generate a more usable diagnostic report for a fault. You ship stripped executables to your users and when they report a fault, you ask them to install the corresponding PDB files to help you get a better diagnostic report. I think that this is a nice idea and I used to wonder if the GNU toolchain would ever support something like this.
Danny Smith pointed out to me that something similar is already supported by recent versions of GDB and binutils. You can use the --only-keep-debug option of objcopy for this purpose. For example:
gcc -g hello.c
objcopy --only-keep-debug a.out a.dbg
strip --strip-debug a.out
a.dbg now has the debugging symbols and a.out has been stripped of debugging symbols. When you want to debug a.out you can use:
gdb -s a.dbg -e a.out
Simple.
Labels:
gcc,
gyaan,
programming
Subscribe to:
Comments (Atom)
