vendredi 1 août 2014

Vim persistent undo

Starting from Vim 7.3, it's possible to keep your "undo history". Even after closing and reopening the file, you can still use u and ctrl+r in order to go back to changes you made before closing the file.
In order to enable this feature, all you need to do is to set the properties undofile and undodir in your .vimrc file
set undofile
set undodir=$HOME/.undodir

Don't forget to create the directory undodir, or else this won't work
You can find more information about this feature here: Vim documentation: undo

lundi 21 janvier 2013

The expr command

The expr command is used to evaluate an expression and output the corresponding value. It could be used for example to use the terminal as a calculator:

    $ expr 80 - 25
    $ expr 80 / 25
Note that there is a space between the different arguments, otherwise the expression might not be evaluated properly.
It can be used as well for string operations and boolean operations

    $ expr length "abc"
    $ expr 1 "&" 0

vendredi 18 janvier 2013

Working with multiple files in vim

There is a couple of useful commands that can be used to work with multiple files as tabs. I've mentioned them in a stackoverflow answer:

  • Open a file in another tab

    :tabe filepath
  • save the current session in order to be able to open the same set of files again

    :mksession session_name.vim
  •  navigate between different tabs

    gt: next tab
    gT: previous tab
  • close all tabs at once

  • open a saved session

    vim -S session_name.vim

mercredi 23 mai 2012

cryptic perl

"Perl is the only language that looks the same before and after RSA encryption."
Keith Bostic. Programmer, created Sleepycat, contributed to free BSD unices.

Funny C quote

"One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs."
Robert Firth. Author of programming books.

lundi 21 mai 2012

one of a million reasons to love programming

From the introduction to the excellent free book Programming ground up,

I love programming. I enjoy the challenge to not only make a working program, but to do so with style. Programming is like poetry. It conveys a message, not only to the computer, but to those who modify and use your program. With a program, you build your own world with your own rules. You create your world according to your conception of both the problem and the solution. Masterful programmers create worlds with programs that are clear and succinct, much like a poem or essay.

vendredi 6 avril 2012

Swapping numbers in java, pass-by-value VS pass-by-reference

I never thought about it, but I just discovered it is not possible to write a method to swap numbers in Java since Java is strictly pass-by-value, not pass by reference.
public void swapNumbers(int x, int y)
    int temp = x;
     x = y;
     y = temp;
If we call this function to try to swap numbers, the numbers won't be changed.
There is an example of swapping numbers in this link:, but it's confusing for beginners.

public class Swapping{
  static void swap(int i,int j){
  int temp=i;
  System.out.println("After swapping i = " + i + " j = " + j);
  public static void main(String[] args){
  int i=1;
  int j=2;
  System.out.prinln("Before swapping i="+i+" j="+j);

This example doesn't mention that after we call the method swap, the numbers will return to their original values after this call.
The same operation is really simple in C++ which allows us to pass values by reference

void swapNumbers(double& a, double& b)
    double temp = a;
    a = b;
    b = temp;
Now, when we call this function, a and b will be swapped.*

double number1(5.5), number2(7.0)
swapNumbers(number1, number2);
cout << "First number : << number1 << endl;
cout << " Second number :" << number2 << endl;

The output will be
First number : 7.0
Second number 5.5;

A reference is merely an alias, another name for the same variable. Hence, making operations on a variable will also change the variable value.