Saturday, 10 November 2012

How to SPLIT BOOT.IMG file into kernel and ramdisk.gz (Android)

This article shows how to split a boot.img file into kernel and ramdisk parts.

In Android systems kernel and initial ramdisk filesystem are usually joined into an only file, named boot.img, and flashed into the device.

Recover image files have same structure too.

mkbootimg is the tool which builds a boot.img file from its kernel and ramdisk parts.

Boot.img file could also contain a second filesystem within it.

Split boot.img file using a python script

Copy code at the end of this article in a file named

Then execute (you need to already have a boot.img file):
$ python -i boot.img -o parts # This splits boot.img, create parts directory and stores there zImage (kernel) and ramdisk.gz.

Saturday, 13 October 2012

How to build Android CyanogenMod 7.2.0 for Samsung GT-S5570 tass phone from source code in Debian

This article shows how to build CyanogenMod 7.2.0 (Android fork) from source in Debian Sid (October 2012) for a Samsung GT-S5570 (tass) mobile phone.

7.2.0 is the stable CyanogenMod version for tass device.

First we create a directory to place everything there:
$ mkdir ~/mydroid
$ cd ~/mydroid

Download Android SDK

The Android SDK will provide us developer tools and libraries necessary to build our Android based system.

We choose linux platform and download a tar gz file.

Then to install the Android SDK we uncompress it and export the paths of tools and platforms directories.
$ tar xvzf android-sdk_r20.0.3-linux.tgz
$ export PATH=~/mydroid//android-sdk-linux/tools:~/mydroid/android-sdk-linux/platforms:$PATH


We have downloaded basic SDK. But it lacks some required tools like adb, etc.

To upgrade Android SDK in console:
$ android update sdk --no-ui

or using a graphical interface
$ android update sdk

It fetches some xml files and starts downloading Android SDK Platform-tools and some documentation.

We export the path to recently added SDK platform-tools:
$ export PATH="~/mydroid/android-sdk-linux/platform-tools:$PATH

Now adb tool is in our PATH.

Install required Debian packages

Sunday, 23 September 2012

ED line editor - tutorial

Ed is a line-oriented text editor.

It can be used interactively or in shell scripts.

Ed is the original text editor for Unix. It was written by Ken Thompson in 1971.

Ed is a small editor with few dependencies that can help you edit some files in situations where no other editor is usable.


$ sudo aptitude install ed
$ which ed
$ ed # run ed program.


$ ed file_name # opens file_name for editing. Changes are not stored until w command is introduced.


Ed works by accepting commands to edit parts of the file.

Commands usually have this structure:


Commands are one letter long.

Address means to which lines command is applied to.

Parameters are passed to command.


Monday, 17 September 2012

LUA PRIME CALCULATOR using preprocessing based on Sieve of Eratosthenes

This article shows a lua script to calculate an ordered prime list starting with 2, 3, 5, 7, etc.

We are going to improve former lua prime calculator using a preprocessing table.
This table will allow us to discard quickly some numbers and its multiples.

Within this lua script, first we perform some preprocessing, and after that actual prime testing for remaining numbers are performed.

Sieve of Eratosthenes

Sieve of Eratosthenes is an algorithm to calculate a prime number list up to a chosen number.

In this program we will use this algorithm to generate a preprocessing table.

Some examples are useful to show how preprocessing table works:

Tables are generated using a sequence with first prime numbers.


Preprocessing table for 2


So we will test numbers this way:
We start with number one, and sum to it the first number from preprocessing table:
1+2 = 3 (3 is the next number to test for primality)

Once preprocessing table has completed, we start from first element again (2):
3+2 = 5

5+2 = 7

Monday, 10 September 2012

How to set Bitlbee (GTalk and Twitter) in Debian

BitlBee is an IRC gateway to other instant messaging networks which use different protocols (e.g: jabber, ICQ, AIM, MSN, etc)

From user point of view BitlBee acts as an IRC server which forwards your messages to other networks like Google Talk, Facebook, Twitter, Identica,

BitlBee official web page:


When writting this article current BitlBee version in Debian unstable was 3.0.5
This version allows us to authenticate using OAth.

$ aptitude show bitlbee
Package: bitlbee                         
Version: 3.0.5-1.1
Description: An IRC to other chat networks gateway (default version)

Install BitlBee IRC gateway:
$ sudo aptitude install bitlbee

If after configuring it we need to restart Bitlbee daemon
$ sudo service bitlbee restart


Sunday, 19 August 2012

SSH client and daemon: Introduction

SSH client application allows you to logging in a remote computer, or execute commands remotely.

It is also able to execute graphical applications, and to forward TCP ports from and to local and remote machines.

SSH establishes a securely encrypted communication between local and remote hosts along an insecure network.

For SSH client to work it needs to connect to a SSH server in the remote computer.


SSH program binaries are:

ssh — OpenSSH SSH client (remote login program)
sshd — OpenSSH SSH daemon

In Debian or Ubuntu:

$ sudo aptitude install openssh-client # installs ssh client

$ sudo aptitude install openssh-server # installs sshd daemon


Sunday, 12 August 2012

Calculate a PRIME number LIST using C language

This C program calculates a list with first prime numbers.

Build the program

C is a compiled language, so we will need to install a C compiler: gcc
$ sudo aptitude install gcc

We copy this text in a file, e.g: prime_calculator.c

Next we compile the file:
$ gcc -o prime_calculator -lm prime_calculator.c -Wall

or if we want further optimization:
$ gcc -o prime_calculator -lm prime_calculator.c -Wall -O3

-lm option links the math library so we can calculate square roots.

Execute the program

After compilation, an executable appears: prime_calculator.
$ chmod a+x prime_calculator # we grant it execution permission.

If we want to show first ten prime numbers:
$ ./prime_calculator 10
2 3 5 7 11 13 17 19 23 29

If we pass more than two arguments, it calculates the prime list but does not show anything. Just to measure its execution time:
$ time ./prime_calculator 10 *
real 0m0.008s
user 0m0.004s
sys 0m0.000s

Sunday, 29 July 2012

Lua: Calculate a prime number list

Lua is an extension language.

This script calculates a prime number list starting with smaller ones.

To run this script you need to install lua language: (e.g: in Debian or Ubuntu)
$ sudo aptitude install lua

Current version(when this article was written) is 5.1:
$ sudo aptitude install lua5.1

After installing it, lua interpreter could be found in /usr/bin/lua.

Then you copy this script in a file, e.g: primes.lua and exec:

$ lua primes.lua 20 # it will calculate first twenty prime numbers.

or give execution permissions to the file:
$ chmod a+x primes.lua
$ ./primes.lua 20

Sunday, 20 May 2012


A screenshot is an image taken from the monitor screen.
It could comprise whole screen or a smaller part of it, usually a window.


X Window System provides an utility to dump images from a X Window: xwd.

xwd stores window images in a special format "xwdump".
This format can be used by other X tools too.

Other tools are also available:
convert from ImageMagick, KSnapshot, gnome-screenshot, ...

We install xwd (in debian, ubuntu):
$ sudo aptitude install x11-apps


We could capture entire screen or some window only.
Whole screen in X Window System is associated also to a window: the root window.

Getting root window screenshots:

Sunday, 6 May 2012

Convert videos to VP6 codec format using MENCODER

This post shows how to encode a video file into VP6 codec, using mencoder program.

As a result we will create a FLV (Macromedia flash player) media file (instead of an avi file)

We will get "On2 VP6" video codec driver from a windows dll.

Mencoder is a tool provided by MPlayer to encode movies, and convert between file formats and codecs.


First we obtain mencoder tool.

In debian:
$ sudo aptitude install mencoder

Current mencoder version when this article was written:
Version: 2:1.0~rc4.dfsg1+svn34540-1+b1

Another way to get mencoder could be installing from source code.


Binary codecs come separately from mencoder. We can download them from MPlayer pages:

To see if a codec is supported:

I have an amd64 architecture but I have to download ESSENTIAL CODECS for X86 anyway:
$ wget
$ tar xvjf essential-20071007.tar.bz2

The windows dll we need is this (check it does appear):

Next we place binary codecs in a directory where mplayer or mencoder can access them:
$ sudo mkdir /usr/lib/codecs
$ sudo cp -v essential-20071007/* /usr/lib/codecs/
NOTE: if you installed mplayer from source location could be: /usr/local/lib/codecs


Saturday, 21 April 2012

Rpm Package Management Quick Reference

An updated version of this article at: RPM Package Management Quick Reference

RPM tool

rpm tool deals with rpm packages directly, but cannot deal with packages placed in a repository. Zypper, Yum,... tools deal with repositories.

$rpm -q package_name #e.g rpm -q subversion Query if a package is installed.

$rpm -qf "*/bash" #find which package owns that file.

#rpm -e package_name #deletes a package.

$rpm -qi package_name # shows info about a package.

$rpm -ql package_name # list files contained in package_name

#rpm -i package.rpm # installs a rpm file package.

#rpm -i --force package.rpm # forces package.rpm installation.

#rpm -qpl foo.rpm # shows the files in foo.rpm file package.

$rpm -q --scripts foo # shows installation and uninstallation scripts for foo package.

$rpm -qR foo # shows which dependencies foo package requires.

ZYPPER (OpenSuse 10.3 and up)

#zypper install foo # installs foo package from repository.

#zypper remove foo # removes a package. e.g: zypper remove python-twisted-conch

$zypper info python-twisted-conch # shows package info

$zypper search python # searchs for packages matching python.

#zipper ref && zipper dup # refresh repositories and then update the system.

YUM (Fedora, etc)

How to set EMACS C STYLE to hack KAMAILIO code

Kamailio (former OpenSER) is a SIP proxy server, call router, and user agent registration server used in Voice over Internet Protocol and instant messaging applications. Kamailio is free software (GPL licensed).

In this post we are going to learn how to configure emacs to follow kamailio coding style guidelines.


From Kamailio documentation:

As a resume:
  • Use tabs for indentation instead of spaces.
  • Set tab stops to 4 spaces.
  • Wrap lines that are longer than 78 characters (80 characters - two characters for window decorations).
  • Avoid C++ style comments (//)
  • Do not declare variables inside blocks.
  • Use the following style for function declarations
  • int func(int x)
        /* body */


We are going to create an emacs C coding style in order to comply with most of those rules.

Saturday, 14 April 2012

How to translate your web page using Google Translate tool

Google provides several useful tools to translate your web page. Then you can offer your page contents in more than sixty languages!

Our goal is to provide a drop down list where user will select target language and then the page will "automagically" translate into the desired language.

Translated page will appear in the same top window frame so not to distort your web page design layout.

Drop down list will show or hide depending on user browser default language.


Procedure to translate a web page is simple:

We will request a web page to Google Translate server, and it will return our web page already translated!

Request will have following structure:|LANG2&u=URL

LANG1 is set to original language
LANG2 is set to target language
URL is the url we want to translate.

This is the same way as going to web page, and pasting there our URL web page.

NOTE: Google also offers to us this other tool: but it introduces some problems maintaining the original formatting of the web page.


Tuesday, 13 March 2012

How to build and install Vodafone Mobile Broadband / Wader in Ubuntu Lucid 10.4 LTS


Vodafone Mobile Broadband (VMB) is a 3G manager GUI software sponsored by Vodafone company.

Wader is a 3G manager daemon which deals directly with your mobile device.

VMB communicates with Wader via dbus.

Currently VMB/Wader supports "wvdial" and "Network Manager" backends.

Both VMB and Wader are written in python.

We are going to build and install them in a Ubuntu Lucid (10.4 LTS) system.


VMB and Wader are not part of Ubuntu Lucid official repository, so we are going to build them from their sources.

First we need to install git to clone VMB and Wader repositories:

$ sudo aptitude install git-core
$ git clone
$ git clone


Sunday, 26 February 2012

Setting up IR remote for AVerTV Digi Volar X in Debian

AVerMedia AVerTV DVB-T Volar X (A815) is an Avermedia usb device able to capture DVB-T signals.

It provides an IR remote device, which we are going to set up in this post.

To properly configure the whole device see previous post


LIRC stands for 'Linux Infra-red Remote Control'.

It provides the daemons and some utilities to support infra-red remote controls under Linux.

$ sudo aptitude install lirc

We investigate about IR devices present in our system:
$ cat /proc/bus/input/devices | grep -n10 a815
187-I: Bus=0003 Vendor=0000 Product=0000 Version=0004
188-N: Name="ACPI Virtual Keyboard Device"
189-P: Phys=
190-S: Sysfs=/devices/virtual/input/input19
191-U: Uniq=
192-H: Handlers=sysrq kbd event19 rfkill
193-B: PROP=0
194-B: EV=3
195-B: KEY=ffffffffffffffff ffffffffffffffff ffffffffffffffff fffffffffffffffe

Installing and setting AVerTV Digi Volar X in Debian

AVerMedia AVerTV DVB-T Volar X (A815) is an Avermedia usb device capable to capture and show DVB-T TV signals.
This device is able to also show HDTV DVB-T signals.


The device contains an Afatech AF9015 Chip.
Supported in kernel since version 2.6.28.

NOTE: If you have an older kernel version you will have to compile the kernel module:
Compile AF9015 module tutorial.
AF9015 Kernel Module Source.

IMPORTANT: Although AF9015 module is already available in the kernel, it NEEDS ADDITIONAL FIRMWARE INSTALLED to work.


I plug the usb device:

$ lsusb
... ID 07ca:a815 AVerMedia Technologies, Inc. AVerTV DVB-T Volar X (A815)

Thursday, 5 January 2012

Split a Media Video File (AVI, FLV,...) using Mencoder and Mplayer

Mencoder is a movie encoder program that allows us to split a media video(e.g AVI) file into several AVI files.

We are going to split a media video file maintaining same video and audio codecs.

As mencoder accepts other file formats than avi files, we will be able to split them too, but result will be avi files.


E.g: We are going to split foo.avi file into foo1.avi(600 seconds long) and remaining length in foo2.avi.

Following mencoder man page advice, we could try these options:
$ mencoder foo.avi -o foo1.avi -oac copy -ovc copy -endpos 600
$ mencoder foo.avi -o foo3.avi -oac copy -ovc copy -ss 600

mencoder options:

Wednesday, 4 January 2012

Swapping on a File in Linux

This article shows how to create a standard file and configure your linux based system to activate swapping or paging on it.


First we create the swap file using dd command. cp is not useful here because swap file has not to contain holes.
# dd if=/dev/zero of=/mnt/swapfile bs=1M count=200 # We create a swap file of 200MByte in size.

For safety we disallow other users to read and modify the file:
# chown root.root /mnt/swapfile
# chmod 600 /mnt/swapfile

Swap size is unlimited for linux kernels after 2.3.3
Kernels after 2.4.10 support up to 32 swap areas.