Friday, February 26, 2010

Change font and font size in Fluxbox

In Fluxbox 1.1 a font and a font size can be changed by editing a overlay file, usually located in ~/.fluxbox/. So just add the following lines to this file and restart fluxboxmenu.title.font: sans-12:bold
menu.frame.font: sans-12:bold
toolbar.clock.font: sans-10:bold
toolbar.workspace.font: sans-12:bold
*font: sans-12
Of course you have to select the font you like or the size.

Thursday, February 25, 2010

bash: split string to array

There are few possible ways of splitting a string with delimiter-separated values to an array in Bash. Here I present five of them.

1. Using tr command

Output:> [123]
> [456]
> [567]
> [5]
> [343]
This method will produce incorrect array due to space in "567 5", but it works fine if there are no spaces in the $STR variable.

2. Using IFS (Internal Field Separator) variable

Output:> [123]
> [456]
> [567 5]
> [343]
This method works fine even if there are spaces.

3. Using read command

Output:> [123]
> [456]
> [567 5]
> [343]
This method also works fine even though there are spaces in the $STR variable.

4. Using sed command

Output:> [123]
> [456]
> [567]
> [5]
> [343]
This method will also produce incorrect array due to space in "567 5", but it works fine if there are no spaces in the $STR variable.

5. Using set command

Output:> [123]
> [456]
> [567 5]
> [343]
This method also works fine.

References

This post was mainly inspired by this StackOverflow question and my need to perform string 2 array conversions in bash.

Wednesday, February 24, 2010

bash: read a specific line or/and a column from a file

If we have column-row wise txt files, we can use awk and sed programs to read the rows and columns of such files.

Read specific line

To read a specific line from a txt file, the following commands can be usedawk 'NR==12' file.txt sed -n '12p' file.txt In both cases, line 12 will be returned.

Read specific column

awk '{print $1, $2}' file The code will return first and second columns from file.txt

Read specific column and line

Additionally, using awk we can get a specific column(s) in of a given line as followsawk 'NR==12 {print $1, $2}' file.txtThe Code will return first and second columns form a line no. 12.

Sunday, February 21, 2010

xampp: Compiling mod_bw.c and getting the error about undefined symbol: apr_atomic_cas

When I was compiling mod_bw.c 0.7 (apxs -i -a -c mod_bw.c) for xampp 1.7.1 on Ubuntu 9.10 and restarting lampp I was getting the following error:httpd: Syntax error on line 129 of /opt/lampp/etc/httpd.conf: Cannot load /opt/lampp/modules/mod_bw.so into server: /opt/lampp/modules/mod_bw.so: undefined symbol: apr_atomic_casThe solution was to edit the mod_bw.c and comment out or remove the following lines:#if (APR_MAJOR_VERSION < 1) #define apr_atomic_inc32 apr_atomic_inc #define apr_atomic_dec32 apr_atomic_dec #define apr_atomic_add32 apr_atomic_add #define apr_atomic_cas32 apr_atomic_cas #define apr_atomic_set32 apr_atomic_set #endifand to recompile the file.

Unfortunately, there was no difference in the file upload speed.

Saturday, February 20, 2010

ImageMagick: add text to many images

Lets assume that we have 800x600 pixels images and we want to add an authors name to the lower right corner. We can do this using the following command (the command overwrites the original files!)
mogrify -fill white -pointsize 16 -annotate +685+590 'Authors Name' *.JPG

Thursday, February 18, 2010

ImageMagick: split one image to smaller images

Lets assume that we have a 1024x1024 pixel image called test.tif and that we want to split this image into 64x64 non-overlapping images called test001.tif, test002.tif, test003.tiff,....
We can do this using this command from
convert -crop 64x64 +repage test.tif test%02d.tif

Wednesday, February 10, 2010

VirtualBox: Autostart guest in Windows XP host

Some time ago I was asked to quickly setup a temporary LAMP server. Since, the time was an issue and it was supposed to be only a short-term solution I decided to take a PC box with Windows XP, install a VirtualBox, and setup an Ubuntu server 8.04 LST as a guest operating system.

Unfortunately, it was over a 1.5 year ago and what was a short-term solution become now de-facto a long term one. However, recently we had some power shortages in our building, and the problem appeared with this PC box, i.e. after it went down due to power shortage it did not start VirtualBox automatically when being turned on. Thus, I was asked to make it start automatically, in such a way that after turning the PC on, everything VirtualBox and ubuntu-server start automatically. I did it in to steps:

1. Setup autologin in Windows XP.

To do this I followed instructions from here.

2. Make VirtualBox start automatically.
To do this I wrote very simple Windows batch script called startVB.bat that contained the following two lines:cd "C:\Program Files\Sun\xVM VirtualBox"
vboxmanage startvm "ubuntu-server"
where "ubuntu-server" is the name of virtual machine to be started. The script was located in Startup folder C:\Documents and Settings\MY_USER_NAME\Start Menu\Programs\Startup.

Friday, February 05, 2010

Anonymous Internet browsing using Ubuntu 9.10, Tor and Firefox

"Tor protects you by bouncing your communications around a distributed network of relays run by volunteers all around the world: it prevents somebody watching your Internet connection from learning what sites you visit, and it prevents the sites you visit from learning your physical location. Tor works with many of your existing applications, including web browsers, instant messaging clients, remote login, and other applications based on the TCP protocol." [taken from Tor website]

Basically we need to install three things:
  1. Polipo - a proxy server,
  2. Tor, the onion router, and 
  3. Torbutton -a Firefox add-on.
Bellow are steps to install these three things.

Install Polipo, a caching web proxy
sudo apt-get install polipoSetup polipo
Manually open /etc/polipo/config and copy-paste config details here or sudo sh -c "wget 'https://svn.torproject.org/svn/torbrowser/trunk/build-scripts/config/polipo.conf' -O /etc/polipo/config"After this restart polipo sudo /etc/init.d/polipo restart Add Tor repository
sudo sh -c "echo 'deb http://deb.torproject.org/torproject.org karmic main' >> /etc/apt/sources.list" Add Tor repository GPG keygpg --keyserver keys.gnupg.net --recv 886DDD89
gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
Update repositories and install Torsudo apt-get update
sudo apt-get install tor
Install Torbutton (an add-on to firefox)
Just go to website of Torbutton and install it.

Check if you are anonymous
Enable tor in Firefox using the Torbutton, and go to Are you using Tor?If everything is OK you should see the following:
Additionally, you can install vidalia, a GUI for Torsudo apt-get install vidalia
Now, using vidalia you can create a new identity (i.e. a new IP) whenever you want:

Monday, February 01, 2010

Javascript Prototype: En example of periodical event broadcaster with ajax

The class below executes script.php every 60 seconds. After successful execution, it throws an event "jobs:updated" with JSON data returned from script.php.