Skip to main content

Posts

Learn BASH with me in 5 mins

I just started learning Linux bash from today. From my first impression of the language, I infer that it is a language with all the basic capabilities as of an infant high level language. May be I am right or wrong.Time will tell . We will keep going and keep discovering gradually. Let's start with the usual protocol of learning a language.

The HELLO WORLD program.
How to print things in shell. This is the first thing everyone wants to know while learning any language.

Anything that is not a variable is printable . And we print/echo it using the famous ECHO keyword

$ echo hello world hello world
Printing a number.
$ echo 1 1 Printing a string with double quotes$ echo"my name is arindam" my name is arindam Printing a string with single quotes$ echo'my name is Arindam' my name is Arindam Printing a number with quotes$ echo'1' 1
Creating  Variables and recalling them.
So how can we store things. How to recall that stored value. How to change that value.

X=9…

An early morning trek to Ghangad Fort

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

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 Winter's tale: First trip of the year to Himachal

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 Plan Day 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