Saturday, 24 December 2011

Git Command Quick Reminder

NOTE: You can find an updated version of this article in Git Command Quick Reminder

$ aptitude install git-core # git basic tools.

NOTE: In Debian Unstable
$ aptitude install git

gitk graphic tool.
$ aptitude install gitk # this graphic tool allows us to browse a git repo.


$ git init # Creates an empty repository in current directory, or reinitializes an existing one.
$ git init directory_name # Creates an empty repo in directory_name directory.

$ git clone remote_url # clone a remote repo. Passing as argument a local directory this command clones a local repo.

$ git clone --depth 1 git:// kamailio # clones sip-router source code, creating a local directory named kamailio. "depth 1" option means it only takes one revision history. That reduces the amount of history to download, but it disallows cloning, fetching, pushing or pulling from this repo. Then, it is only suitable to generate patches.

$ git clone source_repo dest_repo # clones a local repository source_repo in another local repository dest_repo,
if both are directories.
$ git clone file:///path/to/source/repo file:///path/to/dest/repo # another way to specify local directories.
This way we are sure git does not use hard links when cloning source repo.
$ git clone --no-hardlinks source_local_repo dest_local_repo # clone a repository and copy object files instead of using hardlinks for local repo objects.


Thursday, 4 August 2011

My .emacs configuration file

This post describes my .emacs configuration file.

.emacs configuration file is loaded by emacs editor when it starts.

Let's divide the .emacs configuration file into parts to describe it better:

Customized variables
Install user customizations of variable values specified in arguments.

  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(column-number-mode t)
 '(desktop-save-mode t)
 '(display-battery-mode t)
 '(display-time-24hr-format t)
 '(display-time-day-and-date nil)
 '(display-time-mode t)
 '(fringe-mode 0 nil (fringe))
 '(menu-bar-mode nil)
 '(network-speed-format-string " [%NI %AX %AB] ")
;; '(network-speed-interface-list (list "eth0" "eth1"))
 '(network-speed-interface-list (list "eth1"))
 '(network-speed-precision 1)
 '(network-speed-update-interval 2)
;; '(org-agenda-files (quote ("~/org/")))
 '(scroll-bar-mode nil)
 '(size-indication-mode t)
 '(tool-bar-mode nil)
 '(tooltip-mode nil)
 '(w3m-session-load-last-sessions t))

Wednesday, 20 July 2011

Calculate Prime Numbers using an ARDUINO Board

Following example uses an Arduino board to calculate a prime number list, starting from one.
It shows the result using serial port communication.


You should copy this code into your Arduino IDE window, compile it (C-R), upload the code into the board (C-U) and to see the result open the serial monitor (C-Shift-M).

If everything goes fine your serial monitor will show a prime on each line every time it is calculated. Maximum prime able to be calculated depends on long type maximum value.

long number = 3;

void setup()

void loop()
  int is_prime = 1;
  long i = 3;
  long top = sqrt(number);
  while (i<top)
    if (number%i == 0)
      is_prime = 0;
  if (is_prime)
  number += 2;

Within setup function, it shows 1 and 2 primes. It then starts calculating in the main loop using number 3.

Primality test here consists on performing divisions and checking the remainder. It is not needed to test with every divisor, when square root is reached we know it is a prime.

When a prime number is found it is sent over serial line.

As we start calculations with number three, we can skip all even numbers.


Install and run a program in Arduino using 64 bits Ubuntu (lucid) distro

Wednesday, 6 July 2011

Install and run a program in Arduino using 64 bits Ubuntu (lucid) distro

From Arduino home page:
Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software.

Arduino provides a Java based IDE and examples are written in C language:

MY SYSTEM consists on:

Arduino Duemilanove: An ATmega328 running at 16 MHz with auto-reset. It connects to the computer using a USB cable.

Ubuntu distro:
Release: 10.04
Codename: lucid

Linux kernel
x86_64 AMD 64 bits architecture.


First we install needed dependencies:
  • openjdk-6-jre
  • avr-gcc (aka "gcc-avr")
  • version 4.3.2 or later 4.3.x version (4.4.x and 4.5.x seem to have various problems)
  • avr-libc

NOTE: On the contrary to what Arduino page said, I did not need avr-gcc-c++.

$ sudo aptitude install openjdk-6-jre gcc-avr avr-libc
NOTE: gcc-avr version is 4.3.4 in my system


Monday, 25 April 2011

Installing and Configuring ANYTHING.EL for Emacs

anything.el is an application framework written by TamasPatrovics (current maintainer is rubikitch).
It provides a better way to choose between alternatives when typing a command, switching buffers, searching for help, files, etc.
After you select a candidate option from the list anything provides, you can choose between several actions.

We are going to download anything from its source code repository.
$ cd ~/.emacs.d
$ git clone git://


;; Anything.el
(add-to-list 'load-path "~/.emacs.d/anything-config/")
(add-to-list 'load-path "~/.emacs.d/anything-config/extensions/")
(require 'anything-startup)

That it is enough for using anything:
e.g: M-x anything

Also common functions like switch-to-buffer are automatically remapped to anything ones.

However you could also customize your anything buffers, selecting the anything sources you want:

Saturday, 19 March 2011

Simple Python IRC Bot

This article shows the code of a simple python irc bot.

To run it, you should create a file, e.g:, copy following code in it, and exec:
$ python

other way to run it:
$ chmod a+x
$ ./


Thursday, 27 January 2011

Calculate prime numbers using PHP

Simply create a file named primeNumberCalculator.php. Copy following text in it.

You need a web server supporting php scripting.
Place the file where your http web server see it. e.g: /var/www

Open the file in a web browser. e.g: http://localhost/primeNumberCalculator.php


<h2>PHP Prime number calculator</h2>
<form name="input" action="primeNumberCalculator.php" method="get">
How many primes?: <input type="text" name="count" />
<input type="submit" value="Submit" />

// How many prime numbers are we going to calculate:
if ($count == "") {
   $count = 10;  // Default value

// We show the first prime number:
echo $prime_array[0];
echo " ";

$total=1; // prime number array length.
$number = 3; // current number we are going to test for primality.

$i=1; // We start with 1 because first prime is already printed.
while ( $i<$count ) {
   $max = floor(sqrt($number));
   $n = $prime_array[$index];
   while(($n <= $max) && ($is_prime == "true")) {
      if (($number % $n) == 0) {
      $n = $prime_array[$index];
   if ($is_prime=="true") {
      echo " " . $number;
      $prime_array[$total] = $number;

   $number += 2;



Wednesday, 12 January 2011

Calculate a PRIME NUMBER list using JAVA

This article shows how to write, compile, build and execute a program that calculates a list containing the first prime numbers using Java language.

We are going to create a source code file named
Then we copy/paste next programm in that file.

NOTE: Name is important, because in Java language file name has to match the class it contains.

import java.util.ArrayList;

 * Description of CalculatePrimeNumbers class.
public class CalculatePrimeNumbers {

    // By default it shows 50 first prime numbers.
    private static final int MAX_PRIMES = 50;

     * @param args the command line arguments
     * This function accepts zero or one arguments.
     * When called with no arguments it shows 50 first prime numbers.
     * If we specify a number, it shows that a prime number array with that specified length.
    public static void main(String[] args) {
        int top;

 // Parse command line arguments.
            case 0:
                top = MAX_PRIMES;
            case 1:
                top = Integer.parseInt(args[0]);
                System.err.println("ERROR: TOO MANY ARGUMENTS.");
        System.out.println("We are going to calculate " + top + " first prime numbers.");

 ArrayList<long> primes = new ArrayList<long>();
        primes.add(2L); // 2 is the first prime number we get.
 long index = 3; // Calculations start for number 3.

        System.out.println("Prime number list:");
        System.out.print(2 + " ");
        while (primes.size() < top) {
            boolean isPrime = true;

     for(long n:primes) {
                if ((index % n) == 0) {
                    isPrime = false;
            } // End for.

            if (isPrime) {
                // index stores a prime number.
                System.out.print(index + " ");

        } // End while.
    } // End main.

Java is a programming language that is compiled into bytecodes.