Customizing .vimrc

The vimrc file contains optional runtime configuration settings to initialize Vim when it starts. We can customize Vim by putting suitable commands in your vimrc. We can locate the file in the home directory.

There are some very complex configurations we can do in the vimrc file, but I am going to show just a few simple ones because I usually use IDEs (IntelliJ, Eclipse, Netbens, …) or text editors (Sublime, Notepad++, …) to write my code and I just use Vim when I am connected to a remote server through SSH or locally for a very simple changes in configuration files or similar.

An example of vimdc file:

"GENERAL USE
"Avoid console bell when errors 
set noerrorbells
"Language for messages
set helplang=en
"VISUALIZATION
"Line numbers
set number
"Syntax with colors
syntax on
"Parenthesis, brackets and curly brackets matching
set showmatch
"INDENTATION
"Tab size
set tabstop=2
"Use precedent indentation
set autoindent
"SEARCH
"Incremental search
set incsearch
"Ignore case except uppercase string
set ignorecase smartcase
"Mark search results
set hlsearch
"Background color
"set background=dark
Advertisements
Customizing .vimrc

Install Cloud Foundry CLI in macOS

The easiest way to install Cloud Foundry in a macOS system is to use the homebrew package manager.

To install homebrew, we just need to execute the next line in our Terminal:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Once installed, you can “tap” the Cloud Foundry repository:

brew tap cloudfoundry/tap

Finally, you install the Cloud Foundry CLI with:

brew install cloudfoundry/tap/cf-cli

Once you have installed the CLI tool, you should be able to verify that it works, by opening a Terminal and running:

cf --version

This should show something like:

cf version 6.30.0+decf883fc.2017-09-01

If you see a result like this, the CLI is installed correctly and you can start playing.

Now, we need a trial account in a Cloud Foundry provider. There are multiple option we can check in the Cloud Foundry Certified Providers page. Once we have created the account we can proceed to login with out CLI.

cf login
API endpoint> https://api.eu-gb.bluemix.net

Email>john.doe@example.org
Password>
Authenticating...
OK

Targeted org example

Targeted space dev

API endpoint: https://api.eu-gb.bluemix.net (API version: 2.75.0)
User:         john.doe@example.org
Org:          example
Space:        dev

In the above output, the email is the address you used to sign up for a service.

Once you have successfully logged in, you are authenticated with the system and the Cloud Foundry provider you use knows what information you can access and what your account can do.

The CLI tool stores some of this information, the Cloud Foundry Endpoint API, and a “token” given when you authenticated. When you logged in, instead of saving your password, Cloud Foundry generated a temporary token that the CLI can store. The CLI then can use this token instead of asking for your email and password again for every command.

The token will expire, usually in 24 hours, and the CLI will need you to login again. When you do, it will remember the last API Endpoint you used, so you now only have to provide your email and password to re-authenticate for another 24 hours.

First commands

  • cf help: Shows CLI help.
  • cf help <command>: Shows CLI help for an specific command.
  • cf <command> –help: Shows CLI help for an specific command.
  • cf help -a: Lists all the commands available in the CLI.
Install Cloud Foundry CLI in macOS

Git Bash: Shell prompt customization

What is it?

Git Bash for Windows is not just bash compiled for Windows. It is a package that contains bash, which is a command-line shell, and a collection of other, separate *nix utilities which you can run using the shell, compiled for Windows, and a new command-line interface terminal window called mintty.

You can download it from here.

Shell prompt customization

If we want to customize the shell prompt according to our preferences, we just need to edit the file “git-prompt.sh”. In a Windows x64 system, we can find it in:

C:\Program Files\Git\etc\profile.d\git-prompt.sh

Now we just need to play a little bit with the different options available.

As an example, the version I am using right now looks like that:

TITLEPREFIX='Bash Prompt (Git for Windows) =>'

PS1='\[\033]0;$TITLEPREFIX:${PWD//[^[:ascii:]]/?}\007\]' # set window title
PS1="$PS1"'\[\033[32m\]'       # change to green
PS1="$PS1"'\w'                 # current working directory
if test -z "$WINELOADERNOEXEC"
then
    GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)"
    COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"
    COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}"
    COMPLETION_PATH="$COMPLETION_PATH/share/git/completion"
    if test -f "$COMPLETION_PATH/git-prompt.sh"
    then
        . "$COMPLETION_PATH/git-completion.bash"
        . "$COMPLETION_PATH/git-prompt.sh"
        PS1="$PS1"'\[\033[36m\]'  # change color to cyan
        PS1="$PS1"'`__git_ps1`'   # bash function
    fi
fi
PS1="$PS1"'\[\033[0m\]'        # change color
PS1="$PS1"'$ '                 # prompt: always $
MSYS2_PS1="$PS1"               # for detection by MSYS2 SDK's bash.basrc
Git Bash: Shell prompt customization

Error Prone

We, as a developers, sometimes, make mistakes or add bugs to our code without realizing. For this reason static analyzers are a handy tool to apply during our builds or during our code verification processes.

One of these tools is Error Prone.

Error Prone is Google’s Java bug detection and static analysis tool. It is integrated into the Java compiler and catches bugs at compile time. It supports plugin checks for project-specific enforcement.

Basically, it is a tool created by Google for code analysis and error detection for the Java language. It is integrated inside the compiler and tries to detect bugs in compilation time.

But, let’s see and example. Imagine we have a program with the next line of code:

String.format("Param A: {}, param B: {}, param C: {}", paramA, paramB, paramC);

Obviously, it is not correct and the error comes from, maybe, a transformation between a previous log message to a different kind of message. The compiler is not going to complain because it is a string message and it is not a syntax error. But, the truth is there is an error.

When we try to compile the program with Error Prone, we are going to receive a compilation error message like this:

error: [FormatString] extra format arguments: used 0, provided 3
String.format("Param A: {}, param B: {}, param C: {}", paramA, paramB, paramC);
             ^
(see http://errorprone.info/bugpattern/FormatString)

We can see clearly and without any doubts there is an error. Even, a link to the error description is provided.

The proper code should be:

String.format("Param A: %s, param B: %s, param C: %s", paramA, paramB, paramC);

The easiest way to start using the tool, it is to add the maven plugin to our pom.xml file:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
        <compilerId>javac-with-errorprone</compilerId>
        <forceJavacCompilerUse>true</forceJavacCompilerUse>
        <source>8</source>
        <target>8</target>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-compiler-javac-errorprone</artifactId>
            <version>2.8.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.errorprone</groupId>
            <artifactId>error_prone_core</artifactId>
            <version>2.0.19</version>
        </dependency>
    </dependencies>
</plugin>

For more options, just go to the installation instructions page.

The project is open source and you can see all the code in the official repository: error-prone.

I am not saying that it is going to solve all your problems but, at least, it is another tool to increase our code quality and avoid silly mistakes.

Error Prone

Publishing to GitHub

GitHub is a web-based Git or version control repository and Internet hosting service. As a developers, I am quite sure that all of you know the platform.

Every-time we start a new project, even if it is just something for us, it is a good idea to use a version control system. Here is where Git and GitHub can help us.

There are two easy ways to create and upload our project to a repository.

The first way, it is to create the repository in GitHub, and after that clone in our machine the created repository and start writing our code. This is the simplest way. Doing it in this way, our local repository is already connected to the remote repository and we just need to start committing things. The clone command, assuming the account name is “fjavierm” and the repository name is “myproject”,  is:

git clone https://github.com/fjavierm/myproject.git

Te second way, it is when we already have a project in our local machine and we want to add the project to a repository. In this case, we need to perform a few more steps.

1. We need to create the repository under our GitHub account. In this case, my account is “fjavierm” and my repository is going to be “myproject”.

2. In our local machine, in our local project folder, we need to initiate the git repository. This will add a folder “.git”:

git init

3. We can check the status of the available files:

git status

This instruction will show us the files that we can add to the repository to commit. In this step, it deserves to pay special attention to the files that we do not want to add and, maybe, it is a good idea to create the files “.gitignore” and “README.md”

4. Add the files to the repository:

git add .

5. Commit the added files adding a descriptive message. Usually, issue number and description, or something meaningful.:

git commit -m "Starting the project."

6. Connect our local repository with our remote repository:

git remote add origin https://github.com/fjavierm/myproject.git

7. Check we have perform the previous step properly:

git remote -v

8. Push our changes to the remote repository:

git push -u origin master

With these few instructions we should have available all our code in the GitHub repository.

Publishing to GitHub