Friday, July 21, 2017

How to learn python ? in Simple language.

The most important question to answer first is why do I want to learn python?Answering this will guide what you use to learn and how you learn.

Starting with a very generic list of resources to learn python when you eventually want to make websites (for example), will not only reduce your motivation, it will also make it much harder to apply the knowledge you gain.  I've tried to learn coding without context and application, and I've almost never come out of it with any meaningful skills.

When I learned python 3 years ago, I wanted to create websites.  It shouldn't come as a shock to anyone that the best way to learn how to do this was to create websites.

1.  Find what motivates you

Finding and keeping your motivation is key -- I slept through a lot of the one high school programming class I took because it made us memorize a bunch of syntax.  On the other hand, when I needed to learn python to make an automated essay scoring algorithm, I stayed up many late nights learning and iterating.

Motivation is rarely addressed in learning -- you're often just given a list of generic tutorials to try, and told to go do them.  But the great thing about python is that you can develop almost anything, from mobile apps to games to advanced machine learning algorithms.  No matter what you're interested in, you can probably build it in python, and there's probably a good getting started tutorial.

Pick an area or two that you're interested in, and stick with them-- you'll be developing quite a few projects in the areas.

Here are some sample areas, but feel free to add your own:
  • Websites
  • Mobile apps
  • Games
  • Data science/Machine learning

2.  Learn some basic python syntax

Unless you know the basic syntax, it's hard to implement anything.  That said, don't spend too long on this.  The goal is to learn the very basics, so you know enough to start working on your own projects in your areas(s) of interest.

For reference, I spent less than a week on codecademy, and went through about 30% of the material.  This was enough to get started on a project.

Some resources that can help you:

I can't emphasize enough that you should only spend the minimum amount of upfront time possible on basic syntax.  The quicker you can get to working on projects, the faster you will learn.  You can always refer back to the syntax when you get stuck later.

3.  Make structured projects in your chosen area

Unless you actually apply your knowledge, you won't be able to retain it well.  Projects are a great way to learn because they push your capabilities, show you how to apply skills, and give you a portfolio to show employers in the future.

When you start out, it can be helpful to have more structured projects with some guidance.  Here are a few ideas:

Games
Websites
Mobile apps
  • Kivy guide -- Kivy is the tool that lets you make mobile apps with python.  They have a guide on how to get started.
Data science
  • Dataquest.io --  Teaches you python and data science interactively.  You analyze a series of interesting datasets ranging from CIA documents to NBA player stats.
  • Scikit-learn documentation -- Scikit-learn (the main machine learning library for python) has some great documentation and tutorials.
  • Python for Data Analysis -- written by the author of a major python data analysis library (pandas), it's a good introduction to analyzing data in python.

4.  Work on projects on your own

Once you have learned the concepts in a guided manner, it's time to work on some projects on your own.  You'll still need to consult references and look up concepts, but you'll be fitting what you learn into the needs of your project, not the other way around.

Finding other people to work with here can both help you learn and help keep you motivated.

Some ideas:
  • Extend the projects you were working on previously, and add more functionality.
  • Go to python meetups in your area, and find people who are working on interesting projects.
  • Find open source packages to contribute to.
  • See if any local nonprofits are looking for volunteer developers.
  • Find projects other people have made, and see if you can extend or adapt them.
My first project was adapting my automated essay scoring algorithm from R into python.  It didn't end up looking pretty, but it started me on the journey to learning python.

The key is to pick something and do it.  If you get too hung up on picking the perfect project, there's a risk that you'll never make one.

5.  Keep working on harder projects

Keep increasing the difficulty and scope of your projects.  If you're completely comfortable with what you're building, it means it's time to try something harder.

Here are some ideas for when that time comes:
  • Try teaching a novice how to do your current project.
  • Try load testing your website -- can you scale it up?
  • Can you make your program run faster?

Going forward

At the end of the day, python is evolving and changing all the time.  There are probably only a few people who can legitimately claim to completely understand it. 

You'll need to be constantly learning and working on projects.  If you do this right, you'll find yourself looking back on your code from 6 months ago and thinking about how terrible it is.  If you get to this point, you're on the right track.

Python is a really fun and rewarding language to learn, and I think anyone can get to a high level of proficiency in it if they find the right motivation.

Thursday, June 29, 2017

How does one with no prior experience learn Git?

To be honest, learning Git is quite easy. I really don’t understand the fuss that’s going on about it being tough to learn.
Let me take you through the basics first.
Before starting with Git, let us know what is Version Control.
Version Control is the management of changes to documents, computer programs, large websites and other collection of information.
There are two types of VCS:
  • Centralized Version Control System (CVCS)
  • Distributed Version Control System (DVCS)
Centralized VCS
Centralized version control system (CVCS) uses a central server to store all files and enables team collaboration. It works on a single repository to which users can directly access a central server.
Please refer to the diagram below to get a better idea of CVCS:
The repository in the above diagram indicates a central server that could be local or remote which is directly connected to each of the programmer’s workstation.
Every programmer can extract or update their workstations with the data present in the repository or can make changes to the data or commit in the repository. Every operation is performed directly on the repository.
Even though it seems pretty convenient to maintain a single repository, it has some major drawbacks. Some of them are:
  • It is not locally available; meaning you always need to be connected to a network to perform any action.
  • Since everything is centralized, in any case of the central server getting crashed or corrupted will result in losing the entire data of the project.
This is when Distributed VCS comes to the rescue.
Distributed VCS
These systems do not necessarily rely on a central server to store all the versions of a project file.
In Distributed VCS, every contributor has a local copy or “clone” of the main repository i.e. everyone maintains a local repository of their own which contains all the files and metadata present in the main repository.
You will understand it better by referring to the diagram below:
As you can see in the above diagram, every programmer maintains a local repository on its own, which is actually the copy or clone of the central repository on their hard drive. They can commit and update their local repository without any interference.
They can update their local repositories with new data from the central server by an operation called “pull” and affect changes to the main repository by an operation called “push” from their local repository.
The act of cloning an entire repository into your workstation to get a local repository gives you the following advantages:
  • All operations (except push & pull) are very fast because the tool only needs to access the hard drive, not a remote server. Hence, you do not always need an internet connection.
  • Committing new change-sets can be done locally without manipulating the data on the main repository. Once you have a group of change-sets ready, you can push them all at once.
  • Since every contributor has a full copy of the project repository, they can share changes with one another if they want to get some feedback before affecting changes in the main repository.
  • If the central server gets crashed at any point of time, the lost data can be easily recovered from any one of the contributor’s local repositories.
After knowing Distributed VCS, its time we take a dive into what is Git.
What Is Git?
Git is a Distributed Version Control tool that supports distributed non-linear workflows by providing data assurance for developing quality software. Before you go ahead, check out this video on GIT which will give you better in-sight.
Git Tutorial – Operations & Commands
Some of the basic operations in Git are:
  1. Initialize
  2. Add
  3. Commit
  4. Pull
  5. Push
Some advanced Git operations are:
  1. Branching
  2. Merging
  3. Rebasing
Let me first give you a brief idea about how these operations work with the Git repositories. Take a look at the architecture of Git below:
If you understand the above diagram well and good, but if you don’t, you need not worry, I will be explaining these operations in this Git Tutorial one by one. Let us begin with the basic operations.
I will show you the commands and the operations using Git Bash. Git Bash is a text-only command line interface for using Git on Windows which provides features to run automated scripts.
After installing Git in your Windows system, just open your folder/directory where you want to store all your project files; right click and select ‘Git Bash here’.
This will open up Git Bash terminal where you can enter commands to perform various Git operations.
Now, the next task is to initialize your repository.
Initialize
In order to do that, we use the command git init. Please refer to the below screenshot.
git init creates an empty Git repository or re-initializes an existing one. It basically creates a .git directory with sub directories and template files. Running a git init in an existing repository will not overwrite things that are already there. It rather picks up the newly added templates.
Now that my repository is initialized, let me create some files in the directory/repository. For e.g. I have created two text files namely edureka1.txt and edureka2.txt.
Let’s see if these files are in my index or not using the command git status. The index holds a snapshot of the content of the working tree/directory, and this snapshot is taken as the contents for the next change to be made in the local repository.
Git status
The git status command lists all the modified files which are ready to be added to the local repository.
Let us type in the command to see what happens:
This shows that I have two files which are not added to the index yet. This means I cannot commit changes with these files unless I have added them explicitly in the index.
Add
This command updates the index using the current content found in the working tree and then prepares the content in the staging area for the next commit.
Thus, after making changes to the working tree, and before running the commitcommand, you must use theadd command to add any new or modified files to the index. For that, use the commands below:
git add <directory>
or
git add <file>
Let me demonstrate the git add for you so that you can understand it better.
I have created two more files edureka3.txt and edureka4.txt. Let us add the files using the command git add -A. This command will add all the files to the index which are in the directory but not updated in the index yet.
Now that the new files are added to the index, you are ready to commit them.
Commit
It refers to recording snapshots of the repository at a given time. Committed snapshots will never change unless done explicitly. Let me explain how commit works with the diagram below:
Here, C1 is the initial commit, i.e. the snapshot of the first change from which another snapshot is created with changes named C2. Note that the master points to the latest commit.
Now, when I commit again, another snapshot C3 is created and now the master points to C3 instead of C2.
Git aims to keep commits as lightweight as possible. So, it doesn’t blindly copy the entire directory every time you commit; it includes commit as a set of changes, or “delta” from one version of the repository to the other. In easy words, it only copies the changes made in the repository.
You can commit by using the command below:
git commit
This will commit the staged snapshot and will launch a text editor prompting you for a commit message.
Or you can use:
git commit -m “<message>”
Let’s try it out.
As you can see above, the git commit command has committed the changes in the four files in the local repository.
Now, if you want to commit a snapshot of all the changes in the working directory at once, you can use the command below:
git commit -a
I have created two more text files in my working directory viz. edureka5.txt and edureka6.txt but they are not added to the index yet.
I am adding edureka5.txt using the command:
git add edureka5.txt
I have added edureka5.txt to the index explicitly but not edureka6.txt and made changes in the previous files. I want to commit all changes in the directory at once. Refer to the below snapshot.
This command will commit a snapshot of all changes in the working directory but only includes modifications to tracked files i.e. the files that have been added with git add at some point in their history. Hence, edureka6.txtwas not committed because it was not added to the index yet. But changes in all previous files present in the repository were committed, i.e. edureka1.txtedureka2.txtedureka3.txtedureka4.txtand edureka5.txt.
Now I have made my desired commits in my local repository.
Note that before you affect changes to the central repository you should always pull changes from the central repository to your local repository to get updated with the work of all the collaborators that have been contributing in the central repository. For that we will use the pull command.
Pull
The git pull command fetches changes from a remote repository to a local repository. It merges upstream changes in your local repository, which is a common task in Git based collaborations.
But first, you need to set your central repository as origin using the command:
git remote add origin <link of your central repository>
Now that my origin is set, let us extract files from the origin using pull. For that use the command:
git pull origin master
This command will copy all the files from the master branch of remote repository to your local repository.
Since my local repository was already updated with files from master branch, hence the message is Already up-to-date. Refer to the screen shot above.
Note: One can also try pulling files from a different branch using the following command:
git pull origin <branch-name>
Your local Git repository is now updated with all the recent changes. It is time you make changes in the central repository by using the push command.
Push
This command transfers commits from your local repository to your remote repository. It is the opposite of pull operation.
Pulling imports commits to local repositories whereas pushing exports commits to the remote repositories .
The use of git push is to publish your local changes to a central repository. After you’ve accumulated several local commits and are ready to share them with the rest of the team, you can then push them to the central repository by using the following command:
git push <remote>
Note : This remote refers to the remote repository which had been set before using the pull command.
This pushes the changes from the local repository to the remote repository along with all the necessary commits and internal objects. This creates a local branch in the destination repository.
Let me demonstrate it for you.
The above files are the files which we have already committed previously in the commit section and they are all “push-ready“. I will use the command git push origin master to reflect these files in the master branch of my central repository.
Let us now check if the changes took place in my central repository.
Yes, it did. :-)
To prevent overwriting, Git does not allow push when it results in a non-fast forward merge in the destination repository.
Note: A non-fast forward merge means an upstream merge i.e. merging with ancestor or parent branches from a child branch.
To enable such merge, use the command below:
git push <remote> –force
The above command forces the push operation even if it results in a non-fast forward merge.
If you want to learn branching, merging and other operations, read the full blog here: Git Tutorial | Commands And Operations In Git | Edureka
OR
Watch this Video:
Happy Learning! :)

Sunday, April 2, 2017

  1. This program will print 1 to 100 without using any loop and recursion.
  1. #include<stdio.h>
  2. int i;
  3. void b(){
  4. printf("%d\n",i++);}
  5. void c(){
  6. b(),b(),b(),b(),b();}
  7. void a(){
  8. c(),c(),c(),c(),c();}
  9. void main(){
  10. i=1;
  11. a(),a(),a(),a();
  12. }
2. Print hello without using any semicolon in the program.
1st method:
  1. #include<stdio.h>
  2. void main(){
  3. switch(printf("hello")) {}
  4. }
2nd method:
  1. #include<stdio.h>
  2. #define PRINT printf("hello")
  3. void main(){
  4. if(PRINT){}
  5. }
3rd method:
  1. #include<stdio.h>
  2. void main(){
  3. while(!printf("hello")){}
3.Program to print "Hello Quora" using if and else both statement.
  1. #include <stdio.h>
  2. void main(){
  3. if(!printf("Hello "));
  4. else printf("Quora\n");
  5. }
4. C Program to print source code as program output
  1. #include <stdio.h>
  2. int main(void){
  3. FILE *fp;
  4. char c;
  5. fp = fopen(__FILE__, "r");
  6. do { c=fgetc(fp); putchar(c); }
  7. while(c!=EOF); fclose(fp);
  8. return 0;
  9. }
Output (above source code is output):

Saturday, January 28, 2017

Which competitive programming site is good for beginners?

Today one of my friend asked me this question after doing some research on that topic , from google ,quora , wikipedia  I myself landed with this conclusion listed below : -


  1. Infrastructure and UI
    1. CodeChef: Light weight web pages, don't need a really good internet connection to work. Sometimes sucks during heavy traffic contests. Not so cool leaderboard. No direct way to retrieve submissions from leaderboard. Unlike other platforms, only verdict is shown for submission, not number of files or test case numbers.
    2. Codeforces: Again, light web pages, no scalability issues even in heavy traffic. Very intuitive and slick UI, cool leaderboard. Best rating system among all.
    3. HackerEarth: Code editor is available, nice leaderboard. Haven't seen any scalability issues lately. However, contests page cluttered with lot of hiring challenges.
    4. HackerRank: Heavy web pages; with slow internet connection, you might find it difficult to use. No such things as friends/lists as available in other platforms. Good stuff: Code editor available, problem-wise leaderboard, can directly get solutions from leaderboard.
  2. Quality of problems and about contests
    1. CodeChef: Great problems in long and short challenges. Unique format of long challenges, which is great for beginners I think.
    2. Codeforces: High quality problems from highly rated coders. I most enjoy the problems on CF. Only short contests for two divisions. A great feature: educational rounds. No prizes or tshirts for winners as compared to others.
    3. HackerEarth: Recently, good problems in contests like Clash. Easy contests for beginners are a good learning source. Monthly two contests.
    4. HackerRank: Very good structured content topic wise. A project-Euler style contest called infinitum. I liked HourRank(a one-hour contest). No more weekly contests as before.
  3. Editorials and community supportI think for a beginner these factors are the most important.
    1. CodeChef: Good and detailed editorials by dedicated editorialist for each contest. However, less community participation in discussions.
    2. Codeforces: Best in this regard. Editorials written by problem setters. Sometimes brief, but amazing community support. A lot of top rated users discuss very regularly on CF. You can ask people from around the world your queries/doubts and people visit the website very regularly just to browse the blog posts.
    3. HackerEarth: Dedicated editorialists, good editorials, but again, very little community participation.
    4. HackerRank: Problem setters write the editorials which sometime are not so helpful. Scarce community participation.
Considering all aspects, my vote goes to Codeforces. Some other things I like about Codeforces are:
  • GYM contests. Its an archive of various competitions from all around the world like previous ICPC regionals. Most teams preparing for ICPC do virtual contests, which means a virtual competition where you can gauge your preparation levels.
  • Virtual contests. You can simulate the whole contest environment and do the contests which you missed.
  • Mashup contests and groups. You can create groups with your friends and compete on problems chosen by you.