Thursday, August 24, 2006

Matlab and Perl: returning matrixes and cells from Perl to Matlab

Matlab, as one of the most preferable hight level languages among the scientist all over the world, provides interfaces to other programming languages. Normally you can attach to Matlab scripts programs written in: ANSI C, Java SDK , Fortran. This process is called external interfaces and information about it can be found here.

In addition to those languages, there is also possibility to use Perl programs within Matlab scripts. This can attributed to the fact, that Matlab, by default, has embedded Perl interpreter (in fact, it's tripped-down version of the interpreter). Therefor, you can use Perl scripts without any problems.

However, in contrast to ANSI C, Java SDK , Fortran interfaces, Matlab doesn't have any build in routines, to pass and return matrices, cells, vectors to and from Perl. The only thing returned to Matlab is string, which represents stdout of Perl script, meaning, that Matlab receives everything what is returned by print functions in Perl. Everything which normally is printed on stdout, is assigned to one string variable in Matlab. For instance if myscriptInPerl.pl is simple perl script print to console something, then executing this in Matlab console:

A = perl('myscriptInPerl.pl', var1,' var2', var3);

assigns to variable A, all output of myscriptInPerl.pl.

Based on that, my own solution to get matrices, cells, vectors, etc. returned from Perl, is to return string, representing Matlab's code, and executing function eval(A) in Matlab. For example

#myperlscript.pl
#Example file, with Perl scribt to be executed by Patlab
#

$out = "myVector = [2 3 4 5 5 6]; "
#variable with string representing Matlab vector

print $out; #print $out to Matlab

Executing above script in Matlab and evaluating returned string will create myVector variable in Matlab:

A = perl('myscriptInPerl.pl', var1,' var2', var3);
eval(A);

myVector =

2 3 4 5 5 6

Installation of Kubuntu 6.06

Few days ago I was helpping one friend with installation of Kubuntu 6.06 on a PC. I have to admin that personally I would prefer ubuntu, rather then Kubuntu, but he is a fan of KDE environment, so we downloaded it.

I haven't seen Ubuntu yet, so Kubuntu is my first insight into Dapper Drake (DD) family, which has drawn a lot of public attention lately, as being first distribution from Canonical with three and five year support, for desktop and server usage respectively. Since the release, I have read plenty of reviews and opinions about both Ubuntu and Kubuntu. Majority of them was positive about them, and many authors have stayed that (K)Ubuntu is definitively going in the right direction. Due to the fact there is huge amount of available reviews I'm not intending to write one more. Instead, I just want to describe my own experience and feeling about Kubuntu.

To begin with, I need to write that everything went smoothly, and there was not any single problem with installation, even though this PC was more then seven years old.

First positive aspect of Dapper Drake that I noticed is, that the CD you download, both Live and installation CD. Owning to this I could first check if Kubuntu would be working on my PC. I other world's, I could check if Internet connection, printer, etc. was OK. Afterward, knowing that my hardware worked, I started the installation.

Process of installation went smoothly, within surprisingly short time.

After that, I needed to install some additional stuff to my new operating system, so my first thought was to start Synaptic. And I was quite surprised, to find out that there was no Synaptic (graphical package management program for apt). So, no problem, I just run: sudo apt-get install synaptic and there was another surprise - nothing happened. So still, no problem, I open /etc/apt/sources.list and i had to manually unhashed few repositories. Finally, following all those operation I maneged to install what I wanted. Nevertheless, I had and still have mixed feelings about this.

As most of the users I (my friend) wanted to have mp3 support, video codecs, and other popular things, which desktop user must have, and they are not included in (K)Ubuntu by default, on account of licents difficulties. Because of that, I used easyubuntu. This is Python "script that gives the Ubuntu user the most commonly requested apps, codecs, and tweaks that are not found in the base distribution". It worked perfectly, in few minutes I had everything I wanted, and everything was working (audio/video).

Next, I needed to setup printer. I use netwerk HP printer. And there was no surprise, niether. It just worked, after finding it on the list of all printers in configuration panel.

The last stage, was to install VMware server. Unfortunately, this must be done manually, because there are no apt packages. So, I registered (to download vmware you must to register in order to receive free serial number) and I began the installation. There was another nice surprise, everything went perfectly. All process of vmware setup, consists of accepting default parameters :-). That was it:-)

So in conclusion, I strongly feel that Dapper Drake is good or even very good distribution, if you consider only first impression only. However, that little difficulty with Synaptec and apt, can be problem for newbies. I am sure, that my sister, would have huge problems with that, and what's more, I don't see any reasons why it is done like this.

This was my first text about Kubuntu 6.06. I reckon that during further exploitation there will be something new and maybe more interesting to write about.

Gmail and importing mails from other mail account

Some time ago, I switched from my old webmail, to new gmail provided by google.com.

Everything would be perfect if not the fact that gmail, does not have option for importing e-mails form other pop3 servers.

The only solution I found was to download all you emails using e.g. MS Outlook or Evolution. After this, it is necessary to run special program, which will send all your just downloaded mails to gmail account. It isn't the best solution to this problem, but I could not find enythig else.

Fortunetlly, I have access to Linux server with reasonable bandwich, so I downloaded all my mails from former account (more than 600MB) using Evolution mail client. It is client which goes with Gnome as default. Following this, you need to use one of available programs (gExodus - only Windows, gml, ngml) to export you mails from e.g. Evolution to gmail account. Evolution stores all emails in mbox files. If you use Ubuntu Breeze 5.10, this file shoud be somewhere in you home directory.

To export all you emails stored in mbox you can use e.g. gml python script. However, this script wasn't working for me. So, I found modyfied gml (ngml).

Example usage of ngml:

ngml mbox "/home/me/.mail/Inbox/Inbox.mbox" myaccount@gmail.com

And, finally it worked. All those operation were performed on Ubuntu server, which was used, in this case as SMTP server to send all those emails.

Nevertheless, I found it very strange that you have to do so many tricks to import your mails to gmail account. I wander why it is so complicated?

Monday, July 24, 2006

Gmail and plus-addressing

Plus-addressing is an additional option in some mail servers including gmail. What I mean by "plus-addressing" I mean addresses containing '+' in the local part of the email i.e. user-host. For example lets assume that someones email is: someone@gmail.com. If given server allows to use plus-addressing, you can append to the above email some string, also called a tag. And the above email may have form: someone+string@gmail.com, someone+work@gmail.com, someone+spam@gmail.com or someone+blahblah@gmail.com.

What are advantages of this plus-addressing? Thanks to this, we can have one email account, and we can have few addresses just by adding tags. Real power of this system can be seen using gmail accounts, when there is possibility to tell what should be done automatically with incoming email containing additional string after '+' sign. In another words, i gmail such action are accessible by filters.

I will show how to create a filter. Lets create filter that looks for tag: 'todo'. Because of that me email address: someone+todo@gmail.com. Such email for example I will give to my boss that he could send me mails to that addres, and in my gmail account they automatically will be assigne to a label called e.g.: 'work_to_do'.

To begin with we need to create 'work_to_do' label. To do this, you go to Setting and than Labels in your gmail account. There new label can be created:


Then filter must be created. To make a filter first click on 'Create a filter':



and after that you create filter in two stages. Frist, you define your tag (string after plus sign in your email address):


In the second step you define what action should be done with such email. In this case we want to assign label 'work_to_do'. To do this, you check 'Apply the label' and select label to apply and you create filter:

And that's it. From this moment on, you can recieve emails in the form of someone+todo@gmail.com, and they automatically are labeled 'work_to_do'.

Of course, you can consequently create others 'plus-addresses', and you can create different actions for them.

Your PHP installation appears to be missing the MySQL which is required for WordPress

Yesterday I went to this blog and I see:

Your PHP installation appears to be missing the MySQL which is required for WordPress.

I was quite suprise to see it, couse I hadn't been doing anything with my server configuration before, and yet something happend and this site was not working. What's more, my apache, php, mysql, phpmyadmin were working perfectly.

So, I did a little bit of googling, and I found solution on wordpress officiale site here.

I needed to add those lines just before mysql test in wp-settings.php:

if (!extension_loaded('mysql')){
if (!dl('mysql.so')) {
exit;
}
}

I also tried the second possible solution listed there, but it wasn't working.

Saturday, June 24, 2006

Mounting nfs share

When my nfs server is running, it would be nice to mount this share. I use Ubuntu 5.10 as one mounting the nfs share. In fact, I have access to few Ubuntu based servers, so my experience is mainly base on Ubuntu distribution.

Firts of all, to mount on Ubuntu you need root privilages. Asummig you have them, mounting is childish.

Actual mounting can be made in two ways:

  1. Manually - as root you mount using mount command:
    mount -t nfs 196.17.43.65:/home/me/mynfs /home/menew/mounted_nfs
    where:
    • -t nfs - we mount nfs
    • 196.17.43.65:/home/me/mynfs - IP and sheared folder
    • /home/menew/mounted_nfs - where this share should be installed on our local file system
  2. Using /etc/fstab
    Add one line to /etc/fstab describing your nfs volume e.g.: 196.17.43.65:/home/mwolski/mynfs /home/menew/mounted_nfs nfs noauto,rw,users,owner 0 0
    Thanks to this to mount you as a normal user can execute
    mount /home/menew/mounted_nfs

To unmount nfs partition, you invoke umount /home/menew/mounted_nfs just like normal other partition.

Used options in fstab

  • noauto - the nfs is mounted only explicitly,insead of being mount at bootup
  • users - normal user can mount this volume
  • owner - only owner of local directory (/home/menew/mounted_nfs) can mount
  • rw - mount is read/write

Friday, May 05, 2006

Ruby: One click Installer

I was writing a lot how Ruby is cool and great. But now I have come across two problems, or rather annoyance. First of all few days ago I tried to use Ruby on Windows XP; hence, I had installed One-Click Ruby Installer. According to description it contains 'Ruby language itself, dozens of popular extensions, ...'. So I installed it without any problems, it run also without any problems. Nevertheless, I wanted to program some script using Tk. So I was quite surpriese when I found out that I cannot use Tk. Of course due to this, I did not do any programming. Of course this is because I did not install Tk on Windows, but without the access to the Internet, it was hard to do it.

The funny thing about this is, that when you working mostly with Unix based systems (Mac X, Linux, Solaris) many things you assume for granted, like presence of Tk. I forgot that on Windows there is no Tk, just like many other things :-)

Second thing is rather not Ruby but Tk itself. I think that combo boxes are quite useful in GUI applications; nonetheless, Tk does not have combo box widgets. This I already knew from Perl, but with comparison to Ruby, Perl has third party modules that provide combobox functionality eg. JComboBox, Tix. Problem with Ruby is that there is no combobox out of the box, and even though there is Tix port to Ruby (here), its documentation is in Japanese, so for me and for many other programmers it rather not very useful.


Wednesday, April 19, 2006

Latex: Sorting and referencing using bibtex

Standard way of referencing in Latex is to put references number is square brackets, ,e.g., [3]. However, sometimes it is necessary to put references in superscript. To do this in TexShop it is enough to include package Natbib and use it like this:\usepackage[super,sort&compress,numbers]{natbib} This results in reference numbers as shown below
instead of standard way:

Wednesday, April 05, 2006

Ruby: Real number precision

If you do some things that involve float/real/double numbers in Ruby, you must lookout for one thing. For example if one write code like this:

#!/opt/local/bin/ruby

(0..5).each {|x|
puts x/2
}

the result will be:

0
0
1
1
2
2

As everyone can see those results are quite incorrect, cause Ruby assumes that x/2 is division of two integer numbers; hence, the result also must be integer. Such small thing, can be very unseen and hard bug to detect, especially if long, mathematical function is written.
Correct version of the above code is:

#!/opt/local/bin/ruby

(0..5).each {|x|
puts x.to_f/2
}

The result finally is ok:

0.0
0.5
1.0
1.5
2.0
2.5


I had this bug lately and it took me quite a time to find out why my program gives incorrect results.

Friday, March 03, 2006

imagemagick: apply median filter

Apply median filter of radius 2:for f in *.tiff; do convert -median 2 $f ../outDir/$f; echo $f; done