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.

DOWNLOAD ANYTHING
We are going to download anything from its source code repository.
$ cd ~/.emacs.d
$ git clone git://repo.or.cz/anything-config.git

CONFIGURE .emacs FILE

;; 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: pybot.py, copy following code in it, and exec:
$ python pybot.py

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

BOT SOURCE CODE

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

<html>
<body>

<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" />
</form>
<?php

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

// We show the first prime number:
$prime_array=array("2");
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 ) {
   $index=0;
   $is_prime="true";
   $max = floor(sqrt($number));
   $n = $prime_array[$index];
   while(($n <= $max) && ($is_prime == "true")) {
      if (($number % $n) == 0) {
         $is_prime="false";
      }
      $index++;
      $n = $prime_array[$index];
   }
   if ($is_prime=="true") {
      echo " " . $number;
      $prime_array[$total] = $number;
      $total++;
      $i++;
   }

   $number += 2;
}

?>

</body>
</html>

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 CalculatePrimeNumbers.java
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.
        switch(args.length){
            case 0:
                top = MAX_PRIMES;
                break;
            case 1:
                top = Integer.parseInt(args[0]);
                break;
            default:
                System.err.println("ERROR: TOO MANY ARGUMENTS.");
                return;
        }
        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;
                    break;
                }
            } // End for.

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

            index++;
        } // End while.
       
    } // End main.

}
Java is a programming language that is compiled into bytecodes.

Wednesday, 25 August 2010

Beginning with Qt: Introduction, Installing Qt Framework, Qt Hello world

INTRODUCTION TO Qt

Qt is a complete development environment widely used to create GUI applications.

This cross-platform tool is also able to create non gui apps.

Qt is used in the KDE desktop environment, and in other projects like virtualbox.


Qt development environment provides: (version numbers when this article was written)

  • Qt libraries (version 4.6.3)
  • Qt Creator IDE (version 2.0.0)
  • Qt development tools


Qt is available under LGPL and GPL free software licenses. Nokia also provides the Qt commercial license to develop proprietary software.


Qt DEVELOPMENT TOOLS

Qt environment provides us with some development tools. e.g:

qmake
qmake tool helps us creating and managing .pro project files, and from them it creates Makefile files needed to build our projects.
qmake Manual
qmake Tutorial

Qt assistant
Qt assistant tool shows all available Qt help. It is a help browsing system.
Qt Assistant Manual

Saturday, 26 June 2010

Creating a TRIVIAL DEBIAN REPOSITORY

This howto shows the way to create a trivial debian repository. Just a simple collection of deb package files.

There are two debian repository types: automatic and trivial.

Automatic repos are more complex. We are going to deal with trivial ones.

A trivial repository is composed of a root directory and one or more subdirectories.
No database server is needed.

This trivial repository is good enough to host a few packages, e.g creating a repo with your /var/cache/apt/archives deb packages and burn a cd or store them in a removible drive.

Trivial repos do not follow the standard debian repo directory structure, so we will have to specify the exact path in sources.list file.


CREATING MY TRIVIAL REPO STRUCTURE:

Our repo will consist of MyRepo root directory with binary subdirectory.

$mkdir -p /path/to/MyRepo
$cd /path/to/MyRepo
$mkdir binary

We place there the deb packages our repo will provide.
I.e: we copy packages from the apt cache:
$rsync -vP /var/cache/apt/archives/*.deb /path/to/MyRepo/binary
$cd .. # we move to repo root directory.


CREATE PACKAGES CONFIGURATION FILE

Sunday, 2 May 2010

How to BUILD the LINUX KERNEL for the ANDROID EMULATOR (Eclair version)

DOWNLOAD THE KERNEL SOURCE CODE


First we download the kernel source code from https://android.googlesource.com

Within that page there are kernels for other platforms too. We choose to download kernel/goldfish project from there.

$ git clone https://android.googlesource.com/kernel/goldfish

A goldfish directory appears:
$ cd goldfish
This directory does not contain any source code in it.

We check which branch we have downloaded:
$ git branch
it shows * master , not the one we are searching for:

To list all remote available branches:
$ git branch -r
or
$ git remote show origin
origin/HEAD -> origin/master
  origin/android-goldfish-2.6.29
  origin/android-goldfish-3.4
  origin/linux-goldfish-3.0-wip
  origin/master


What does goldfish mean? (from android-kernel mail list)
Goldfish is the kernel hacked branch that supports the qemu based arm emulator for android, so it is the one we need.

Download GOLDFISH kernel version
Choose the version that suits you.
$ git checkout --track -b android-goldfish-2.6.29 origin/android-goldfish-2.6.29
$ git branch
* android-goldfish-2.6.29
  master


RUNNING THE EMULATOR


Within this link we will find how to get the android emulator, and launch it.
Building Android in Debian Sid

Showing the kernel version running in the emulator
$ adb shell
# cat /proc/version
Linux version 2.6.29-00261-g0097074 (digit@digit.mtv.corp.google.com) (gcc version 4.4.0 (GCC) ) #14 Tue Feb 2 15:49:02 PST 2010


OBTAINING KERNEL CONFIGURATION


We are going to obtain the kernel configuration .config file from within our running emulator.

$ cd /path/to/goldfish # we enter in the kernel source directory.
$ adb pull /proc/config.gz . # get compressed .config file from the emulator.

$ gunzip config.gz # uncompress it.
$ cp config .config # rename it into .config

Now you can edit .config file the way it suits you the most.


BUILDING AND COMPILING THE KERNEL


CROSS_COMPILE environment variable stores the path to the arm cross compiling toolchain. I use the one which comes with android source code.

$ ARCH=arm CROSS_COMPILE=/path/to/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- make

Executing make will build the kernel.

Last lines will show:
Kernel: arch/arm/boot/Image is ready
Kernel: arch/arm/boot/zImage is ready


So we have obtained Image and zImage kernel binary files.


RUN THE EMULATOR USING THE NEW COMPILED KERNEL IMAGE


We need -kernel option:
$ emulator -kernel /path/to/goldfish/arch/arm/boot/zImage -show-kernel -verbose

We can check now the kernel version:
$ adb shell
# cat /proc/version
Linux version 2.6.29-00262-gb0d93fb (user@myPC) (gcc version 4.4.0 (GCC) ) #1 Sun May 2 14:27:31 CEST 2010


If we do not specify kernel option it usually uses the prebuilt one:
$ emulator -show-kernel -verbose
emulator: argv[01] = "-kernel"
emulator: argv[02] = "/path/to/mydroid/prebuilt/android-arm/kernel/kernel-qemu"


ACTIVATING MODULE LOADING SUPPORT IN THE KERNEL


Module loading support is previously disabled in the kernel, if we want to load modules in the kernel we have to enable it:

edit .config file and set:
CONFIG_MODULES=y

$ ARCH=arm CROSS_COMPILE=/path/to/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- make

I am asked about some options when executing make. I ask yes for module related options.

After compiling I see several modules have been built.

MODPOST 6 modules
CC      drivers/video/fb_sys_fops.mod.o
LD [M]  drivers/video/fb_sys_fops.ko
CC      drivers/video/syscopyarea.mod.o
LD [M]  drivers/video/syscopyarea.ko
CC      drivers/video/sysfillrect.mod.o
LD [M]  drivers/video/sysfillrect.ko
CC      drivers/video/sysimgblt.mod.o
LD [M]  drivers/video/sysimgblt.ko
CC      drivers/video/vfb.mod.o
LD [M]  drivers/video/vfb.ko


We can upload the modules in the emulator and install them:
$ adb push drivers/video/fb_sys_fops.ko /data
$ adb shell
# insmod /data/fb_sys_fops.ko


REFERENCE


http://www.cianer.com/androidg1/28-building-android-kernel-images


YOU MAY ALSO BE INTERESTED IN:


Building Android in Debian Sid

Sunday, 25 April 2010

Building Android in Debian Sid

We are going to build and test Android in Debian Sid on x86 32 bits architecture.

As a requirement we need JDK 5.0, update 12 or higher. Java 6 is not supported, because of incompatibilities with @Override.

Debian Sid provides all packages we need except this one. We could install from source but instead we are going to install JDK 5.0 from Debian Stable (Lenny) repositories:

ADD DEBIAN STABLE (LENNY) REPOSITORIES


#echo "deb http://ftp.debian.org/debian/ stable main contrib non-free" >> /etc/apt/sources.list

#aptitude update

sun-java5-jdk package will now become available.


INSTALL ALL PACKAGES WE NEED:


#aptitude install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev


SELECT THE RIGHT JAVA VERSION:


$file /etc/alternatives/java* # To know which alternative files we have to update.
#update-alternatives --config java
#update-alternatives --config java_vm
#update-alternatives --config javaws


We also install valgrind, a tool that will help you find memory leaks, stack corruption, array bounds overflows, etc.
#aptitude install valgrind

Sunday, 28 March 2010

Connect to Internet using a Sony Ericsson K530i phone in Debian GNU/Linux via Bluetooth

Within this post we are going to explain how to connect to internet using a Sony Ericsson K530i mobile phone via bluetooth, in a Debian Sid system.

CONFIGURING OUR K530i PHONE


First step consists on configuring bluetooth settings in our phone.

Activate bluetooth in the phone:
Settings -> Connectivity -> Bluetooth -> Turn on

Set a name for your phone:
Settings -> Connectivity -> Bluetooth -> Phone name
We select a name for our phone, e.g: my_K530i

Make your phone visible to other bluetooth devices:
Settings -> Connectivity -> Bluetooth -> Visibility -> Show phone


INSTALLING BLUETOOTH SOFTWARE

Sunday, 28 February 2010

How to Create a GENTOO Distro CHROOT ENVIRONMENT

This article describes how to build a chroot environment for Gentoo distribution.

NOTE: Debian GNU/Linux will be our host system, but these steps should also work for most other Linux based distributions (e.g: Ubuntu).


DOWNLOAD A SMALL MINIMUM GENTOO SYSTEM

First we are going to download a minimal Gentoo system, called STAGE3.

We choose our architecture, in my case x86, and i686 specifically.
http://mirrors.kernel.org/gentoo/releases/x86/autobuilds/current-stage3/
$ wget http://mirrors.kernel.org/gentoo/releases/x86/autobuilds/current-stage3/stage3-i686-*.tar.bz2

There is a list of mirrors here: http://www.gentoo.org/main/en/mirrors.xml

We could download directly from gentoo page too:
$ wget ftp://distfiles.gentoo.org/pub/gentoo/releases/x86/current-stage3/stage3-i686-*.tar.bz2



BUILDING OUR GENTOO DIRECTORY

We create a directory where we will place Gentoo files: