Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

9 Jul 2026

Preventing duplicate keystrokes from bluetooth keyboards

I bought a cheap wireless keyboard a few months ago. While the keyboard was mostly fine, it sometimes repeated the same letter twice or thrice. For example, every few minutes, when I type a word like “India”, I see “Indiia” on the screen with an extra i. It was a mild annoyance for a while, so I was living with it. When I started making typos in design documents that I was creating at work, it started to be severe enough to require a solution.

The issue went away when I connected the keyboard using a cable, so this was clearly a bluetooth issue. I asked Gemini what the problem could be, and it said that the following could be happening:

  • The keyboard sends a keystroke to the computer over bluetooth.
  • The bluetooth transmission is slow, probably due to interference. The computer doesn’t receive it within the expected time.
  • The keyboard thinks the transmission was lost; it sends the same keystroke once again.
  • But the initial keystroke eventually arrives. Quickly after, the retransmission also arrives.
  • The keyboard thinks it sent only one keystroke (because the first transmission was lost), but the computer sees two keystrokes. Oops!

A solution

I feared I may have to buy a new keyboard. While a more expensive keyboard may be able to work more reliably despite interference, there is no guarantee that it will. Gemini suggested a different solution. Apparently there are software tools that can run in the background and drop duplicate keystrokes that arrive in quick succession. The KDE Plasma UI that I use has this feature built-in, but as an accessibility feature. It’s called Bounce Key. I enabled it with a timeout of 50ms. This configures the operating system UI to discard any duplicate keystrokes that are received within 50 milliseconds.

A nifty software solution for a hardware problem.

25 Nov 2024

Fund benchmarks hint at fund portfolios

Hybrid mutual funds are a little tricky to evaluate. Not only do you have to understand the strategy the fund will follow, but you also have to know the asset allocation that the fund will maintain. The fund’s scheme information document holds the authoritative answer for how the money is invested, but the benchmark chosen by the fund can give a quick hint on what to expect. I use benchmarks as an early signal to filter out funds that may not be suitable for my needs.

Let us look at a few examples of multi asset allocation funds. All the following screenshots are from ValueResearchOnline. I will not name the funds because identifying individual funds is not necessary for this exercise, and I don’t want to give unintentional signals (positive or negative) about any specific fund.

This is a popular mix of assets: 65% equity qualifies the fund to be taxed like equity. That may sound attractive to many investors, but I generally avoid such funds because I reach for hybrid funds only when I want to keep volatility low.

This is an interesting one, and honestly an appealing choice for me. This fund is well diversified with a global equity index and a commodity index added to the benchmark. (This is the first time I am even looking at this fund, actually.)

This is a simpler fund with just 3 asset classes in the benchmark. I also like that A-II debt is the largest asset class in the benchmark, which is a good hint that this fund will be less volatile than many of its peers.

While benchmarks give us a good hint on how the fund will invest our money, it is crucial to look at other sources of information, too. Reading the scheme information document, looking at the history of the fund (if available), and the history of the AMC (if available) can give us valuable information on what to expect from the fund.

24 Oct 2024

What does ‘Investing for the Long Term’ mean?

The lifetime of a typical investment corpus is many decades long. Our investment corpuses often outlast our own lives. Decisions that optimise short term gains while ignoring the long term effects can end up causing a net loss.

1. Don’t invest in active strategies (such as active mutual funds, PMS funds, Smallcase, etc) if you don’t absolutely trust the firm running the fund/strategy. The fund manager will be gone in a few years, or at best a few decades. The market dynamics will change in a few decades. Will this strategy still be a winning strategy? Do you have a plan for managing the situation when the tables turn?

1a — Corollary: If you have an active strategy that you can execute on your own, and you can execute it without much hassle for decades, you can definitely follow it. But barely anyone knows such a strategy and have the conviction to bet large sums of money on that strategy.

2. Don’t get into half-baked strategies like Coffee Can Investing. Don’t enter the equity market like an Abhimanyu. You need to know when to exit and how to exit. It is not wise to assume that great companies of today will remain great investments forever.

3. Don’t invest in sectoral or thematic funds that are expected to do well in the next few years. They will see a slump after those few years. What will you do then?

3a. Don’t buy overnight sensations (such as the Nvidias/Teslas or Quant AMC funds or crypto assets) in the hope of making quick money. Yes, you may make quick money in the next few years. Can you hold onto those investments for the next 40 or 50 years? (Remember that a typical retirement corpus has a lifetime of 70 years or so.)

Both sectoral/thematic bets and overnight sensations require you to know when to exit. Unless you time the exit precisely, you may lose quite a bit of money. The vast majority of retail investors cannot exit on time. Hence, it’s better to simply swallow the FOMO (fear of missing out) and stay away from these temptations.

4. Don’t add portfolio clutter that is hard to manage. Either you will be dead and your family will have to declutter your messy portfolio. Or you will get old and won’t have the vigour to manage a cluttered portfolio. (See also: A cluttered portfolio is not a problem—it’s a symptom)

5. Don’t be afraid to correct your mistakes even if it is costly in the short term. It’s better to pay capital gain taxes today and exit a bad fund/strategy than to put your portfolio under unnecessary risk for many more years.

10 Sept 2024

Where to park emergency fund?

“Where to park my emergency fund?” is a question I see many people ask. This is also a question I was asking a few years back, but I did not get a satisfactory answer. In this post, I am going to write down my own answer to this question. My goal is not to give one single answer, but to give a matrix of options to choose from.

‘Emergency Fund’ by 401kcalculator.org • CC BY-SA 2.0flickr.com

a. Easy, transparent access

If you want the money to be accessible easily, without even having to consciously think about using the emergency corpus, add this as sweep deposit(s) to your primary account. If you run out of money in your bank account some day, your deposits will automatically liquidate to pay for your expenses.

Who is this good for?

  • People who don’t want to think too much, but just want the safety of having an emergency fund.
  • People who have family members who don’t want to (or cannot) think about drawing from different accounts or liquidating assets like mutual funds, fixed deposits, etc.

Maintenance strategy

Add the emergency cash to the primary bank account. Keep spending from that bank account without worrying whether you are drawing from the emergency fund or not. Every few months—say 6 or 12 months—review the surplus in the bank account + deposits. If it’s fallen below the amount you wanted to save, replenish it.

b. Easy, but non-transparent access

Open a separate bank account just for holding emergency fund. All cash in this account (including sweep deposits) is your emergency fund. This is a good option if you want the money to be accessible easily, but you want the use of the emergency fund to be a conscious decision.

Who is this good for?

  • People who don’t want to accidentally dip into their emergency fund. For example, this is good if you want to know when all you had to access your emergency fund so you can make better financial plans.
  • People with a “family emergency corpus” that anyone in the family can use. Open an either-or-survivor bank account in up to 3 family members’ names. Everyone uses their regular account for their day-to-day expenses. Anyone can use the joint account in emergencies.

Maintenance strategy

It’s very easy to tell how much money from the emergency fund has been used by just looking at the emergency account’s statement. Replenish the account as early as possible after every use (or periodically).

c. Harder to access, but more tax efficient

Interest paid to the money kept in banks is taxed every year irrespective of whether you used the interest or not. If you park the cash in mutual funds, you only pay tax if/when you use the money.

Using mutual funds is tax efficient, but the liquidity is severely limited compared to bank deposits. If you need a reasonably large sum at 4pm on a Friday, the earliest you can get access to cash is Tuesday! Or Wednesday if Monday happens to be a holiday.

Who is this good for?

  • People who have other means to manage emergencies. For example, you are young and single, and you can ask your parents to lend you some cash.
  • People who don’t like to manage bank deposits, such as calculating tax liability on realised + accrued interest.

Maintenance strategy

Same as option (b), but you also need a plan for (i) how you or your family members will redeem the mutual fund, and (ii) how you are going to manage the lag between placing a redemption order and getting cash in your bank account.

You can choose from a few mutual fund categories. Liquid funds are the safest; ultra short and money market funds are a tad bit riskier but may give about 0.5% more return. Gains from arbitrage funds are taxed even more favourably, but redemptions take 2 business days (vs 1 business day for debt funds).

Plug: Looking to open a new bank account with auto sweep-in and sweep-out? Check out my post Comparing auto-sweep accounts of 3 banks.

d. A corpus with 2 different buckets

There can be 2 kinds of emergencies.

  1. The first category needs only a little bit of money, but you need it quickly. During the emergency, you may be preoccupied with more important things, and hence thinking about money then can be a hassle. Medical emergencies, a family member getting into an accident, a relative asking for an emergency loan, emergency car, house, appliance repair, etc are some examples.
  2. The other category of emergencies needs a larger sum of money, but you’d need to spend it over a longer duration, say, a few months. Temporary loss of income is a typical example. In such cases, you usually have time to think and plan an asset liquidation strategy.

Let’s say you want to tackle these 2 kinds differently. You may want to optimise for liquidity and accessibility for the first kind and optimise for the highest return for the second kind. In this case, you can choose either (a) or (b) for the first part of your emergency corpus and (c) for the second part.

For the second part, it will be tempting to go with a hybrid mutual fund or a multi-asset mutual fund to potentially get a higher return. However, keep in mind that job losses often coincide with larger economic uncertainties. How would you feel if you lose your job right when your emergency corpus is down by 30% (because of the gloomy outlook in the market)?

Conclusion

The purpose of this post is to show a few solutions to inspire people to think of something that suits their needs and preferences. I hope that goal is accomplished. Everyone has unique needs. Make a plan that lets you feel the most comfortable, because living comfortably is the whole point of saving money.

23 Aug 2024

A ‘fun portfolio’ is essential for investment enthusiasts

People who like and get excited about investment products should maintain a fun portfolio.

After the initial few years of exploration, most investors will settle down with a portfolio of assets. From then on, the assets tend to be stable since they have chosen these assets after some exploration and experimentation. For my own portfolio, they are 2 equity index funds and a debt fund. I don’t think I want to change those assets now since these assets were chosen after a lot of deliberation.

However, there are fancy investment assets that I want to invest in. Not because they’ll generate great returns, but because I just like them and I want to own a piece of them.

Image credit: pickpik.com

Here are a few that I have wanted to invest in over time:

  • Holding equity shares directly rather than through mutual funds.
  • Offerings like Kotak Cherry and ETMoney Genius.
  • Edelweiss AMC’s thematic fund that invests only in IPOs.
  • Momentum strategies, especially those involving mid- and small-caps.
  • Multi-asset strategies.
  • … and so on

I take pocket money every month, and that money is invested in these fancy assets/strategies. Having a ‘pocket money’ system allows me to cap the size of this ‘fun portfolio.’ This allows me to have fun playing around with fancy assets without jeopardising the family’s financials.

3 Jul 2022

My costly taxation mistake

I made a costly mistake in the 2021-22 financial year. I did certain things assuming that a specific tax rule will lower my tax liability. My accountant who is preparing my tax return is telling me that my assumption was wrong. Basically I am looking at a big tax bill this year (along with interest too, since I didn’t account for this while paying advance tax)!

Lesson learnt: do not assume you’re right and cross-check with experts. If you expect to save a lakh rupees in taxes, it’s prudent to spend one or two thousands in validating the assumptions to be doubly sure.

11 Sept 2021

Using credit card rewards to increase emergency corpus

I am scared of inflation. Not just ‘aware’ of inflation and plan with inflation in mind. I am really scared of purchasing power eroding due to inflation. This fear influences all my financial plans.

I have set aside some liquid investment as my emergency fund, to manage unexpected expenses. Because I am always afraid of inflation, I have set a goal of increasing the emergency corpus by 10% every year. While having a growing corpus is reassuring, it’s not easy to add to your corpus every year. I don’t have a plan for how to fund this increase.

I got an idea last week. I use cash back credit cards that give me some cash regularly. The reward shows up as credit on the card statement, but it’s cash nonetheless. From this month on, I am going to move that money into my emergency corpus. That will not be sufficient for the target increase of 10%, but every little bit helps.

In a way, credit card cash rewards encourage spending. The more we spend, the larger the size of the rewards are. Credit cards give me free money every month. I’ll consciously moving this free money over to my emergency corpus. I somehow feel like this is a better habit than unconsciously spending the cash back rewards.

14 Jul 2021

Look before you leap: the temptation to invest in gold (again)

A new issue of Sovereign Gold Bond (SGB) is currently available for purchase, and that’s what I see everywhere I look. Everyone sells SGBs and everyone is advertising them big time. Understandably so, since gold is one of the most favourite investment vehicles of Indians.

decided to not invest in gold sometime back, but still, the temptation caused by these promotions made me consider buying maybe a few grams. Then I came across these 2 at the right time:

The highlight here is that neither of these is new to me. I knew I didn’t want to invest in gold; I knew I had to look at rolling returns before purchasing any new investment asset. Yet, I had the temptation to buy SGBs.

Moral of the story? It’s hard to keep your head steady when there’s so much noise around you. Remain focused, and remain with conviction whether you decide to invest in a certain asset or decide to not invest in a certain asset.

19 May 2020

Hacking Kuvera “family account” for goal separation

tl;dr: Create “fake” family member profiles to keep short-term and long-term goals separate or to keep your debt/equity investment ratio intact.

Let’s say you’re investing for some long-term goals (10 or more years away). Simultaneously, you also want to save for some short-term goals (1 or 2 years away). Or you just want to park some money in some debt funds (such as ultra short term funds). Kuvera’s default setup doesn’t support these needs very well. (Maybe for a good reason? They have SaveSmart which is probably what one should be using?)

Cash in a sack bag
Photo courtesy: PickPik.com
Mixing of short- and long-term goals
Kuvera uses unified goal planning, which takes advantage of the fact that as years pass, you’ll be earning more but your needs will reduce (because, say 2 of your 6 goals are already accomplished). But what it also means is that you cannot use Kuvera as a “recurring deposit” for saving (not investing) for a short-term goal. When you add a short-term goal, Kuvera will ask you to add just a tiny bit to your existing (long-term) SIPs because unified goal planning is inherently like that. If you kept adding many such short-term goals—I don’t pretend to know what really will happen—but intuitively it feels like you won’t have sufficient time for the money to grow for your long-term goals. It feels safer to keep the long-term SIPs and short-terms SIPs separate.

Parking surplus money for a few months/years
Let’s say you have some extra money lying around. You cannot quite invest it because you know you’ll have to spend that money in a few months. Or you may want to put a portion of your emergency funds in ultra short term debt funds that give higher return than liquid funds. (Also something wise people advise you to not do. Debt funds are for giving stability to your portfolio; don’t chase returns without understanding the risk.)

Basically, you want to park some money in debt funds. The moment you do that, your goal-based investments’ debt/equity ratio gets out of whack. This can be confusing and if you aren’t careful, would make your portfolio less than optimal.

In search of a solution…
Making Kuvera ignore your short-term or parked funds is easy: go to the folio management page and hide the folios that have the short-term funds. But now you cannot keep an eye on those funds.

I looked for alternate apps to track these funds. I tried ET Money and MoneyControl. They had the main feature that I wanted: I can enter when I bought what funds for how much; they’ll show me the current value, daily change in valuation, etc. But their user interfaces were a mess compared to Kuvera’s clean and beautiful UI. I tried Goalwise, but they only support defining and tracking goals, not the “I just want to track these external investments” use case. Their UI was so cluttered I didn’t even have the desire to learn if I can use their app somehow.

After struggling through this for a few weeks, I suddenly thought of a solution: just add a new “fake profile” to my account. I have enabled Family Account feature on my account so I can track my wife’s and brother’s investments. Now I have added a fake profile (i.e. a nonexistent family member) to the family for tracking short-term goals and parked funds. Now that I have learned this trick, all my recurring deposits will be going to Kuvera. I hope I’m not making a dumb mistake here 😬

6 May 2020

Analysing the health of mutual funds

What should a mutual fund investor ideally do? Study mutual fund documents first and then invest. What did I do? Bought some funds without much analysis or reasoning and then, after a few months, I am looking at fund fact sheets and trying to understand how well they are managed. I am saying this upfront because I want to highlight that I am just doing things haphazardly, including the analysis itself. I don’t know what all information one should look at in a fact sheet, and how to determine if a fund is doing well. With that caveat out of the way, let me get into what I found from my analysis.

As a newbie investor, Franklin India’s decision to shut down 6 debt funds was bizarre to me. That news made me realise how some mutual funds can be bad. I had noticed this Reddit thread before, but couldn’t understand what they were talking about. I didn’t try to understand the discussion because I hadn’t invested in any of those funds. After the news, I reread that post and read some more on the web. I started to get some idea on what fund attributes I could look at.

If monitoring the health of mutual funds is an important thing investors should do, there must be dashboards on the Internet… or so I thought. After failing to find such a dashboard, I decided I had to make one myself. I downloaded March 2020 fact sheets of all my funds and I summarised some key stats (click on the image to magnify):
Spreadsheet showing AUM, NCA, and % of risky debt assets of some mutual funds

This was more confusing than useful to me: of the 12 funds I had data for, 6 had negative cash! Many debt funds, including liquid funds, had exposure to sub-top-grade debts. Is every debt fund taking risk in the market then?

After a few hours, I decided to add data from February so I can see how things have changed over the course of March. This turned out to be a good idea. Now I was able to see a clearer picture:
Spreadsheet showing some mutual funds' NAV, AUM, NCA, % of risky debt assets, and change in the number of units held

The market was less crazy in February, and that shows up in the numbers:
  • Only 2 funds had negative cash. They also held a fairly low amount at -0.29% and -1.46% of respective AUM.
  • Other than Kotak Savings, exposure to sub-top-grade debt was also minimal. Nippon Liquid fund had 0.35% lent to unrated borrowers.
In March, uncertainty rose sharply due to Covid-19 lockdown. That is also reflected in the numbers:
  • Many investors have redeemed their debt funds: 30% reduction in AUM seems normal! (Remember, this was before the Franklin fiasco.)
  • Quite a few funds now hold negative cash, probably to accommodate the high number of redemption requests.
  • Risky debt has also increased across the board.
  • PGIM is the only fund house to exclusively hold top-tier debts; they are also the only debt fund managers to hold some cash in hand.
(One surprising observation from the data is that people have bought equity mutual funds while they have exited debt funds. Maybe they were rebalancing because it was the end of quarter?)
What are my takeaways from this exercise? I was fond of Kotak Savings fund because it looked so nice. Kotak web sites are so good, I just loved looking at this fund’s official web page. PGIM UST fund’s site looks okay, but it’s hardly impressive. Logging into PGIM’s investor web site also doesn’t work most of the time. Due to all this, I didn’t really like PGIM funds. Dumb mistake, I know! I was judging both Kotak and PGIM ‘books’ by their ‘covers’. When I look at my spreadsheet, however, I see how disciplined PGIM’s fund managers are, and how risky Kotak Savings fund really is.

If I hadn’t gone through this exercise, I might have sold the PGIM units and bought Kotak units instead. I am so glad I sat down and looked at the numbers.

3 Apr 2020

How I blew an opportunity to buy equity funds for cheap

Equity investments are losing valuation due to the market crash. Depending on whom you ask, what to do in such a situation varies. The advice I took was to maintain asset allocation and rebalance when the allocation is off.

It’s not obvious how maintaining asset allocation can help during a market crash like this. But it’s not hard to understand if you think about it a little. Let’s say your desired asset allocation is 30% debt and 70% equity. When equity loses value and debt increases in value, your portfolio could get to something like 38% debt and 62% equity. The advice is to sell your (potentially overvalued) debt and buy undervalued equity at a cheaper price. As the equity market recovers, you would make some profit.

I did have a desired asset allocation before market rout, but due to some (self-induced) complexity, I had messed it up. I was over-invested in equity than I had thought. I discovered that mistake when I was taking a deeper look at my portfolio. I also found out that equity losing value had brought my portfolio down to the desired allocation. I don’t have to do anything for now; the market has rebalanced my assets. 🤦🏾‍♂️

But that also means that, because my asset allocation was off, I am not able to buy more equity at a cheaper price now. The equity I hold were bought at a higher price and I am holding onto the loss. It’s a lost opportunity.

While it’s true that nothing stops me from buying more equity now even if it means my asset allocation will be off for a while. I have decided to not do that because that’s essentially timing the market. There’s no guarantee that the market will recover after my equity purchase. Debt funds, at least in India, are not really going up in value either. Because many companies are at the risk of going bankrupt, investors are not keen to buy debt funds as well. Because demand is fairly flat, the value is also mostly flat. By selling my debt funds now, I may not be selling overvalued assets.

Moral of the story: asset allocation is actually important. Assets being off balance could lead to lost profits.

20 Feb 2020

Choosing mutual funds to invest in

You want to invest in mutual funds, but you don’t know which of the thousands of available funds is right for you. The easiest thing to do is just look at historical returns and pick one that has performed well in the past. That’s pretty much what I did when I started investing in mutual funds a few years ago. Unsurprisingly, the returns weren’t as mind-blowing as I had expected.

Fast forward to 2020, I am now a Kuvera customer. (Plug: join using my referral code JK1P3 and get 100 Kuvera coins for free.) In addition to providing a well thought-out investment platform for free, Kuvera has written quite a bit about how to think about investing and wealth management. From the experience using Kuvera and reading about the thinking behind their decisions, I think I am starting to see some of the intricacies in choosing a good fund.



In October 2018, Kuvera changed their recommended funds. In October 2018, they started recommending DSP Equal Nifty 50 instead of IDFC Nifty. I compared the facts and performance of these 2 funds, and it was surprising how unattractive the DSP fund looked to a novice investor like me.

In the past year, the IDFC fund has given an impressive 15.25% return while the DSP fund has given a mere 6.69%. The DSP fund’s return is below the benchmark return, actually!

Comparison of past 1 year fund performance. IDFC Nity has yielded 15.25% returns while DSP Equal Nifty 50 has yielded only 6.69% returns.

The fact that the DSP fund is underperforming the benchmark is reflected in its “info” statistic. The IDFC fund has 0.8 for “info” while the DSP fund has -0.04! The IDFC fund wins in other attributes too: it has a cheaper expense ratio (0.24% vs 0.38%) as well as barely less volatility (14.14% vs 14.25%).

Fund statistics comparison between IDFC Nifty and DSP Equal Nifty 50

How then is the DSP fund better than the IDFC fund? They mention 3 reasons:
  • Lower concentration of financials
  • Historic EW premium
  • Buy low–sell high in a systematic way
Of these, I don’t fully understand the “buy low–sell high” point, likely because I haven’t read the fund documents.

Lower concentration of financials
This becomes obvious if you look at the stocks held by these funds. The IDFC fund holds HDFC Bank shares for 10.6% of its value. In other words, you would be buying HDFC Bank shares roughly worth ₹10.60 if you were to buy the IDFC fund for ₹100. Intuitively, that is not something you’d want to do if you want to diversify your investments. But there’s more than just intuition.

Top 10 holdings of IDFC Nifty and DSP Equal 50 funds

Historic EW premium
I think the “EW” refers to “equal weight” here. The DSP fund distributes the money roughly equally between every share in the Nifty 50 basket. While intuitively this is a good diversification strategy, apparently this has yielded better returns historically. Gaurav Rastogi, CEO of Kuvera, states in a comment:
The reason we choose DSP Equal Weight Nifty fund instead of a plain vanilla Nifty index (IDFC) fund is because Equal Weight indices have outperformed their plain vanilla indices globally and in our back test in India as well on a risk adjusted basis.


What are my takeaways from this?
  • Past returns are useful data, but comparing the returns of 2 funds may not give us the full picture.
  • Understanding how a fund is managed such as how they choose shares, the objective of the fund, etc are important. Investors should understand what the fund manager does with our money.
  • Because most of us don't have the time or skill needed to study the mutual fund options, following the recommendations of good financial advisors is an easy shortcut to picking good investments. (How you tell if an advisor is good, I have no idea!)

8 May 2015

Finding blog posts with broken links

How frequently do you end up with erratic HTML in your blog posts?  Not very frequently.  But if you do find your blog in such a state, how do you fix it?  I was playing around with my Picasa settings and in the process I managed to break all my album URLs.  All my albums now returned a 404.

I wanted to find all my blog posts that link to one of my Picasa Web albums and fix the broken links.  Unfortunately Blogger's search will only search the text of the posts, not the HTML.  What this means is that a post containing HTML like "<a href="http://picasaweb.google.com/mankis.pics/Pilgrimage2010>photos</a>" can be found by searching for "photos", but not by searching for "picasaweb" or "mankis.pics".  Like any self-respecting programmer, I decided I'd whip up a script that would do the searching for me.

To access my posts from a script I have two choices: use Blogger's API or get a dump of my blog by exporting it to a file.  API would be a good choice if I have to edit a great number of posts, but I only have to edit a few posts so I went ahead with the latter option.

If I pass the export XML file and the search string, my script would print URLs to edit posts that contain the string.  This is how I found all posts with links to a Picasa album:
% ./find_blog_posts.py \
     -b /tmp/blog-04-30-2011.xml \
     -s 'mankis.pics'
http://draft.blogger.com/post-edit.g?blogID=28645193&postID=5479412993915553873
http://draft.blogger.com/post-edit.g?blogID=28645193&postID=6291962710796224390
...
The script is available online if you want to use.

10 Jul 2013

Behavioural optometry

When I was looking for an optometrist a few months ago, I wasn’t specifically looking for a behavioural optometrist. In fact, I didn’t even know there was such a things as behavioural optometry. I found Smart Vision Optometry through Google search. Their web site didn’t quite convince me to visit them, but somehow I decided to go check them out. In hindsight, that was a good decision.

This is what I have understood from my treatment so far. Eyesight and vision are two related but different things. Eyesight is the ability of your eyes to see things. Vision is your ability to make use of visual information to make decisions. For example, seeing the other side of the road and an approaching car is eyesight. Gauging the width of the road, distance of the approaching car, and the car’s speed to determine if it’s safe to cross the road is vision. Having a good eyesight is necessary, but not sufficient, to having a good vision.

A conventional optometrist is solely focused on improving your eyesight, while a behavioural optometrist tries to improve both your eyesight and vision.

My doctor (Gary Rodney) recommended that I try orthokeratology instead of wearing glasses. I don’t wear glasses during the day anymore; I wear contacts at night while sleeping. I am also taking vision training exercises every day to improve my vision. In addition to helping me see better, the vision training is supposed to keep my myopia from worsening. It’s definitely more work than just getting a new pair of glasses, but the payoff makes the effort well worth it.

When your next optometrist visit is due, try to find a behavioural optometrist. Maybe then you won’t have to keep changing your glasses every few years.

29 Sept 2012

Don’t pay for web hosting if you don’t have to

A few months ago, I moved all my websites, including my personal homepage www.manki.in to Google hosting.  (That is, some Google product running on my own domain.)  However, there was one piece in the puzzle that was still with my web hosting provider: redirecting any requests to the naked domain manki.in to www.manki.in.  Once the request reaches www.manki.in, Google would take care of it from there on.

This was the setup of my site for several months, until yesterday.  Only yesterday I found out an awesome feature Google Apps has.  It can redirect requests to your naked domain to any subdomain you specify.  Precisely the one thing I was paying my web hosting provider for!   And Google would do this for free because I am on their free Google Apps plan.  That amounts to saving more than $50 a year.  Very cool!

Essentially, I had to set up DNS A records to point my domain name to Google’s IP addresses and tell Google Apps which subdomain I wanted the requests to go to.  Check Google’s help page for detailed step-by-step instructions.

One last thing you need to do is disconnect your domain name from your hosting provider’s IPs so your users are always sent to the right place.  Once you have added the A records to map your domain to Google’s IPs, delete all original A records so your domain is not pointing to your hosting provider anymore.  When your hosting contract runs out next year, you can simply not renew it :)

2 Sept 2012

Inspecting 302 HTTP headers

Let’s say you want to inspect the response header for an HTTP request.  But the response is a 302, so your browser immediately navigates to the new location and you never get to see the 302 response (and the headers).

One way to solve this problem would be to install a browser extension that would keep the headers for you even after the redirect has happened.  But I’m not a big fan of installing browser extensions for functionality that I very rarely need.  So I use the wget command instead:
wget -S -O/dev/null --max-redirect=0 'http://www.google.com/'
-S flag tells wget to print the headers to stderr
-O/dev/null discards the response body (by writing it to the null device)
--max-redirect=0 tells wget to not follow any redirects.

This is the 302 redirect google.com sends for redirecting users to country-specific Google domain:
--2012-09-02 09:54:33--  http://www.google.com/
Resolving www.google.com (www.google.com)... 74.125.237.50, 74.125.237.48, 74.125.237.52, ...
Connecting to www.google.com (www.google.com)|74.125.237.50|:80... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 302 Found
  Location: http://www.google.com.au/
  Cache-Control: private
  Content-Type: text/html; charset=UTF-8
  [...snip...]
  Date: Sat, 01 Sep 2012 23:54:33 GMT
Location: http://www.google.com.au/ [following]
0 redirections exceeded.

30 Jul 2012

Poor battery life after Android 4.1 (Jelly Bean) update?

If your Android phone was recently updated to Android 4.1 (aka Jelly Bean) and you have been seeing really bad battery life ever since, read on.  It could be that Google+ sync has been enabled by the update and that’s using up a lot of power.  Go to your phone’s Settings > Accounts > Google settings screen.  For every Google account listed, deselect the Google+ option.  This should bring back sane battery life to your phone.

See Demystifying Android power usage for more generic tips on saving battery life on Android devices.

1 Apr 2012

Rolling back git commits without losing history

I sometimes introduce a buggy feature to a program and I want to roll it back.  If I had already committed the buggy feature into my git repository, I prefer to keep the buggy commit in revision history... just for posterity ;-)

Finding how to do this was a bit hard, so I’ll document it here.  I know I’ll need to look this up another time; it’s easier if it’s on my own blog :)  The command to roll back to a previous commit is:
git checkout <commit> <repository root>
For example, running git checkout ea2ff0a50 ~/d/prog would restore all files under ~/d/prog directory to the state they were at ea2ff0a50 commit.  Now I can commit the “new” rolled back state with a different commit message, for example “Roll back free penguins feature.  Penguins are too cute to be given away.”

The other approach for rolling back, where you lose the buggy commit for good is to use git reset.

29 Mar 2012

Generic solutions and specific solutions

From certain points of view, programming is fairly easy.  Most of the common problems have known solutions.  Often, programming is simply applying common solutions to specific problems.

I have a web app whose sole purpose is to create thumbnails of images whose URLs are given.  It took a few seconds for serving each request, so I applied a common solution to the “my program is too slow” problem: caching.  With two levels of caching, I brought down the average response time to around 150ms.  (Caching code is in boldface.)
if PICASA_URL_REGEX.matches(original_url):
  # Resizing Picasa URLs is child's play.
  # All we need is some URL tweaking.
  response.Redirect(resize_picasa(original_url))
  return

if FLICKR_URL_REGEX.matches(original_url):
  original_url = mid_size_flickr_url(original_url)
# local_cache is a simple hash map.
if original_url in local_cache:
  response.Redirect(local_cache[original_url])
  return

thumb_url = memcache.Get(original_url)
if not thumb_url:
  thumb_url = data_store.Get(original_url)
  if not thumb_url:
    image_bytes = http_client.Fetch(original_url)
    thumbnail_bytes = image_resizer.Resize(image_bytes)
    thumb_url = data_store.Store(original_url, thumbnail_bytes)
  memcache.Set(original_url, thumb_url)
local_cache[original_url] = thumb_url
response.Redirect(thumb_url)
Though 150ms isn’t too bad, I had been wanting to optimise this further for several months.  Only I couldn’t figure out how.  Yesterday, something dawned on me: I was using the caches all wrongly!  I was unnecessarily repeating a bunch of string operations and regular expression searches for every request before even touching the caches.  A better approach would be to hit the cache as early as possible.  I changed the algorithm to be like:
# response_cache is a a simple hash map.
if request.query_string in response_cache:
  response.Redirect(response_cache[request.query_string])
  return

if PICASA_URL_REGEX.matches(original_url):
  # Resizing Picasa URLs is child's play.
  # All we need is some URL tweaking.
  thumb_url = resize_picasa(original_url)
  response_cache[request.query_string] = thumb_url
  response.Redirect(thumb_url)
  return

if FLICKR_URL_REGEX.matches(original_url):
  original_url = mid_size_flickr_url(original_url)
thumb_url = memcache.Get(original_url)
if not thumb_url:
  thumb_url = data_store.Get(original_url)
  if not thumb_url:
    image_bytes = http_client.Fetch(original_url)
    thumbnail_bytes = image_resizer.Resize(image_bytes)
    thumb_url = data_store.Store(original_url, thumbnail_bytes)
  memcache.Set(original_url, thumb_url)
response_cache[request.query_string] = thumb_url
response.Redirect(thumb_url)
Immediately the average response time came down to around 40ms.  Plus, it’s not unusual now to find requests that get served in less than 5ms!

Algorithmic difference between the two code snippets is subtle, yet the performance difference is substantial.  What makes programming interesting is the fact that knowing the solution is not always sufficient.  Ability to adapt a generic solution to specific problems is one of the things that makes one a good programmer.

Appendix
Sample logs before code change:
Sample HTTP request log before code change
After code change:
Sample HTTP request log after code change

24 Mar 2012

Disable automatic updates for your crucial Android apps

Android Market has a per-app preference for automatically updating the app when a newer version is available.  It’s convenient, and is usually a good security measure to keep this option enabled for all your apps.  However, if there’s an app that’s “crucial” — i.e., if you cannot afford to have this app not running, you may want to disable automatic updates for that app.

I use Sleep as Android to track my sleep.  I turned on sleep tracking last night and went to sleep.  Woke up this morning and saw that the Sleep app wasn’t running.  Instead there was a notification from Android Market that it had updated the Sleep app overnight.  The app got killed when it was updated and was never started again.  Had it been a weekday, I would have missed my wake up alarm and could have slept longer than usual.

I have now disabled automatic updates for this app.  Disabling automatic update for this app would require that I manually update it every time there’s a new version.  It’s a pain, but it’s much better than oversleeping and being late to work.