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

XWD: how to take SCREENSHOTS in X WINDOW SYSTEM


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

XWD TOOL


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


CAPTURE WHOLE SCREEN


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.


INSTALL MENCODER


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.


OBTAIN BINARY CODECS


Binary codecs come separately from mencoder. We can download them from MPlayer pages:
http://www.mplayerhq.hu/design7/dload.html
http://www.mplayerhq.hu/MPlayer/releases/codecs/

To see if a codec is supported:
http://www.mplayerhq.hu/DOCS/codecs-status.html


I have an amd64 architecture but I have to download ESSENTIAL CODECS for X86 anyway:
$ wget www.mplayerhq.hu/MPlayer/releases/codecs/essential-20071007.tar.bz2
$ tar xvjf essential-20071007.tar.bz2

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


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


CONFIGURING VP6 SETTINGS

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.


KAMAILIO CODING STYLE GUIDELINES


From Kamailio documentation: http://sip-router.org/wiki/coding_style

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 */
    }
    


EMACS C KAMAILIO CODING STYLE


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.



USING GOOGLE TRANSLATE TOOL

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:

http://www.google.com/translate_c?langpair=LANG1|LANG2&u=URL

where:
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 http://translate.google.com/?hl=en web page, and pasting there our URL web page.

NOTE: Google also offers to us this other tool: http://translate.google.com/translate_tools?hl=en but it introduces some problems maintaining the original formatting of the web page.



SELECTOR WITH LANGUAGE OPTIONS

Tuesday, 13 March 2012

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

WHAT IS THIS VMB / WADER THING?


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.


DOWNLOAD THE SOURCE CODE


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 https://github.com/andrewbird/wader
$ git clone https://github.com/andrewbird/vodafone-mobile-broadband


INSTALLING BUILDING DEPENDENCIES

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



INSTALLING AND SETTING UP LIRC

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

It provides the daemons and some utilities to support infra-red remote controls under Linux.
http://lirc.org

$ 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
196-

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.

http://linuxtv.org/wiki/index.php/Afatech_AF9015


LINUX KERNEL DRIVER

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.


DETECTING THE DEVICE

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.


SPLIT ONE FILE INTO TWO


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: