Posts

Vim goto definition

For navigation in large code bases. Mostly these have been tried with C/C++, but works similarly for other languages - Go, PHP, Elixir with some customization. OS used - Ubuntu Goto definition Install ctags -> sudo apt-get install exuberant-ctags  Activate ctags from project root -> ctags -R  Open all source files from this project root in Vim To goto function/variable definition under cursor -> Ctrl + ]   To jump back ->   Ctrl + t   Goto local variable/global variable declaration If tag not found for some global variable/local variable/static/function For definition and search(keyword under cursor) in same file(highlighter works with some good vim plugins) -> gd  For global definitions -> gD  To jump back -> Ctrl + o  Goto header files To go-to file ->   gf   To jump back -> Ctrl + o  This article will get updated more. The main aim is to k...

ssh: Could not resolve hostname git: No address associated with hostname

I came across this error when I needed to clone a git repo. I tried few times but I couldn't get it working. There were few suggestions on the internet, but none resolved my issue. So, lets get to the point, this issue may occur due to following reasons: 1. If you are using proxy to access git and it is not properly configured/proxy is not allowing you access git due to permission issues. More here: git-clone-no-address-associated-with-name getting-git-to-work-with-a-proxy-server 2. This happens due to a silly mistake. [I do make silly mistakes sometimes] Are you actually using git clone for cloning? I used this - ssh git@github.com:neovim/neovim.git instead of git clone git@github.com:neovim/neovim.git ----- Hope this have resolved your issue :-) Happy Coding.

The First C Program - Hello World! : Behind the code

This code will print Hello World! as output. #include <stdio.h> int main() { printf("Hello World!\n"); return 0; } To understand more, I would recommend to go through following: 1. Preprocessor macros # directive is for C preprocessor. #include simply looks for file stdio.h and includes the complete file in the current program. stdio.h is a header file which contains the declaration of variables, macros and functions of C standard library. 2. main() function This is the function which acts as starting point for C program. Its return type is int, which is followed as per ISO C89/99 standard. The system considers a program to have run successfully if at the end, it returns 0. So, in my opinion, this might have been the reason to choose int as the return type of main. 3. Logic Further, more functions and logic can be included inside main() to complete a desired task. In the above program, we are only printing one line and thats "Hello World!". 4...

Installing Golang : The fast way

Steps only for Ubuntu. Other OS quick installation guide coming up soon! So, this article is useful when you are in hurry and obviously, want to trust me :) There are basically two ways to install golang - one is using the classical apt-get method and the other one is installing from source. he First method     $ sudo apt-get update     $ sudo apt-get install golang This will pretty much do the thing. Just two commands. You can verify the installation just by checking this:     $ go env GOROOT This command will output the directory name where go is installed. Usually, it will show /usr/lib/go. You can check go version:     $ go version     go version go1.5.1 linux/amd64 You are set to use golang. Please don't forget to configure $GOPATH and $GOBIN directories explained below.  Note: This method will install go version which is included in os package. If you need to install particular version o...

Expandable Arrays in C : behind the code

Image
Arrays. They are beautiful. In C, we always try to work through restrictions arrays have i.e the size of the array must be statically defined. We always want a dynamic array whose size can be decided at run-time. There are ways which we use widely for e.g by using pointers and then dynamically allocating memory to it using malloc or calloc. But depending on the situation, we might require more efficient and organizable ways. I will explain the concept with a series of examples as in how simple arrays evolved to the tricky expandable ones. The classic way is to use pointers This snippet will allocate a memory block of size = array_size(integer array). Though this is not what I wanted to explain because this way is too clumsy. Imagine if you need 10 dynamic arrays in your program, you have to write these four lines each time and you have to keep track of all the 10 sizes. A better way is to use structures: We can simply create a structure containing two elements: array_size and...

Stack Size : behind the code

How to know the stack size of a process in Linux? #Interview Question The stack word is very popular when it comes to C programming. It often intrigues us that how much is the stack size of a process and how to know it. The answer to this question can not be given without considering the "platform independent" thing. Well, we all are familiar with the word "platform independent". It is only word which comes to our mind when we don't know the answer. :P So, the stack size depends on the platform, the architecture - microprocessor is of how many bits - 16, 32, 64? But I will explain the answer with respect to Linux operating system. Method 1 The simplest method which I found is through cat /proc/-pid-/limits cat command is used to access a file. proc is a directory which contains information about all the running processes. -pid- is the process id of the process. We can know the process id of any process using ps -ef command. See man page of p...

error: invalid application of ‘sizeof’ to incomplete type ‘struct ’

list.c:47:39: error: invalid application of ‘sizeof’ to incomplete type ‘struct Litsnode’ So, I was trying to run a program based on linked list and this is what I got. This is a very silly problem. I am mentioning it here just to help those who got frustrated like me :-\ Let me show you the line where this error occurred : 46   struct Listnode * newnode; 47   newnode = (struct Listnode *) malloc(sizeof(struct Litsnode)); Now, View it properly. Check the name(spelling) of the structure mentioned to sizeof : " struct Li ts node ". Though the defined name of the structure was : " struct Listnode " That's it.  This happens all the time that we may type something wrong. The important thing is to identify it. :-) Feel free to give any suggestions :)