A Weekend at the Scotland of India


On January 26th when the nation was celebrating its 68th Republic, I set out on a family trip to the Scotland of India – Coorg.

Being a family trip I was not on my RE. Since it was a car ride, I slept for the initial part of the Journey. Then we sopped over at ‘Stop Over’ in Bidadi for breakfast. Looks like the staff there was not ready to accommodate the Long weekend rush. We had to wait for almost an hour to get our breakfast, and it was an even tougher struggle to finish that breakfast.

We resumed our journey and we crossed some beautiful countryside roads. The beauty of the Karnataka country side is always a welcoming sight. Cattles, farmers, farm lands small puddles of water.

We crossed Srirangapatna. Since we had already been there in the past we decided not to halt. The roads were really smooth and I dozed off a couple of time during the journey.

We reached ‘Athithi Comforts’ in Kushalnagar around 12:30 PM.

dscn0187

Checked in and rushed in for lunch. Over lunch we decided to visit the the famous Namdroling Monastery and Harangi dam. As these seemed to be close by to our hotel.

The first stop was the Namdroling Monastery. I have been to this monastery before during my schooldays. The picture I had of this place from my memories was of a colorful and serene place with lots of paintings. Like everything else the colors of the monastery had faded with time. It was dull but the place still had its serene and peaceful environment. We roamed around, occasionally glancing at the display boards that had descriptions about the various paintings and about the Buddha Idols that were the main attractions of the monastery.

budhas

From Left Buddha Padmasambhava, Buddha Sakyamuni and Buddha Amitayus

 

The monastery was established by the 11th throne-holder of the Palyul lineage, His Holiness Drubwang Padma Norbu Rinpoche in 1963, following his 1959 exit from Tibet as the second seat of the Palyul Monastery.

It was prayer time and we could hear drum and trumpets accompanied by chanting, adding vibe to the whole monastery.

Our next stop was Harangi dam. The road to the dam was really interesting, lonely roads with greenery on both sides. I really missed not being on my bullet. We reached the dam, but unfortunately the dam was closed and was not accessible for the public. We stopped our car and decided to make the most of what we had. I tried clicking a few cormorants and parakeets that were around.

We still had time to kill and then we decided to make it to Raja’s Seat before sunset to enjoy the view. Being a cloudy evening it got dark soon and we just made it to the place.

I was still excited about the few birds that I was able to identify that day and the photos that I clicked.

The Second day plan was to cover Tala Cauvery. We were all excited to see the birth place of  one of the largest rivers in South India. Again the road from Madikeri to Tala Cauvery was full of curves and steep slopes and filled with beautiful picturesque backgrounds.  All the way I was dreaming of a beautiful stream of water flowing through the mountains, may be a small water fall-  Ah what a perfect spot to see some birds. But to my utter dismay all that was there was a  regular temple with a small pond of water, there were some people, taking dips in that pond. This pond signified the origin of the river. We all were wondering whether we had missed something, the origin of a river cannot be a Pond for sure, was this a hoax or maybe we really missed something. From the temple there was a small flight of steps that led to a hill top that had some pretty decent views. The disappointment created by what we expected Vs what we saw at Tala Cauvery over shadowed everything else, even those beautiful spots seemed dull to us and we decided to head back to Madikere to get some lunch and maybe visit a couple more places and finish off the day.

After lunch, we visited the Madikere fort. It had a small museum with some relics and old artifacts. The museum building itself seems to be an old church and there were memorial stones all over the place. A small typewriter kept on display caught my attention and I stood gazing at that ancient piece of technology for sometime, imagining how many letters and documents that machine would have punched out in its years of service. We then took a stroll around the fort looking at the view and wondering how soldiers would have used those vantage points to spot enemies. There were some sparrows and a coucal on the walls of that fort, but since it had started drizzling, I had left my camera in the car. We also visited the Omkareshwara temple. The temple has a design that is quite similar to the ones seen in Muslim dargahs. It was almost getting dark and we decided to get to Abbi falls as it was nearby. By the time we reached there it was already dark. I don’t know if it was the dim lighting or the gloom cast upon us by Tala Cauvery, but Abbi falls looked beautiful.

Next day morning I woke up early and decided to go for a walk. I had recently picked up the hobby of birding. I picked up my camera and started walking. The sun was just rising and i could hear the birds singing on the tree tops, but I just couldn’t make out where they were. Finally I managed to see a brown shrike, a spotted dove, a red whiskered bulbul. This got my spirits high for the day. This was the last day of our trip and Nisargadhama and Dubare Elephant camp was left on our list. After breakfast we first went to the elephant camp. The camp was closed due to some strike but we had a good view of the cauvery river and people enjoying rafting. I was still on the look out for birds.

Nisargadhama was again a typical picnic spots with tourists littering the place, there was a deer park. Its a pity to see these beautiful creatures in captivity. On the final leg of this trip I was able to ‘shoot’ a Ashy Drongo, a yellow wagtail and a magpie robin.

Three days had gone by in this beautiful place and now it was time for us to return. With a bunch of photos and memories we bid farewell to the paradise called Coorg.

 

 

Advertisements

The Monarch of BR Hills


Sometimes things don’t work out as planned and all you can do is just wait for everything to fall in place. From the last week of December, 2016 I had made plans to visit BR Hills. I had heard from friends and over the Internet that the ride to BR hills was beautiful and cannot be missed. But then every week the plan got postponed until 14th January 2017. Again as in my previous trip to Savandurga, we were a group of 4 ( my wife Pooja, and our friends Arun and Vidya).

From Bangalore through Kanakapura, Kollegal route we set forth to the K. Gudi Wilderness camp situated inside BRT Tiger reserve. Enjoying the scenic country side beauty of Karnataka. I must say it was difficult to keep your eyes on the road. There was so much to look around and see.

But the most interesting part of the ride was the final 11km just before K. Gudi wilderness camp through the BRT Tiger reserve. The jungle was silent and calm except for the leaves rustling in the wind and the occasional chirping of a few birds. There was a Blue chested Kingfisher that was trying to race with us, but I just slowed down to enjoy its beauty. Then lay ahead of us 11km of sheer pleasure, roads winding up the hill and through the jungle. I do not have words to describe what I saw or experienced in that 11 Kms. And probably the only sound to be heard was my enfield thumping as it was climbing the hill. Usually from my past experiences in such trips the jungle roads will be littered with bonnet macaques and spotted deer, but this time there was no one.

DSC02407.JPG

Cottage at K.Gudi

Around noon time we reached K. Gudi wilderness camp. My friends were already there had checked in and were out with their cameras. So we hurried into our rooms not wanting to miss anything. The welcome party at the camp was organized by an Asian Paradise Flycatcher.IMG_1908.JPG This was followed by another show by a couple of Blue-throated bee eaters. We took a stroll around their property and by then lunch was ready. At 4pm we all had geared up and were ready for the jungle safari. From our previous safari experiences expectations were low and we took it causally. Our guide was Mr. Narayan and besides the 4 of us there were 2 more people on the Jeep (Dr. Prem and his son). After the first half an hour of the trip I felt that Mr. Narayan had some kind of super power with which he could spot almost anything at any distance. All the way along we saw drongos, white breasted king fishers, Tickell’s blue fly catcher and so on. There were some barking deers too. This continued for almost 2 and half hours and I guess Mr. Narayan was not yet in a mood to give up and took us on the main road in the opposite direction of the camp. It was getting dark and the cold jungle breeze was getting colder with each passing moment. And suddenly there it was, on the road side a magnificent beast with orange and white fur, with black strokes like the strokes made by an artist using a paint brush. I was in a trance for a moment trying to figure out what had just happened. There was so much excitement in that jeep and I was still not able to get hold of the moment. Having missed a golden opportunity in the past at Wayanad, this was like a second chance for me. I decided not even to touch the camera. This was the moment and I had to be in it. I was not going to let anything distract me from it.

Seems like luck was on our side, the tiger just decided to sit down relax and it gave us a grand pose. My friend started frantically clicking, even Dr. Prem was busy with his camera. Since all I had was my mobile phone, I thought I will enjoy the view. It never took its eyes off us but at the same time he was not scared or anxious. It seems that he knew that he was in control and that we were at his mercy. After all this was his jungle, his kingdom and we were the outsiders. And finally when he got bored by our gimmicks, just stood up and started walking towards our side. I could feel the tension in the jeep as it started walking, it gave us one final look. By then a couple of cars had lined up behind us, that grand creature just disappeared into the bushes.

0Y7B4326.jpg

Mr. Narayan drove like crazy back to the camp. We were received like heroes and everyone had gathered around to look at the photos.

That night we all went to sleep with a sense of accomplishment that none of us have ever felt in life. Maybe this was by far the most beautiful thing I have ever seen.

The Curious Case of Preprocessors


What would be the output of the following code snippet:

#include <stdio.h>
#define V 1
int main()
{
  int Value = 1;
  #if V == Value
      printf("Hello world\n");
  #endif // V
  return 0;
}

If you guessed that the program will print “Hello world” you are wrong.

The reason being #if is a preprocessor directive and at the stage where preprocessor directives are evaluated or expanded, ‘int Value = 1’ has still not been processed and memory has not yet been allocated. This will happen only at the compilation stage and not the preprocessing stage.

So basically there is no meaning in V==Value and this will evaluate to false. So for this piece of code to work you will have to define even ‘Value’ with the #define statement.

Thanks to two of my colleagues Rakesh and Mitul for this interesting discsussion.

Sunday @ Savandurga


It was a lazy Sunday morning. I had to struggle to get out of bed in the chilly January morning in Bangalore. But the thrill of the ride and the day ahead were motivation enough to get me moving. I started from Bangalore around 8am. It was a group of four (Me, my wife and two of our friends). We all had a quick breakfast and wanted to start the trek before it gets too hot.

Although it was a Sunday morning roads still had traffic blocks until we reached the toll gate on NICE Road. After that it was like a waltz for me on my RE. The cool wind blowing on your face randomly some cars whiz by. The feeling is just amazing and highly intoxicating, it makes you wish the ride was never over. We entered the Mysore road and then took a deviation that takes you to ‘Dodda Alada Mara’. We passed by the gigantic Banyan tree. Having heard legends about it, I wanted to stop there very badly but then  we were already getting late for the trek. I just enjoyed that marvelous tree as I drove by.

The next couple of kilometers had some dusty roads and nothing interesting. Soon we were riding through scenic Karnataka Country side with lush green fields on both sides. Once you approach Savandurga, you can see the Monolithic hill from several kilometers away. There was a Narasimha swamy temple at the foothills.

Without much delay we started our trek of Savandurga. At first the steep slope looked intimidating but we were confident that this is doable, at fair distance we could see a stone wall and we believed that was the top of the Savandurga hill. We all somehow managed to climb taking rests where ever we found a rock to lean on. There was a guy selling ‘frooti’ carrying a load of those tetra packs walking so leisurely. He told that us that further ahead there were steps. Then we saw a lady in a sari climbing the hill, all we could do was watch this with our mouths wide open. I wondered does a desk job make you so unfit (Or maybe it was all the Junk food that I eat). Any way these gave us hope and inspiration although short lived. To our surprise when we reached the stone wall we realised that we had not even made half of the trek. And the path ahead was even more steeper and and even more challenging.

img-20170109-wa0014

 

 

Beyond a point I was literally crawling praying to all the gods that I don’t slip. There were certain stretches of the trek which had to be done in one shot. If you stop in the middle you will just slide or roll back down. Anyway after 2 hours we somehow managed to climb upto a point where there were some kind of ‘steps’ but by then we were all exhausted and we also started worrying as to how we will descent. The sloped would be even more challenging on our way back.

 

 

img-20170109-wa0023

The ‘Road’ not Taken

 

My descent was something like the spiderwalk in the movie Exorcist. I was the slowest in the group and I was happy that I came back in one piece.

exorcist-spider-walk

Yes but we somehow made and we all felt proud that we were part of some sort a dangerous adventure for the weekend. We never missed to take selfies. The view from the top was really breath taking . The beautiful river Arkavathi flowing towards the Manchinabele dam and the nearby hills. Even at around 12 noon the visibility was not that great and you could see  the mist slowly drifting away. After all the tiresome and scary trek was for this view. Once at the top we forgot how hard it was to get there and we chose to ignore the thoughts of getting back down. For a few minutes we all were lost in this beautiful view and mother nature caressing our sweaty foreheads and cheeks with a cool breeze.

img-20170109-wa0018

Arkavathy River

The Garden Pi


This is a small project that will introduce you to IoT and on how to use WebIOPi and Raspberry Pi to create a small and cool project.

These are the components that you will require for this project:

  1. Raspberry Pi B+ ( Any Rpi should work)
  2. 3-6V Submersible Mini water pump
  3. Wifi Adapter  (You can skip this if you have a LAN cable long enough to reach your garden)
  4. Transistor Bs550
  5. 5V Relay
  6. Tube to supply water from the pump to the flower pots.

Setting Up the Wifi Adapter

As mentioned earlier if the LAN cable is long enough to reach your garden then you can skip this stage.

Make sure the Wifi adapter you have is compatible with the Raspberry Pi you have. I have used an Edimax Wifi usb adapter.

Insert the adapter into the Rpi USB slot and power up your Rpi.

At the command prompt type in the command lsusb

lsusbout

From the output of this command we get to know if the Wifi adapter was detected or not. In my case the last line shows my Wifi adapter.

The next task will be to edit the /etc/network/interfaces file. Type the command

sudo nano /etc/network/interfaces . This should open up the file and the contents should be edited as shown below:

# The loopback interface
 auto lo
 iface lo inet loopback
auto eth0
 iface eth0 inet static
 address 192.168.0.26   #your static IP
 network 192.168.0.0
 broadcast 192.168.0.255
 gateway 192.168.0.1     #your gateway IP
 netmask 255.255.255.0

allow-hotplug wlan0
auto wlan0
iface wlan0 inet static
 address 192.168.0.25   #your static IP
 network 192.168.0.0
 broadcast 192.168.0.255
 gateway 192.168.0.1   #your gateway IP
 netmask 255.255.255.0
 wpa-ssid "SSID of Your Wifi Network"
 wpa-psk "password of your Wifi Network"

Here I have configured the static IP of 192.168.0.26 for LAN connection on Rpi and 192.168.0.25 for Wifi on RPi.

Type ifconfig at the comamnd prompt and make sure the IP address of the Wifi (or LAN) is assigned correctly. If not reboot your Rpi.

Once this is done try pinging your Rpi from within the same network. Use the IP address of LAN or the Wifi adapter based on how your Rpi is connected to the network.

Now on your Rpi try pinging some external website like http://www.google.com

If the ping is successful all is fine. If not don’t worry there is a fix to it.

Type in route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 wlan0

If this is the output then notice that the gateway has not been set properly. All you have to do is execute the command given below.

sudo route add default gw 192.168.0.1

Now the you should be able to ping external websites. It would be a good idea to add this line to the ~/.bashrc file so that every time your Rpi starts up this get done automatically.

Once the wifi is setup you are ready to move on to the next section.

Installing WebIOPi

Since the WebIOPi has a pretty neat tutorial on how to setup WebIOPi, I will redirect you to that: http://webiopi.trouch.com/INSTALL.html

If you have both eth0(LAN)  and Wifi(wlan0) configured you may run into and issue where weaved is not able to access your WebIOPi server.

In that case type in sudo ifconfig eth0 down and that should do the trick. If it does consider adding this also to the ~/.bashrc file.

Setting Up the Garden Pi Web Page

For this project all you have to do is to write a single index.html file.

so create a project directory structure as shown below:

mkdir ~/gardenpi/html

 

edit the /etc/webiopi/config file

  • Locate [HTTP] section, add following line to tell WebIOPi where to find your HTML resources
...
[HTTP]
doc-root = /home/pi/gardenpi/html
...

More details about the config file can be found here

Now create the file ~/gardenpi/html/index.html

Add the following content into it:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Garden Manager</title>
 /webiopi.js
 
 webiopi().ready(function() {
 webiopi().setFunction(3,"OUT");
 webiopi().setFunction(2,"IN");
 // Create a "Pump" labeled button for GPIO 3
 var button = webiopi().createGPIOButton(3,"Pump");
 // Append button to HTML element with ID="controls" using jQuery
 $("#controls").append(button);

 // Refresh GPIO buttons
 // pass true to refresh repeatedly of false to refresh once
 webiopi().refreshGPIO(true);
 });
 
 <style type="text/css">
 button {
 display: block;
 margin: 5px 5px 5px 5px;
 width: 160px;
 height: 45px;
 font-size: 24pt;
 font-weight: bold;
 color: white;
 }

 #gpio3.LOW {
 background-color: Black;
 }

 #gpio3.HIGH {
 background-color: Blue;
 }
 </style>
</head>
<body>

Turn on the pump by clicking the button below
 
</body> </html>

Once the file is created connect and LED between the GPIO3 and Ground of the RPi.

Open up a browser in your PC or mobile and go to http://192.168.0.25:8000

and ensure that the LED turns on and off at the click of the button. All you have to do now is to connect the pump instead of the LED.

Since the pump draws more current than compared to what the Rpi can supply we will be using a relay.

Wire up your components as shown in the diagram below:

cktdiagramgardenpi

This is my Rig, you may not be able to make much from the picture:

Jpeg

Hope you guys ill enjoy doing this project.

 

My Experiments with Boost Graph Library


Recently I picked up “An Introduction to Graph Theory” by Robin J. Wilson. After going through a couple of chapters I felt the sudden urge to try out a few of graph theory problems through programming. To try out the algorithms I first need to create the graphs themselves, which seemed a bit of a tedious task. But then thats what the boost graph Library is there for.

The BGL has made it very easy to create graphs and perform any operations on them.

Below is a simple program that lets you create a graph using the BGL.

#include<iostream>
 #include<boost/graph/adjacency_list.hpp>
 #include<boost/graph/graphviz.hpp>

int main(){
 boost::adjacency_list<> graph;
 int noVert = 0;
 int start=0,end=0;
 char choice = 'y';

 while(choice == 'y') {
 std::cout<<"Enter the start and end vertex of the edge: ";
 std::cin>>start>>end;
 boost::add_edge(start,end,graph);
 std::cout<<"Do you want to add another edge(y/n): ";
 std::cin>>choice;
 }

boost::write_graphviz(std::cout,graph);
 return 0;
 }

The coolest feature of BGL is that it allows you to write your graph as ‘dot’ file, which can be used to by Graphviz to visualize. Checkout my github repo for more BGL based programs.

Range Based For Loops in C++11


Here is a short post on the range based for loops in C++. I recently learned about range based for loops in C++11 standards. These are nothing but easier constructs on writing loops. You no longer have to write:

for(initialization;condition;update)

The syntax is:

for(declaration:expression)

Although this looks like a very simple feature there are a few things to keep in mind while using the range based for loops.

Lets take a look at a simple piece of code:

#include<iostream>
int count(int array[100])
{
 int total=0;
 for(auto num:array)
 total++;
 return total;
}
int main()
{
 int array={1,2,3,4,5};
 std::cout<<count(array)<<"\n";
 return 0;
}

If you compile the above code it throws compiler errors.

The same code will work if ‘array’ is a local variable in the main.
This baffled me for quite sometime and it is a friend of mine who explained to me why this happens.

This is how a range based for loop works:

It starts from the beginning of the array and travels till the end. So it needs the iterators to traverse the given array. In the code provided above ‘array’ is passed as a pointer and it does not have any iterator or boundary information. So in my original code if I pass ‘array’ as a ‘std::vector<int>array’, the code works fine.

Hope this will help someone else who is stuck. To know more in depth about how range based for loops work in C++, refer to the link provided below:
http://en.cppreference.com/w/cpp/language/range-for

Calling a function On termination of main() in C


Dear readers, A friend of mine taught me this new “trick” where you can call a function when the main() in C exits.

In the Library “stdlib.h” there exists a function

int atexit(void (*func)(void))

the “func” is any function without any arguments.

The atexit() calls the function that you register as soon as the main() terminates.

Here is a simple sample code to demonstrate this.

#include<stdio.h>
#include<stdlib.h>
void func()
{
printf(“This is after main\n”);
}
int main()
{

atexit(func);
printf(“in main\n”);
return 0;
}

The function can be registered anywhere in the main() but it will be called only after the main() terminates.

Hope this helps atleast some of you in doing some cool things. Please feel free to share your ideas.

The World of Dynamic Programming


Recently I came across the an algorithm that can find the maximum sub array in a given 1-D array. Its called the Kadane’s algorithm.It comes under the domain of dynamic programming. I would like to write about a few things I understood about Dynamic programing so that it may help someone else to get a start and at the same time to improve my own knowledge on the topic.

Dynamic programming is an optimization problem or a programming technique, where the given problem is split into sub problems and so on.
To understand more about dynamic programming we need to look at how it obtains optimization. Dynamic programming builds its optimal solution by creating optimal solutions for its sub problems.This is also called optimal substructure.
It follows the principal of Optimality which states that “A problem is said to satisfy the Principle of Optimality if the sub solutions of an optimal solution of the problem are themselves optimal solutions for their subproblems.”

Or to put it in simpler terms optimal substructures means that the optimal solution to a problem is made up of optimal solutions to its sub problems.
Another technical term used in dynamic programming is Overlapping subproblems. This means that there are a few subproblems in total and
many recurring instances of each.

Dynamic programming uses a bottom up design process. A very good example of this will be the fibonacci series generation.
Lets first look at the recursive solution to generate fibonacci series. Instances like f(1) ,f(0) repeat multiple times. If these values can be stored they don’t have to be calculated multiple times.

The left side shows the number of steps taken by a dynamic program and the right side shows the steps taken bya recursive program to calculate fibonacci series.

An example of Dp and Recursion

An example of Dynamic Programming and Recursion

It is also to be noted that dynamic programming is not the same as divide and conquer, because dynamic programming proceeds by splitting the  problem space in every possible manner.

I have tested the efficiency of the of  both kinds of Fibonacci code. And here are my findings with respect to time taken for running the code.

Test on Fibonacci

And below is the code used for testing this.

#include<stdio.h>
#include <time.h>

int fibonacci1(int n)
{
  int a=0,b=1;
  int i,c;
  for(i=0;i<n;i++)
    {
      c=a+b;
      a=b;
      b=c;
      //printf("%d\n",c);
    }
  return b;
}

int recfib(int n)
{
  if ( n == 0 )
    return 0;
  else if ( n == 1 )
    return 1;
  else
    return ( recfib(n-1) + recfib(n-2) );
}
int main()
{
  clock_t t;
  double normaltime=0,rectime=0;
  int sample;
  for(sample=0;sample<100;sample++)
    {
      t=clock();
      fibonacci1(sample);
      t = clock() - t;
      normaltime = ((double)t)/CLOCKS_PER_SEC; // in seconds
      t=clock();
      recfib(sample);
      t = clock() - t;
      rectime = ((double)t)/CLOCKS_PER_SEC; // in seconds
      printf("%f,%f\n",normaltime,rectime);
    }
  return 0;
}

2014 in review


The WordPress.com stats helper monkeys prepared a 2014 annual report for this blog.

Here’s an excerpt:

The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about 27,000 times in 2014. If it were a concert at Sydney Opera House, it would take about 10 sold-out performances for that many people to see it.

Click here to see the complete report.

%d bloggers like this: