Sunday, May 31, 2015

Just a blog : A quick guide to git and GitHub (Part 1)

There is plethora of git guides over internet, some are really good and some really suck. I here am writing a simple blog for the newbies who have successfully made an account over github and are really excited about it.

GitHub is a web-based Git repository hosting service, which offers all of the distributed revision control and source code management(SCM) functionality of Git as well as adding its own features. Unlike Git, which is strictly a command-line tool, GitHub provides a web-based graphical interface and desktop as well as mobile integration

Or simply

Github connects you with other people who are interested in sharing and creating together.

So there are really two ways to begin with. Here goes the first one.

Create a repository : Repository is what you call the bundle or stuff you are going to upload and work on. Go to https://github.com/new and create a repository. Let's name it hello-world.
Add some description, or you might want to add it later. Initialize it with a Readme. It's a good practice and let's you clone it immediately. (Yeah right, see below)

Clone it : Open your console, move to the directory where you want to work and do this.
 $ git clone https://github.com/username/hello-world.git
This will create a directory in your computer. Now, this isn't a simple directory. It is a 'clone' of the github repository. You can say that the files in it are controlled by the version control system git and tracked with the repository on github.

Do this,
 $ cd hello-world  
 $ git remote -v  
 origin    https://github.com/<username>/hello-world.git (fetch)  
 origin    https://github.com/<username>/hello-world.git (push)  
This shows that the link to repository of yours at github is known by the name origin over here.

Now another way of this is first you create the directory on your computer. Navigate inside it and do
 $ git init  
This will initialize an empty git repository inside it. Later, you can add the link to the repository by the git remote command like this
 $ git remote add origin https://github.com/<username>/hello-world  
You can always use git remote -v command to track the aliases.

Making the first change : Okay now we are in condition of adding some files or code to this repository. I am going to make a python file with hello world program and publish the change over the github repository too.
So make a new file say hello.py inside the directory, open it with your favorite editor and write the one line code to print whatever you want. Why just hello world? (Because dmr did it!) Now write it and save the file.

The first thing you should always do is to see whether you have done any changes or not in the repository. This can be done by
 $ git status  
After the changes you made, you must be getting this after git status
 On branch master   
  Your branch is up-to-date with 'origin/master'.   
  Untracked files:   
  (use "git add <file>..." to include in what will be committed)   
    hello.py   
  nothing added to commit but untracked files present (use "git add" to track)   
Add, Commit, Push! : In your console, do this.
 $ git add .  
This adds all the files in the track which you have changed.
Now it's time to commit that change. By committing, git understands that you want the change to be in record. Every commit is accompanied with a message that appears on the log (git log) Do this
 $ git commit -m "Added hello.py"  
You've made your first commit! But it won't be appearing over github, because you made the changes locally. You need to push it over the web. For that, you use
 $ git push  
Or,
 $ git push origin  
to say git where actually you are pushing it to. Or,
 $ git push origin master  
to say git over what branch on origin you are pushing it to.

That's it! You've published your changes to your GitHub repository.

NOTE : This is a very basic start. There are more concepts to be explored. You can search for specifics. StackOverflow has also great resource. This is one of those posts, which are not intended to bring the dark side of git to the face.

Happy Coding!

Tuesday, May 26, 2015

Why is Sublime Text not something to be frowned upon?

There have been people, advisers, and more people, enlightening the fact about "real programmers", they use emacs or vim.

'I use sublime text', is often misunderstood as 'I am a novice and I don't like pure black window'. There is no way this 7 years old editor is going to compete with 39 years old emacs and 15 years old clone of yet another 39 years old editor vi. Nevertheless, there's much more to come.

The first thing that Sublime Text lovers say about vim and emacs is "Why should I open an editor which I don't know how to get out of?" Fair enough. They are not mere text editors. They have built-in code to edit any external code. Isn't that pretty? Well, you have to follow some steps to close it. (Or you can forcefully shut down your console anytime you want. No matter they are powerful, you belong to the human race.) They also have more powerful features which make its user's life easy.

But before you'll think of your easy life, they'll make you hate your life first. As Pascal Precht in one of his blogs discuss about the learning curve wall of vim. Here is a picture which is very explanatory.


The next argument by emacs users are "We don't like using touchpad and want everything right there in our editor, like mail, news, everything!"

You are great sir! But let me also tell you, you are rare and have wrong conclusion about sublime users. We aren't fond of touchpad either! As of me, I survived a whole semester of college with my touchpad not working. But that doesn't mean I moved to emacs or vim. subl to open, pgup pgdn and arrow keys for navigation, ctrl + s to save, ctrl + t for new tab, I mean I had got everything done with my keyboard and the fact is that Chrome also obeys these commands (or vice-versa). Imagine you scrolling through a webpage and wondering why j and k are not helping you.

The point I'm trying to make is why shouldn't we encourage newbies to use the editor which makes their life really easy very fast so that they could simply learn how to code rather then learning how to code to code. Later on, let them decide whether they really dislike this editor and move on to something more challenging and I believe some people will surely move on to the challenging ones. 

But I will surely not. I'll wait for the day when I'll get tired of putting my hands on something so beautiful.

Friday, May 15, 2015

Morse Talk : My first Python package

Something strange happened with me two days ago. I was reading about Dennis Ritchie, the creator of C and Unix, and I came to know that he has been awarded Turing Award for that. It's just another Million Dollar prize also recognized as 'Nobel Prize for Computing'. Anyways, I carried on reading, came to know about Alan Turing, the man behind the Enigma Machine and then I got really fascinated by Cryptography. Out of nowhere (or maybe related?), I got excited about Morse Code. Maybe because of a recent re-watch of the movie Interstellar in which Cooper uses Morse code to transfer the message 'STAY' to his daughter Murph. In next few hours I wrote two functions to encode and decode in Morse and its binary equivalent. I faced few difficulties in writing the decode function specially in placing gaps between the words. However, I still don't have any code to decode a binary encoded message.

So, What is the use case?
Seriously, I have no idea. I just searched out and there were not many efficient code dealing with this. So, I thought of putting it up. I have hosted the project on github (https://github.com/orkohunter/morse-talk) and released the first version with minimal functionalities on pypi (https://pypi.python.org/pypi/morse-talk). This all was really fun!

Though I've got a lot of studying these days because there are only ten days for the coding period to start for my Google Summer of Code project, I managed to work on that. I'm not pretty much serious on Morse Talk, but I'll see later what could happen. The possible features which could come to my mind in two days are

  • Enunciating Feature
  • Morse Tutor
  • Something to do with generating waveforms (I don't know much about that)
Maybe I'll seek out more ideas in college. Maybe not. Who knows?

Happy Coding!