Paswordless Git push

If you use git to maintain code for your projects then automating the git pushes is a nice to have feature. Following steps I have tried on github.com and it works. If you use other git service provider then step-1 might be different, otherwise all other steps remain same.

  1. Follow the steps mentioned in generate ssh key to add a new ssh private and public key to your machine and github account.
  2. Check out your package using git (not https) url which internally uses SSH. If you have already checked out the source code using https then following below steps to reassign new url.

Example of HTTPS url used by a git repository:


➜ brainz git:(master) git remote -v
origin https://github.com/abnayak/brainz.git (fetch)
origin https://github.com/abnayak/brainz.git (push)

Change the HTTPS protocol to git


➜ brainz git:(master) git remote set-url origin git@github.com:abnayak/brainz.git
➜ brainz git:(master) git remote -v
origin git@github.com:abnayak/brainz.git (fetch)
origin git@github.com:abnayak/brainz.git (push)

That’s it, now you can push your code to github without being prompted for username and password.

 

Building C++11 code in Sublime Text 3

By default Sublime Text does not build C++ with C++ 11 features. Follow below steps to activate the c++ 11 building feature in Sublime Text 3.  Steps are tested on Windows. I don’t think this will be too different on Mac or Linux except the shortcut.

  1. Install PackageResourceViewer plugin
  2. Open the command center by entering Ctrl + Shift + p
  3. Type “PackageResourceviewer: Open Resource”
  4. Then C++ –>  C++ Single File.Sublime-build , this will open the build config file for C++
  5. Where ever you g++ add -std=c++11 infront of it and save the file

How to delete a folder in UNIX starting with dash/s (-)

Recently while working in Linux, accidentally I created a folder named “–versionset”. I was quite a tuff task to delete the folder as this name is parsed as option to rm command. After searching a bit found a solution in stackoverflow to disable dashes during the parsing. Here is the command you need to use to remove a file starting with dashes.

rm -rf -- --versionset

— in the command deactivates the parsing the dashes in the file name.

How to Interpret Pointers in Expressions

Use the following rules to decode pointer types in expressions:

[1]
The best way to read a type is from left to right. A few examples:
int const x = 9; – the const applies to whatever appears to its left, therefore the int is const
int const *p = &x; – again, the const applies to the int, not to the pointer. You can change the value of p but not the value of whatever p points to
int *const g = &i; – const applies to the pointer, not to the int. You can change the value pointed by g but you can’t change the pointer g
The same rule can be used to read references and pointers to pointers:
int **h; – read from right to left: a pointer to a pointer to an int
int const *const *r; – a non-const pointer to a const pointer to const int
int const &a; – a reference to a const int
int const *n; – a non-const pointer to a const int. You can change the pointer but you can’t change the value of what it points to
int const *&k = n; – a reference to a non-const pointer to a const int. You can’t change the value of what the pointer points to. Since you have a reference to a pointer, changing k will also change the pointer n

The only exception to that rule is when there’s nothing to the left of a const, in which case the const is applied to whatever appears to its right:
const int x = 9; – the const applies to the int
const int *p = &x; – again, the const applies to the int, not to the pointer. You can change the value of p but not the value of whatever p points to
const int const y = 10; – compilation error: both consts apply to the int
const int const *g = &x; – again, a compilation error: both consts apply to the int, not to the pointer

All the information is derived from the below Quora post. All credit goes to the original author of the post.

https://www.quora.com/Why-are-we-returning-the-reference-of-a-pointer-of-a-pointer

Constant Pointer & Pointer to Constant

In the above program comment out line no 14 and 18 for successful compilation.

Pointers can be of two types

1. Constant Pointer: In this case the pointer is constant, this is similar to ‘const int’. So, this type of pointers should initialized at the point of definition and only point to a single memory location through out the life time.

2. Pointer to Constant: In this case the pointer is pointing to a read only memory location, i.e it’s holding memory location of a constant. This type of pointers behave like a normal pointer but you can’t assign a new value by pointer de-referencing ‘*’ operator.

Why CD is a shell in-build command

We will go in reverse way. What would have happened if cd was implemented as a external command. Bash has to fork a new process and that process will run cd, which in tern change the folder to the destination location. What ever folder change happened that is only effective for the child process and our original process which forked the cd process still in the old directory. So, at the end of the cd execution we are still inside the old folder.

This is the reason why cd is shell in-build function. There are hack which can have the same effect of cd when implemented as external process but that requires more complex coding.