05. August 2015

Vi/Vim comands

First of all there are 2 modes. Insert and Command . By default one is in the command mode.

i : to move to insert mode
esc : to move out from insert mode

Following is a set of commands I use in a regular basis.

a : append : start after cursor
i : insert : start before cursor

w : move forward word by word
b : move backwars word by word

ctrl+F : scroll forward 1 screen
ctrl+B : scroll backward 1 screen
ctrl+D : scroll forward 1/2 screen
ctrl+U : scroll backward 1/2 screen

ctrl+E : scroll forward 1 line
ctrl+Y : scroll backward 1 line

ctrl+H : move to top line
ctrl+M : move to middle line
ctrl+L : move to last line

/ : search for pattern : forward from cursor
? : search for pattern : backwards from cursor

f,F : search inline forward,backward
t,T : move cursor to occurance of the character forwar,backward
; , , : repear last find command forward and backward

ctrl+G : print line info
G : move the cursor by line number

ctrl+L : Redraw the screen : Remember the screen in just a buffer of texts
Configuring vi :

set nu : show line numbers
set nowrapscan : search does not wrap TOP or BOTTOM

Happy editing.

18. May 2015

Git, Forking and Syncing

There are couple of things to understand before going to the commandline, just remember that we have assumed the name UPSTREAM as the repository, from where we have forked the project and master is our own remote repository where we save our changes. Well, another important thing is to configure the UPSTREAM or simply configure a repository from where we want to sync.

git remote -v
git remote add UPSTREAM https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

For syncing forked repository, the commands are as below.

git remote -v
git fetch UPSTREAM
git checkout master
git merge UPSTREAM/master
git push origin master

This is a direct tutorial from github.

Happy syncing.

18. January 2015

Making crossplatform CLI application with HAXE

When I first heard about CLI applications, I thought it might be shipping with the OS itself. Then I found that we can write our own CLI applications. At that point I assume that well, just a CLI application, means it runs everywhere. But actually CLI applications by default are not crossplatform! Yes, I realised it much later. In order to have a crossplatform CLI app, one needs all the required environment to compile to and compile for a particular OS.

HAXE comes in handy in this case. One can make a crossplatfom CLI app with just one code base. Ofcourse you need the required environment to compile to that particular environment. There is even a shorter way to this, compile for NEKO virtual machine. This NEKO VM ships with HAXE. Once you compile to NEKO, all you do is package all the NEKO dependencies and there you have a crossplatform CLI for every OS. Here we will compile to NEKO and run through NEKO, but just keep in mind that the same code can be compiled to CPP(C++) to produce true native CLI.
Lets begin with the compiler settings or the build file. The .hxml file has the following content.

# HAXE build
# Defining the application entry
-main MyCliApp
# NEKO : compilation
-neko bin/myCliApp.n
#
# CPP : compilation
#-cpp bin/cpp/

We are setting up for compiling to NEKO but then we have the options commented out for compiling to CPP. If we want to compile for the C++ target, then comment out the NEKO target and enable the CPP(C++) target. Well, this compilation will create a file named myCliApp.n inside the ‘bin’ folder. To run the file, we have to navigate to the ‘bin’ folder and run with NEKO as below.

neko ./myCliApp.n

Thats about compilation and running. Lets get back to coding. There is no surprise here as all we have to do is, get the right package and class from HAXE and use it. Here is the Git repo for this example. The application entry initialises ‘PrintInfo’ Class. That class prints the information that we want to show to the user and finally asks the name of the use. As user inputs the name, it greets the user and moves to our defined command prompt. We have setup some commands to display. Depending upon user input the necessary commands are executed. All these are happening in MyCli.hx Class. The code is commented for easy reference in this repo. Here is the direct link to the class.

Happy coding.