Tuesday, May 16, 2023

Applying for an international drivers permit (IDP) from Pune

 

I was pleasantly surprised to know that it looks like this can be done from your home.   I have successfully applied for the permit and am currently (May 17, 2023) waiting to see if I am actually able to get the permit.

Prerequisites:

  • Image of your current passport
  • Image of your current drivers license
  • Image of Form 1A filled by a registered medical practitioner.  This is the same form that one needs to submit when applying for a drivers' license

 Download the mParivahan app on your mobile (as of May 17, 2023 I know it works on Android, have not checked for any other mobile platform).  Follow the instructions on screen and finally pay the requisite fee (Rs. 1000) and you are all set. 

As mentioned above, at the time of going to press, my application has been accepted but I have not yet received my IDP so I still cannot confirm that this online method works.  However I am hopeful that it will work since I was able to successfully renew my driving license twice (in 2017 and 2022) entirely using online methods.  I will update this information whenever something significant happens.


Combining multiple jpeg images using a Linux commandline

 I needed to combine multiple jpeg images into one.  I found the solution at https://stackoverflow.com/questions/20075087/how-to-merge-images-in-command-line.  Basically the command I gave was

convert Form*.jpeg +append form1a.jpg

Sunday, October 30, 2022

Adding signature to images (for purposes of self attestation)

Many organizations in India require us to submit "self-attested" documents.  Self-attestation simply means affixing your signature to a photocopy of a document.  This same requirement has also been preserved when one uploads these documents online.  Here are the steps I followed in order to convert an already existing document image without self-attestation into one with a signature:

  • Used https://www.scanwritr.com/app/ in order to create a pdf document  with a signature.  Note that the original file was a .jpg file
  • On my Linux machine I ran the command pdftoppm foo_self_attested.pdf foo_self_attested -jpeg -singlefile to generate a .jpg file out of the pdf file
     

The resulting file was acceptable to the "National Voters' Services Portal" (I was trying to apply for my Election card) 

Wednesday, August 19, 2020

Generating BBO files (.lin format files) using Thomas Andrews dealer

Thomas Andrews' dealer http://bridge.thomasoandrews.com/deal/ is, to my mind, the best bridge dealer out there and one I use extensively. It has a number of cool features but the one feature I love about it is that it is extensible in every imaginable way. One way you can extend it is by defining your own output formats.  In this blog post I will provide you with a tool to customize its output so that you can generate tailored hands that can then be loaded for play on BBO, the popular online Bridge platform (https://www.bridgebase.com)

Suppose, for example that you want to generate hands where North has 13 or more High Card Points(HCP).  You would then write a simple tcl script called example.tcl that looks like this:

 

main {

    if { [hcp north] >= 13 } {
        accept
    }
    reject
} 

Then when you execute this script by running the command deal -i example.tcl, the dealer generates hands where North has 13 or more HCP

By default, its output looks like this: 

 

          ♠ J74
          ♥ 3
          ♦ AQJ3
          ♣ AQT54
 ♠ AQ              ♠ T9653
 ♥ AT962           ♥ K74
 ♦ 9               ♦ T75
 ♣ KJ832           ♣ 96
          ♠ K82
          ♥ QJ85
          ♦ K8642
          ♣ 7
--------------------------
          ♠ QJ6
          ♥ AQ72
          ♦ KQ85
          ♣ 83
 ♠ AT432           ♠ K875
 ♥ 3               ♥ 8654
 ♦ 972             ♦ 63
 ♣ QT64            ♣ AJ2
          ♠ 9
          ♥ KJT9
          ♦ AJT4
          ♣ K975
 

Let us now suppose that you want to instead generate similar hands and use these to practice bidding with your partner on BBO.  BBO allows you to use your own hands - however these hands need to be in BBO's proprietary "lin" format which takes some learning, to put it mildly.  Unfortunately the dealer does not have any out-of-the-box mechanism for generating files that BBO can consume.  This is where the dealer's extensibility comes to our rescue.  You can extend the dealer's capability with  a simple piece of code that I am sharing here.

Here is the code to generate output in a lin format:

proc write_deal {} {
foreach hand {north east south west} {
set fmt($hand) "S[$hand spades]H[$hand hearts]D[$hand diamonds]C[$hand clubs]"
}
set handstring "$fmt(south),$fmt(west),$fmt(north),$fmt(east)"
# Need to add logic to calculate dealer and vulnerability
# For now we have set it so deal number is always 1
set dealno 1

# Dealer = 1,2,3,4 South, West, North and East respectively
set dealer 3
# Vul can be one of 'e', 'n', 'b' or ''
set vul ""
set msg "Deal $dealno"
puts "qx|o1|pn|South,West,North,East|st||md|$dealer$handstring,|rh||ah|$msg|sv|$vul|pg||"
}

To use, this code, do the following:

  • cd dealdir (this is the directory containing the dealer program called "deal") 
  • Locate the directory called "format" under it.  For example, on Windows it will probably be the directory windows\format.  Paste the above code in a file called "lin" in that directory
  • Add a directive inside your source file to source this file (see below) and you are all set

This is how your code will look like with this change (the one line addition to your original script is highlighted in purple in the code below):

source format/lin 
main {

    if { [hcp north] >= 13 } {
        accept
    }
    reject
}

Once you have done this, the same script will output something that looks like this:

qx|o1|pn|South,West,North,East|st||md|3S87HT5DT963CKQJ84,SQ3HK98762DKQ875C,SKJ964HAJ3DA42C53,SAT52HQ4DJCAT9762,|rh||ah|Deal 1|sv||pg||
qx|o1|pn|South,West,North,East|st||md|3SQJT64H843DJCA953,SA8752HQJTDT62C84,SK93HAK9DAKQ874CQ,SH7652D953CKJT762,|rh||ah|Deal 1|sv||pg||
qx|o1|pn|South,West,North,East|st||md|3SKHJ654DK9872CJ42,SQJ532HA987DT6CT6,SAT98HQ32DAJ54CA8,S764HKTDQ3CKQ9753,|rh||ah|Deal 1|sv||pg||
 

Save the output to a file and then upload that file to your BBO account. You can now actually bid/play with these newly generated hands on BBO.  For instructions on how to upload the file to BBO, see https://www.bridgebase.com/forums/topic/70978-how-to-upload-lin-file-from-handgenerator-for-teammatch.


Hope this blog post helps you.  Happy bridging!!!

 

 

Sunday, May 31, 2015

A recipe for Vegetable Biryani



Here is a recipe for Vegetable Biryani that has been well received by others so I thought I will post it here.  Why am I adding yet another Biryani recipe when there are literally thousands already on the web?  The reason is that most recipes seem to assume that everything will just work.  Reality is however different.  In real life
  • after following the recipe, we may find that the rice has remained uncooked and we have to figure out how to recover from that problem
  • we may not have all the ingredients so we may start wondering what to do
  • the recipe may not explain what advance preparations might be required
  • and so on ...
In this recipe I have tried to explain the rationale for various steps in the hope that this will help you extricate yourself if (when) you encounter something unexpected besides encouraging you to depart from the book.
First a high level view of the process of making Biryani:
  • Cook the vegetables that will ultimately go into the Biryani
  • Shallow fry the onions along with cumin seeds and ground cumin powder.  This will ultimately be mixed into the semi-cooked rice in the next step
  • Partly cook the rice in water infused with various spices and mix the onions in the rice
  • Interleave layers of semi-cooked rice and vegetables in a vessel and then cook this over low heat

Advance preparations

  • You will need Basmati rice - I have never tried this recipe with any other rice and would hesitate to suggest that you use any other rice variety since getting the rice right is one of the key elements of a good biryani
  • You will need a good thick bottomed vessel in which to slow cook the Biryani since a think bottomed vessel will result in the Biryani getting burned at the bottom.  If you do not have such a vessel you need not despair - you could simulate this by placing your actual Biryani vessel in another vessel while doing the slow cooking but then you will need another wider vessel for this.  My experience with rice cookers has been mixed so I will not recommend them  (although you will find some tips for how to use a rice cooker as well)
  • You will need a lot of Indian spices.  While it may be O.K. if you are missing some of these , you would want to have most of these spices available.  In the ingredient list below I have labeled the ingredients as "essential" or "desirable" to help you plan.
  •  You will need lots of vegetables - my rough rule of thumb is that for every unit of uncooked rice you can safely use three times the quantity of raw vegetables by volume.  Vegetables that go well with the Biryani are:
    • Tomatoes
    • Cauliflower
    • Green Beans
    • Green Peas
    • Bell Peppers (also called Simla Mirchi or Capsicum).  Apart from the green colored variety, feel free to use the red and yellow versions too
    • Potatoes in limited quantities but if you want to use these, use the ones that will not get mashed but will retain their firmness when cooked.  Also, you would be better off using somewhat large pieces (say cubes of size 3/4th of an inch ?)
    • Cilantro for garnishing (also called Dhania leaves or coriander leaves or kothimbir)
  • If you are not cooking on a rice cooker, it will be useful but not essential to have some yogurt around

Ingredients

  • 175 ml (approx. one cup) Basmati rice (essential)
  • Three times as much of vegetables (essential)
    • handful of green beans
    • 90 ml green peas
    • 3 bell peppers
    • 180 ml of cauliflower
  • One large tomato chopped (essential)
  • 2/3rd cup chopped onion (essential)
  • (Optional) a teaspoon of heavy cream for adding to the vegetables
  • (Optional) six teaspoons of yogurt (dahi or curds)
  • 4 spoons cooking oil (essential - I usually use peanut oil but any cooking oil without a strong smell should do)
  • 1/2 tsp roasted and crushed cumin seeds (essential)
  • 1 spoon cumin seeds (essential)
  • 2 tsp grated ginger (essential)
  • 2 or 3 leaves of garlic chopped finely (essential)
  • 1 tsp turmeric (essential)
  • 1/2 tsp chilli powder (substitute green chillies if unavailable)
  • Salt to taste
  • 5 cloves (Laung)
  • about 4 inches of cinnamon (Dalchini) stick (highly desirable)
  • about 6 cardamom (elaichi) pods slit (highly desirable)
  • 4/5 bay leaves, aka Tamalpatra  (highly desirable)

Making the Biryani

  1. Chop the onions and the vegetables.   Remember to string the beans and throw out the seeds from the bell peppers.  You may mix all the vegetables at this point except for the tomatoes and the cilantro which you should keep separately.
  2. Wash and rinse the rice, soak it in plenty of water.  After about 20 minutes drain the water. 
  3. While the rice is soaking, roast the cumin seeds till they appear to have become crisp and then crush these seeds into powder. 
  4. In a thick bottomed vessel (or a non-stick container) heat about two teaspoons of oil.   When the oil has heated, lower the flame and add about a teaspoon of cumin seeds and make sure that the oil has heated sufficiently by looking at the effect it has on the cumin seeds.  Then add the chopped onions and the ground cumin powder and sautee' this mixture together, occasionally stirring.  Do this until you see the onion changing color (this should take about three to five minutes ).  Important thing to remember is that you should not burn the cumin seeds - remember to lower the stove before putting in the cumin seeds.
  5. Gather the following ingredients in a plate:
    • grated ginger
    • chopped garlic
    • 1 teaspoon turmeric powder
    • 1 teaspoon cumin seeds
    • About three teaspoons of salt - remember that you need to put enough salt to compensate for the fact that the rice in the Biryani has no taste of its own
    • Chilli powder according to your taste
  6. You could reuse the vessel used in the last step for cooking the vegetables.  Just make sure that it is large enough to hold all our vegetables and still leave room for stirring the vegetables.  Take about two teaspoons of cooking oil and heat it in a fashion similar to the previous step.  Once the oil has heated sufficiently lower the heat, add the ginger and sautee' it for about 30 seconds.
  7. Add the remaining ingredients from the plate, stir them for another 15 seconds.  If you feel that things are close to getting burnt, turn off the heat and add the tomatoes before turning on the heat again.  If needed, add a teaspoon of water to ensure that nothing burns and sticks to the bottom.  After about 30 seconds, add the remaining vegetables except the cilantro.  Stir the vegetables and cook on high heat for about three minutes. 
  8. Lower the heat and place a lid on the vessel to minimize loss of heat and water vapor.  The idea is that by heating the vegetables on high heat we have already heated the moisture in the vegetables and given time and a minimal amount of heat, the vegetables will cook of their own accord.  Also note that we do not need to add any water - the vegetables we have chosen contain enough moisture to begin with and this is released in the presence of the salt when heated. 
  9. Let the vegetables cook for about 15 minutes (please resist the temptation to take off the lid and stir !) .  Take off the lid and raise the stove heat.  The idea is to evaporate the water from the vegetables while simultaneously ensuring that the vegetables have got cooked.   Stir occasionally and cook until the water has mostly evaporated but do not let the vegetables burn at the bottom.  Initially when you take off the lid it may appear that the vegetables are uncooked.  Do not worry - by the time the water has evaporated the vegetables would have got cooked. 
  10. If you are using heavy cream, you could add this to the mixture at this time.  Also add the cilantro leaves.
  11. With the vegetables prepared, it is now time to cook the rice.  For every cup of rice, take two cups of water and add the cinnamon, cloves, cardamom, bay leaves to it.  Add a teaspoon of salt and bring the water to a good boil.  When the water has started boiling, add the rice and cook it for about three minutes.  Then turn off the heat and drain the water.  Remember that the rice will not be fully cooked at this point.  Remove the various spices from the rice since you want to provide a pleasant eating experience for the consumers of your Biryani.  Add the previously fried onion to the rice and use a fork to mix it in the rice without crushing the rice grains. 
  12. We are now at the final step of  the Biryani making process where we will slow cook the rice and the vegetables together.  This is the most critical part of the recipe.  In this step we have to ensure that the rice gets cooked properly but that is does not get burnt.
  13. The safest utensil to use for this step is a heavy bottomed non-stick container.  Smear the bottom with some ghee (or butter or oil) to reduce the chances of the rice sticking to the bottom.  Divide the rice into three parts and spread the first part at the bottom of the vessel.  Then spread half the cooked vegetables over this.  Repeat this once more and top it off with the third portion of the rice. 
  14. This step is optional - add just enough water to the yogurt so that it forms a thick paste.  Heat this on low heat for about a minute and then pour the yogurt on top spreading it evenly over the rice.
  15. Apply a tightly fitting lid and cook on a low flame for about 25 minutes.  Open the lid and check to make sure that the rice at the top has got cooked - if not, heat it some more until this is done.  Add some more cilantro leaves and serve.

Additional tips

If you do not have the "perfect" utensil for doing the slow cooking of the rice, I have a good workaround - in fact the workaround results in an even better Biryani but is a little clumsier.  The workaround is to cook our Biryani inside an outer container.  Take a  utensil wide enough to hold our Biryani container and boil some water in it.  Put the container containing the Biryani rice into this container in such a way that the water does not spill.  Then heat this combination of containers as described above.  The advantage of this method is that the Biryani container gets heated from the sides as well as the bottom.


My experience with using a rice cooker for cooking Biryani has not been a particularly happy one.  For one, the result depends on the make of the rice cooker so I cannot make general recommendations.  However if you are using a rice cooker, I would recommend against using the yogurt since it often leaves the rice at the top uncooked.  Also, I would suggest cooking the rice a little longer when we pre-cook the rice (say 5 minutes).  You need to run the rice cooker on the "white rice" setting.   Finally, do not trust the cooker when it says that the rice is ready - open the cooker and inspect the rice at the top and if it is uncooked, cook it some more for another 10-15 minutes using your judgment.

Wednesday, May 02, 2012

How to Print large number of files automatically

Despite being in the second decade of the 21st. century when bits have replaced pages we still have to occasionally print out large numbers of documents when dealing with banks, government departments and the like.  I recently had the need to take printouts of a few dozen documents of assorted types - Word documents, pdf files, jpg images, tif files etc.  Doing this manually would have been quite painful and would involve
  • opening the file by double-clicking on it
  • choosing print
  • clicking on print
And I would have to repeat these steps for every file.  Instead I wrote the following Powershell  function to automate this:

function Print-Docs 
{
    Begin { $shell = New-object -comobject Shell.Application }
    process {
        $parent = (Split-Path (Get-Item $_))
        $file = (Split-Path -Leaf (Get-Item $_))
        
        if($parent -and $file) {
            $folder = $shell.NameSpace($parent)
            Write-Debug ("Printing file '{0}' from folder '{1}'`n" -f $file, $parent)
            $file = $folder.ParseName($file)
            $file.InvokeVerb("Print")
        }
        else {
            Write-Warning "Missing file $_"
        }
    }
}

After this it was a simple matter to do something like

PS: 64 > ls *.xlsx,*.docs,*.jpg | Print-Docs
and  I had my documents printed out thus saving me at least fifteen minutes.

Note - this will work only on Windows 7 and newer versions of Windows (unless you installed Powershell on an older version). 

Food for thought:
  • Some of the programs (e.g. the jpg program) prompts the user for some input.  How can this be modified so that the program is truly automated?
  • How would you do this in a UNIX environment (I remember vaguely that you could do automation of GUI programs through wish and TK)?

 

Sunday, June 06, 2010

Powershell commandlet to select a random subset from input stream

The problem:

Given a stream of incoming objects, we want to select a random subset of size "count".

This has many applications - for example, in my work as a software tester I could use this to do something like

cat alltests.txt |
Select-Tests-Meeting-Some-Criteria |
Modify-Tests |
Select-Random -Count 100 |
Run-Tests

This pipeline modifies all tests meeting some criteria and then selects a random subset of just 100 tests out of the (say) millions of modified tests in my test repository and executes those tests.

The obvious brute force solution would be to save all incoming objects into an array, shuffle the array and select the top "count" objects from the array. But this has a number of problems including:
  • Storage requirement of O(N) where "N" is the size of the input
  • All the processing starts only after all input has been read in so that there is a computational peak right at the end of input and no computation happens while reading the input
We can instead adopt a different approach that involves iteratively discarding input as it streams in and retaining only "count" objects at any given point of time. Of course, while doing so we have to ensure that all input objects have an equal chance of being selected. To ensure that we do this correctly, we will need to bias our selection to favor objects that have already survived previous eliminations rather than the new incoming object that has not yet been subjected to previous eliminations. This is easy to achieve if we maintain the invariant that the nth. input object should have a probability of survival equal to count/n for n>= count.

Here is a Powershell commandlet that encodes this logic:




function Select-Random {
param ($count) ;
begin {
if($count -le 0) {
throw [System.Exception]
}
$num_seen = 0;
$rand_generator = New-Object system.random;
$selected = @();
}
process {
if($num_seen++ -lt $count){
$selected += $_;
}
else {
#Get a random number between 0 and ($num_seen -1)
$random = $rand_generator.Next(0,$num_seen);
if($random -lt $count) { #Choose the new number and add to $selected
$selected[$random] = $_ ;
}
}
}
end {
$selected;
}
}




And here is a test to make sure that our algorithm works correctly - our input consists of the integers from 1 to 11 and we select 10 of these. In other words, the probability of selection for any number is 10/11 = 0.9091. We repeat this test 10000 times and check the frequency of occurrence of each number in the output - it should hover around 0.9091 * 10000 = 9091

for ($i = 0 ; $i -lt 10000 ; ++$i) {
$list += ((1..11) | Select-Random -count 10)
}
$list | Group-Object | Sort-Object -Property Count

PS: 44 >.\select-random.ps1

Count Name Group
----- ---- -----
9051 4 {4, 4, 4, 4...}
9056 7 {7, 7, 7, 7...}
9070 1 {1, 1, 1, 1...}
9079 2 {2, 2, 2, 2...}
9083 8 {8, 8, 8, 8...}
9088 10 {10, 10, 10, 10...}
9094 9 {9, 9, 9, 9...}
9094 6 {6, 6, 6, 6...}
9099 3 {3, 3, 3, 3...}
9133 11 {11, 11, 11, 11...}
9153 5 {5, 5, 5, 5...}

Some things I learnt from this exercise:
  • How to initialize an empty Powershell array
  • How to add an element to the end of a Powershell array
  • The Group-Object commandlet

Saturday, June 05, 2010

Importing mh mail into gmail

From 1990 until approx. 2004 I used the UNIX based mail client "mh". Around 2004 I got an invitation from my friend who worked at Google to try out gmail.

I had never used any web-based email service for a number of reasons:
  • I had assiduously collected all my personal email across a period of more than fifteen years and wanted the security of knowing that all my email would always be available to me even if the "free" email provider were to close down
  • As an mh user I was accustomed to the power of being able to do stuff such as "scan +inbox | wc -l" and no web based email would allow me to do that
  • I did not care to read email accompanied by flashing advertisements etc.
The downside of my intransigence of course was that I could not take advantage of the universal access to my email that web based email providers offered besides having to ensure secure storage all my email myself.

gmail was a refreshing change however since it was the first email provider to also allow pop-based access to email stored there. With gmail I now had the choice of accessing my email anytime I had internet access while still permitting me to retain control over my email since I could always download it onto my local machine and I opened an email account (which was then "invitation only" :-).

The reality turned out to be different however. While it was true that I could download my mail in gmail using POP that had its own problems since all my emails got downloaded (including once I had already downloaded) every time I fetched mail from my gmail server. Furthermore gmail had added a number of cool features such as keyboard shortcuts, tagging, searching etc. that I was fast getting addicted to. Also I had taken up a job that involved working in a Windows environment so that it was no longer very feasible for me to use my Linux laptop at work. Before I knew it, I had already accumulated a substantial amount of mail in my gmail account in addition to my substantial mail on my home machine. Furthermore with the evolution of email I have to regretfully acknowledge that mh (or its graphical successor exmh) no longer cuts it and I have accepted that I have to move on from my past love ...

I am now trying to import my old mail from mh into gmail and here is how I was able to successfully achieve this:
  • download the python script "gml" from http://marklyon.org/gmail/old/gml.tar using "wget http://marklyon.org/gmail/old/gml.tar"
  • Extract the file gml.py - "tar xvf gml.tar"
I then wrote a bash script to upload all my old email to gmail and here is what it looks like:


folders -noverbose -all -recurse -fast -noheader -nototal | while read folder
do
#Remove the old mbox file
/bin/rm ./msgbox
#Pack this folder into an mbox format file
packf +$folder
#Mail the contents of this file one mail at a time while preserving
#original headers and simultaneously add folder-related information
#for use in gmail
python gml.py mbox ./msgbox address+$folder@gmail.com outgoing_smtp_server_address
done


Just in case you were not aware of this, gmail allows you to create multiple aliases for the same email address e.g. (messages to foo@gmail.com, foo+bar@gmail.com, foo+baz@gmail.com are all delivered to foo@gmail.com) - see http://mail.google.com/support/bin/answer.py?hl=en&answer=12096 for more details.

As a result I can now (theoretically) transfer all my old email to my gmail account. I will now need to figure out how to automatically label them based on the old source folder name (which I am embedding into my "To:" address field. I have not yet figured out how I can do that. Watch this space ...