Strolling with Aman A voyage to infinity.

Chilika Lake : The Best of Odisha

So it had been one and a half year since I landed in Odisha, The soul of Incredible India and I hadn’t explored any of Odisha’s great landscapes except a short trip to Udaygiri and Khandagiri, so to consume the wanderlust generated over three semesters, We (I and my 9 other friends) decided to had a detour from our monotonous college life and visit Chilika Lake, Asia’s largest brackish water lagoon. We boarded a passenger train from Khurda Road Junction to Balugaon and reached there in early morning. We picked up few snacks to eat and hired a motor boat for approximately ₹2500 and started our voyage into the heart of the lake. The water was skyline-silver and window clear, the only sound piercing in shimmering emptiness of surrounding space was of the boat’s engine and cacophony of our group of 10 people. It was astounding to see the callow reflection of sun rays glimmering in our eyes.

The lake has two mini islands floating on its surface and like any other tourist attraction of Odisha, both islands are acquired by religious trusts to offer devotion to sacred local goddesses thus the many tourists there were families on their pilgrimage. The another major attraction on the lake is the Bird Sanctuary where tons of flamingos arrive every season to blossom the Indian wildlife heritage. Unfortunately, we visited the sanctuary in a little off season so there weren’t as many birds as we expected. Also our boatman told about the recent decline in the numbers of birds visiting each year due to different climate change factors. The main attraction of the Chilika Lake is undoubtedly the presence of Irrawaddy Dolphin in its brackish water. Sadly there are only 134 dolphins left in the lake spanning an area of 1165km² as per 2017 census so you must have an extraordinary fortune to catch a glimpse of this endangered species of fish.

By the time we finished our voyage and started returning back to the coast, the sun was also ready to submerge in the distant water and it was the best possible farewell moment to bid us adieu from a wonderful day by the mother nature. If you have any query about planning a trip from Bhubaneswar to Chilika Lake, feel free to ping me.

Web Scrapping with Python

Internet has superabundant information and knowledge but to extract that knowledge in organised, scalable and systemetic way for data analysis and other research purpose is known as Web Scrapping.

Web Scrapping automatically extracts the data from a particular website and present it in user desired form. We can scrap many things from the web like Stock updates, Price of any product from Amazon. In this post I’ll scrap news updates from my college’s website.

Getting Started

We can use almost any scripting language for web scrapping however the popular options are Javascript and Python. Both Javascript and Python have rich set of scrapping libraries like CheerioJS for Javascript and Scrapy, BeautifulSoup for Python.

I’ll use Python and BeautifulSoup for this post because both Python and BeautifulSoup are beginner friendly.

  • For Mac and Linux users, Python is preinstalled.
  • Windows users can install Python from official website.

For installing BeautifulSoup library, simply enter following command in terminal.

pip install beautifulsoup4

Finding Target from HTML

All the news & updates of IIT Bhubaneswar are enlisted on this webpage. Visit this Webpage and press Ctr + Shift + I to inspect source code of the webpage. Now click on the the mouse button present on the top-left part of inspector panel and hover over list of news updates. We can see in inspector panel that all news and updates of that webpage are inside an unordered list with class rectlist.

<ol class="rectlist">

Thus we have to scrap all list items present in aforementioned unordered list.

Writing script for scrapping

After running this script we’ll get required result in terminal.

You can learn more about BeautifulSoup library by visiting it’s official documentation.

Other Resources:

Update: I recently came to know another very good resource(https://likegeeks.com/python-web-scraping) for Web Scrapping. I think you may also like it.

Warning: Scrapping data from certain website may violate their Terms and Conditions or Privacy Policy. Please check such things before deploying any scrapper. Most of the websites also have a file named robots.txt on their server which lists all such webpages that shouldn’t be crawled so check for such files before scrapping from any site. For e.g. robot.txt file of Google is present on this link.


You can comment below any doubt / criticism or compliment. Also if you like this post please share it among your hacker friends. Don’t forget to bookmark my blog and keep visiting frequently. Bonne journee!

Setting up Competitive Programming Environment

This blog post emphasize some random Gyan which may be useful for competitive programmers during coding contests.

1. Chosing an Operating System

Almost every beginner use Windows but the OS preferred by veteran developers and programmers is certainly Linux as it provide a better coding experience and plethora of customization opportunities.

The following article describe why you should consider using Linux:
7 Superb Reasons Why You Should Use Linux For Programming

Chosing a Linux Distro

The another great thing about Linux is that there are plenty of distros available. Few popular distros are:

  • Ubuntu
  • Fedora
  • CentOS
  • Mint
  • openSUSE

I personally work on Ubuntu as it is one of the most popular distro with awesome community support and its package manager library apt and dpkg have almost all requisite packages for a good coding setup. You can chose any distro as they are almost similar to each other.

If you don’t want to miss the awesome graphical aesthetics of Windows, Linux can be dual booted alongwith Windows (I prefer this way): Dual booting windows with Ubuntu

Simplify your life by Bashing

The most useful tool offered by UNIX like operating system is BASH. Yeah, the same prompting green shell that Hackers use in hollywood movies. The basic commands like cd, ls, mkdir, rm, chmod are quite handy while interacting with FHS.
It is advised to learn basic Linux shell commands before proceeding. You can enroll in this free introductory course offered by The Linux Foundation on edX.

Useful Linux Packages

  • Git
    It is a version controlling system build by Linux founder Linus Torvalds. You can learn it in just 15 minutes here. Execute the following code in terminal to install git (for Ubuntu):
    sudo apt-get update
    sudo apt-get install git
    

    Configure git:

    git config --global user.email "[email protected]"
    git config --global user.name "Your Name"
    
  • Google Chrome
    No need to say anything on this. Here is the command to install:
    sudo apt-get install libxss1 libappindicator1 libindicator7
    wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    sudo dpkg -i google-chrome*.deb
    
  • VLC Media Player
    Again, no need to say anything. Here is the command to install:
    sudo apt-get update
    sudo apt-get install vlc browser-plugin-vlc
    
  • MacBuntu
    Intrested in customizing your ubuntu to display like a MacBook? for eg. Following is the screenshot of my Desktop:
    This is the link of MacBuntu installation guide.

2. Chosing a Programming Language

The most important weapon for a competitive programmer is Programming language. You can do competitive programming in almost any language but the language preferred by most of the programmers is C++ followed by Java and Python. ACM ICPC allows only 4 languages (C/C++, Java and Python) in world finals. I personally use C++ because of its awesome STL(Standard Template Library) and also it is a bit faster than Java. Java is heavily based on OOP so even writing a simple Hello World! program require many lines. Also it is very easy for C programmers to step up on C++ as C is a subset of C++. Using C++ is advisable alongwith basic knowledge of Python as Python can be helpful while dealing with big integers. Following pie chart shows the most used programming language on Hackerearth online judge. You can enroll in C++ course offered by John Purcell on Udacity to learn basic C++ programming. However if you prefer learning from textual tutorials, http://www.cplusplus.com/doc/tutorial/ can be useful for you.

Few useful C++ tricks:

  • Speedify C++ I/O
    The standard C++ I/O functions (cin/cout) flush the buffer on every next I/O call which unncecessarily increase I/O time. For enhancing C++ I/O speed, you can either use C’s standard I/O function (scanf/printf) instead of (cin/cout) or you can write the following lines in main function.
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    

    Similarly the C++ endl also flush the buffer. You can either use C’s '\n' instead of endl or you can write the following macro in your C++ file.

    #define endl '\n'
    
  • Get rid of those includes!
    Simply use
    #include <bits/stdc++.h>
    

    This library includes many of libraries we do need in contest like algorithm, iostream, vector and many more. Believe me you don’t need to include anything else


3. Chosing a Text Editor

Many programmers prefer an Integrated Developement Environment(IDE) like Code::Block, DevC++, Eclipse etc. but I think using an IDE for competitive programming is an overkill. Personally for me IDEs are best suited for big developement projects, however I feel more efficient on Text Editors like Sublime Text in coding contests. Also text editors provide plethora of shortcuts like Ctrl + D, Ctrl + KK, multiple cursors etc. to make your life fast and easy. I prefer Sublime Text over Atom as Atom is built with Electron which is powered by Chrome engine thus making Atom slow while booting. You can install Sublime Text by executing following command in your shell:

sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer

You can run sublime text either clicking its icon in search menu or by executing following command in shell:

subl file_address.extension

To improve Subime Text’s aesthetics, you can install themes like Brogrammer from Package Control. For that you have to first install Package Control followed by Brogrammer.

Screenshot of my Sublime Text: My Sublime Text 3

Using sublime without knowing its super useful shortcuts is futile.

You must learn useful sublime text’s shortcuts to gear up your coding speed. Click Here for Sublime text shortcuts cheatsheet. Don’t forget to bookmark them.

Sublime Text Snippets feature:

Quoting from Sublime Text documentation:

Whether you are coding or writing the next vampire best-seller, you’re likely to need certain short fragments of text again and again. Use snippets to save yourself tedious typing. Snippets are smart templates that will insert text for you and adapt it to their context.

For a C++ programmer writing macros, typedef, including libraries etc. everytime while creating a new file can be a WET practice. So to DRY up this you can use sublime snippet feature.

To create a new snippet, select Tools > Developer > New Snippet…. Sublime Text will present you with skeleton for a new snippet.

Now delete everything and copy-paste the following:

<snippet>
	<content><![CDATA[
	<!-- Your Snippet Code here -->
}
]]></content>
	<tabTrigger>code</tabTrigger>
</snippet>

Replace <!-- Your Snippet Code here --> comment with your desired snippet. Now save the file in default directory with a name like cpp.sublime-snippet.

For example following is my C++ snippet code:

/**
*	Name: Aman Pratap Singh (@apsknight, </www.apsknight.cf>)
*	Institute: Indian Institute of Technology Bhubaneswar 
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define debug(x) cout << '>' << #x << ':' << x << "\n";
#define endl '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define maxx 1e6+7

int main() {
	off;
	$0

  	return 0;
}

For triggering this you have to just type code + TAB in your C++ file. Notice the $0 sign in 2nd line of main function in my snippet. This $0 sign tells sublime to place the cursor here after triggering the snippet.

Beside this, Sublime also has plenty other useful features, to learn them you may consider downloading this awesome book by Wes Bos.

You can also visit this blog for setting up sublime for your coding environment: http://blog.codingblocks.com/2017/setting-up-sublime-text-for-competitive-coding

  • Vim (Most famous CLI text editor due to Large plugin support and customization)
  • Emacs (Another famous CLI text editor)
  • Notepad++
  • Gedit (Default text editor of Ubuntu)
  • Visual Studio (Famous text editor by Microsoft)

4. Other useful Gyan

Some useful things that may save your life during your proramming journey.

Code Hosting

Suppose you stucked in an infinite loop or segmentation fault while solving a problem and you realize that your friend may help in this case. In this case sending your code to your friend on FB Messanger/Whatsapp/Hike or Emailing the code is not certainly a good idea. Here comes the sites such as pastebin, ideone which may help you by hosting the code on their server and you can share just a tiny URL to your friend.

There are quite a few such services available on Internet. Following are some of them:

Personally I prefer the last one http://paste.ubuntu.com/ because of its Gedit like Rich Synax Highlighting, nice UX and no Login/Authentication is required. Also the sharing link of Ubuntu Paste’s is much shorter than other.

Cloud9 - The next generation IDE

Cloud9 combines a powerful online code editor with a full Ubuntu workspace in the cloud. Cloud9 supports more than 40 languages. This may be useful when you have to code and you don’t have your laptop around. This service provide you an IDE in your browser which require only good internet connection. It also provide many other features like workspace sharing, simultaneous coding, built-in terminal, awesome debugger and much more. You can create one private workspace and unlimited public workspace with a free account. For knowing more about Cloud9, Visit https://c9.io.

GDB and Valgrind

GDB is a debugger built by GNU which can help you in debugging your C++ files and Valgrind is a tool which can check if there is any memory leakage in your program. For nore details about them, you can refer to these videos: GDB, Valgrind

Markdown

Markdown is a markup language like HTML. Learning it may not be important but it may be useful in writing rich comments. Some online judges like Codechef support writing comments with markdown. Also it is an important tool while writing documentation of your code (which probably you’ll never do in competitive programming). Markdown is quite useful in web development. This blog post is also written in markdown.
You can learn basic markdown here, You should also bookmark markdown cheatsheet for your future reference.

Shell scripting

Shell scripting can be useful for automating repetitive stuff. For eg. I created following script for my cloud9 IDE, which on executing ask for a problem code and create a new C++ file.

#!/bin/sh
# Navigate to the folder in which the file has to be created. 
echo Program Code?
# Ask for Program code.
read code
# path is variable storing absolute file path.
path=$(pwd)/$code.cpp
# touch(create) file.
touch $path
# Write default snippet in 
echo "#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\n#define repeat(i,n) for(int i = 0; i < n; i++)\n\nint main() {\n\tios_base::sync_with_stdio(0);\n\tcin.tie(0);\n\n\treturn 0;\n}" >> $path
c9 $path
echo "Okay! Done :)"

You can also find this script in my Github repository.
Visit this awesome tutorial for learning shell scripting.


Image Source: Geeksforgeeks, Hackerearth
You can comment below any doubt / criticism or compliment. Also if you like this post please share it among your hacker friends.
Don’t forget to bookmark my blog and keep visiting frequently. Bonne journee!