Git

Nice display of the current tree

git log --graph --all --format=format:"%x09%C(yellow)%h%C(reset) %C(green)%ai%x08%x08%x08%x08%x08%x08%C(reset) %C(bold
white)%cn%C(reset)%C(green)%d%C(reset)%n%x09%C(white)%s%C(reset)" --abbrev-commit "[email protected]"

An alternative:

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

You can also make an alias. Copy and paste the line below on your terminal:

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

And every time you need to see your log, just type in

git lg

Or, if you want to see the lines that changed

git lg -p

Source: https://coderwall.com/p/euwpig

NB: If you want to see a list of aliases set up on your linux box, just type alias at the prompt.

Simply add color to your git environment:

git config --global color.ui auto

Source: http://git-scm.com/book/en/Customizing-Git-Git-Configuration

Tutorial

Learn git from your browser: https://try.github.io/levels/1/challenges/1

Delete current tag

git tag -d 12.15
git push origin :refs/tags/12.15

Stash current work

git stash save
git stash pop

Push

To avoid doing all the time:

git push origin <your-feature-branch>

You can do:

git push origin <your-feature-branch> -u

You next, you will just have to do:

git push

Find which commit is breaking the test with 'git bisect'

You may be in situation where you come back from holidays and find the tests that were passing before broken.

Git can help to find which commit produced the failure.

To start bisect, run:

git bisect start

You know that the tests are failing so you indicate it with:

git bisect bad

You checkout an earlier revision when you know that the tests were passing (git log can help):

git checkout <the_failing_revision>

Then run the tests, and if they are passing, indicate it:

git bisect good

Once you have indicated that once it was bad and once it was good. You can leave git bisect do the job automatically:

git bisect run <command_that_run_the_tests>

You can now grab a coffee and come back few minutes later to see what commit made the tests failed.

Finally, you also need to come back to the original revision:

git bisect reset

Sources:

What is the original commit of a git repository?

You know git log to see the history of he commits.

Once you get the results of git log, you can do 'G' (capital G) to inverse the order of commits and see the first one in time.

Revert all the changes you did

git checkout -f

The watch command

watch -n1 ' ps aux | grep what_you_want'

Something interesting when combined with svc:

cd /etc/service # or wherever svc (supervise) is installed
watch svstat *

It will monitor every 2 seconds the state of your service.

Monitor the queries being run in real time:

watch -n 1 'sudo -u postgres psql --tuples-only --command "SELECT datname, procpid, date_trunc(\$\$second\$\$, age(current_timestamp, xact_start)), current_query FROM pg_stat_activity;"'

Source: http://kevin.deldycke.com/2011/10/postgresql-commands/

VIM

VIM basics

The built in tutorial of Vim is very useful to know the basics. To launch it simply type the following in your terminal:

$vimtutor

It will launch some lessons with an approach 'learning by doing'.

Configuration

The ~/.vimrc file provides Vim's default configuration

vim memento

Simple vimrc

set textwidth=79  " lines longer than 79 columns will be broken
set shiftwidth=4  " operation >> indents 4 columns; << unindents 4 columns
set tabstop=4     " a hard TAB displays as 4 columns
set expandtab     " insert spaces when hitting TABs
set softtabstop=4 " insert/delete 4 spaces when hitting a TAB/BACKSPACE
set shiftround    " round indent to multiple of 'shiftwidth'
set autoindent    " align the new line indent with the previous line

Jump to function definition:

g + *

Highlight variable under cursor:

:autocmd CursorMoved * exe printf('match IncSearch /\V\<%s\>/', escape(expand('<cword>'), '/\'))

Move cursor to its last position:

The quickest way is to hit either:

''

(two apostrophes) or:

``

(two backticks). Note that the difference is that the backtick goes to the same location on the line, whereas the apostrophe goes to the start of the line. On a UK keyboard, the apostrophe is more accessible, so I tend to use that one. There are loads of useful marks like this, see :help mark-motions. For some other motions (not 2j I think), there's also the jump-list that lets you navigate back and forth among a number of motions. Ctrl-O and Ctrl-I do this navigation, but see :help jump-motions for more information.

Line numbers

To display line numbers along the left side of a window, type any one of the following command while using text editor:

:set number

Go to line

:42

where 42 is the number of line you want to go

Split the screen

:vsp

Paste from another application into vim

To avoid indentation issue:

:set paste

Symbolic links

Blog creation

Website hosted from my Github Repository

It is using Github Pages. Create a repository called username.github.io, where username is your username (or organization name) on GitHub and put your website files in there.

Website generation using a Python framework: Nikola

This website is using Nikola which is a Python static website generator. Assuming that you have created a github repository called username.github.io, clone it with:

git clone [email protected]:username/username.github.io.git

Then initialize your website with this command:

nikola init username.github.io

where username.github.io is the repository you have just cloned.

cd in this directory and execute this command:

nikola build && nikola serve -b

The website will open at the url http://127.0.0.1:8000.

To deploy to Github, change the file conf.py such as:

GITHUB_DEPLOY_BRANCH = 'master'

Once you are happy with it, you can deploy to Github with the command:

nikola github_deploy

Posts written using reStructuredText

Useful cheatsheet for the basics: http://github.com/ralsina/rst-cheatsheet/raw/master/rst-cheatsheet.pdf

This is also a way to learn how to use Vim. Since Nikola 7.0.1, you can use the -e option when creating a new post. But before, you need to set up a default editor. If you want to use vim, you can first locate it:

which vim

Then you can use it in the export variable:

export EDITOR=/usr/bin/vim

Download a pre-built template from bootswatch

nikola bootswatch_theme -n custom_theme -s spruce -p bootstrap3

Installing Nikola

pip install nikola

If you have the following error while installing nikola:

** make sure the development packages of libxml2 and libxslt are installed **

You can fix it with:

sudo apt-get install libxslt1-dev libxslt1.1 libxml2-dev libxml2 libssl-dev

Upgrading Nikola

Since Nikola can be installed with Pip, you can use the following command:

pip install -U nikola

To install pip, see http://pip.readthedocs.org/en/latest/installing.html

If you have the following error:

Python.h: No such file or directory

You can fix it with:

sudo apt-get install python-dev

To upgrade pip:

sudo easy_install -U pip

To downgrade pip to a previous version:

sudo easy_install pip==1.2.1

Add your own domain

Log in to your domain provider website and change the forwarding value to the website url provided by Github-pages e.g. username.github.io