Posts

An early morning trek to Ghangad Fort

Image
Ghangad is a short but exciting trek offering the thrill of trekking over difficult patches in portions and some heart trembling moments when you cling on to a thin wire of hope for support.
It great for training beginners. And the view is just splendid.

Duration : 30 mins - 40 mins

Why to choose this trek:

1) Great for only morning treks like Sinhagarh. It offers a mind view of two sides of the mountain .
2) Easy to reach. The route to Ghangad offers amazing landscapes from Tamini Ghat. So it's a bonus.
3) Don't need to plan ahead. Don't need to carry much stuff if you planning to return same day.
4) In rainy season, the waterfalls in the valley area are amazing. We plan to do it this rainy season.
5) Barely any crowd. We encountered no one. Absolute silence and just the wind blowing , animal sounds from the forest . It was just a trekker's dream come true.

Our Plan :

We started at 3:30 .
Climbed and reach back home by 12 AM .
It's an hour long journey . We went via…

Python List sorting with key argument explored

Everybody uses lists as an array to store values. List provide a lot of in-build features.SortingMembershipIndexingIterationreversingAdding/RemovingPoppingCount
Lots of reasons to use lists. I think, one of the most used features is sorting. Internally , python uses Merge sort technique to sort the array items. But the sort method can be used in many other ways to have more control.

The python help says:


>>> help(list.sort) Help on method_descriptor: sort(...) L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*; cmp(x, y) ->-1, 0, 1

Things to note: The sort method doesn't return anything. It saves the changes in the list permanently. Thats why it is faster than the method sorted

SIMPLE SORT


>>> l = ['c', 'b', 'd', 'a'] >>> l.sort() >>> l ['a', 'b', 'c', 'd']
If elements are strings, they gets sorted by alphabetical order.

SORT IN REVERSE ORDER


>>> l =…

One day trip to Malshej Ghat

Image
Maharashtra offers a host of choices when it comes to hills ,valleys and forts.  Activities like trekking or rappelling are most popular here. 

Malshej is one of those places that will offer you its own specialty. 

Rocky mountains, deep gorges, Beautiful tunnels , roads snaking around. Uncountable waterfalls.Dense forest and its habitat. 


It's a power package for a day. One day escape from the daily hassles of life. Western Ghats for you ladies and gentlemen.


How to reach:
A road trip will be the best option. You don't want to miss the chance of stopping anywhere you want and click pictures or just stare in awe. 



How to plan:Start at early morning 6 AM.Reach Malshej in 3 hrs.Straight away park at the MTDC.Have break fast at the restaurant inside.Stroll behind the hotel . There is a beautiful pathway made for tourists.





Find a good waterfall. Enjoy bathing in it. It's just awesome .


 Return home before night.
Best time to go:Rainy season. June - August
Precaution:Before you plan, ch…

Writing context managers using Python

We use. We forget. This is for myself so I remember the magic called Context Manager. You already must have used the "with statement" for file handling, threads, socket and other operations. I am going to talk about creating you OWN context managers.

The magic operator to be used is : @contextmanager. It can be imported from the module "contextlib"

To create a context manager, use the decorator contextlib.contextmanager


@contextlib.contextmanagerdefgetListCounts(x): try: fromcollectionsimport Counter yield Counter(x) finally: print'No of elements in the list : %d' % len(x)

Let's now use the above context manager 

Example 1:
>>> with getListCount([10, 10, 12]) as c: print "Element occurring the most is %d" % c.most_common()[0][0] Element occurring the most is 10 No of elements in the list : 3
Example 2:
>>> with getListCount([10, 10, 12]) as c: print "Element occurring the least is %d"…

Python: Super class examples

Hi all. We are going to see some examples of usage of keyword 'super' here . 
Below code shows two classes Employee and Developer. A parent and a child.


classEmployee(object):def__init__(self,first,last):self.first=firstself.last=lastprint'Employee: {0}, {1}'.format(first,last)defhike_category(self):hike=0ifself.grade=='A':hike=(0.1*self.pay)+self.pay#percentelifself.grade=='B':hike=(0.15*self.pay)+self.pay#percentelifself.grade=='C':hike=(0.20*self.pay)+self.pay#percentreturn'{0},{1} gets {2}'.format(self.first,self.last,hike)classDeveloper(Employee):def__init__(self,fname,lname,grade,pay):super(Developer,self).__init__(fname,lname)self.grade=gradeself.pay=pay
Lets run the above program.

Results:

>>> d = Developer('arc', 'roy', 'C', 10000) Employee: arc, roy >>> d.hike_category() 'arc,roy gets 12000.0'
Observations and things to note
Above programming is done in Python 2.7. In 2.7, the class …

A week long vacation to Himachal

Image
DEV BHOOMI | LAND OF GODS | ABODE OF SNOW

Himachal has many meanings. And true to its meaning, I believe, the snow clad mountains is where the God's live.
Me and my wife made this 10 day trip from Jan 27th to Feb 5th 2017 starting from Delhi Airport.



The PlanDay 1 Day 2 Day 3 Day 4 Day 5 Day 6 Day 7 Day 8 Day 9 Day 10 Delhi Delhi to Shimla drive Shimla Shimla-Khufri Shimla to Manali Manali

CNTLM in Office

Image
If you are facing a proxy problem , CNTLM is a general option everybody considers. But the working of CNTLM is not always guaranteed. I myself get confused every time I need to use it.

What problem are we actually talking about?

While working in offices and restricted environments where firewalls and other invisible barriers stop your requests from going out, you sometimes need a way to temporarily jump over that barrier to get your job done . Example: You might face them while trying to install using pip in command line, trying to clone a personal git repository. 

What is CNTLM exactly?

I think this is best answered by the creator himself. Refer this. You can download it from here. For configuration, you an refer this. There are many uses of CNTLM but I am trying to solve my own problem here. So I will stick to breaking office barriers for now ;) .

Why do I need to use it :
1) Python package installations using PIP
2) Git operations : Cloning and pushing to server.

Here are a set of steps I …