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

Sunday, February 12, 2006

Matlab code time execution

Most people is familiar with tic; toc; commands in matlab to check execution of their code;

But more detail insight into this problem is by profile viewer.


This nice tool shows exactly how much time is used by each line, how many times it is executed. Moreover, profiler also gives some suggestions how to improve execution time.

For example, thanks to profiler I was able to reduce time of one image processing program from few hours to few minutes. Profiler showed me, that very simple operation, takes huge amount of time. Just by removing, changing and rewriting few time consuming lines, I was able to significantly shorten exec time of my program.

Thursday, February 09, 2006

Mac X: Changing bash prompt in X11's xterm

Default bash prompt in my X11's xterm was:PS1="\h:\w \u"This was very annoying as the prompt contained all the path to the current directory, which was especially bed if I went dip into the directory tree. In such a case it is better to use '\W' option instead of '\w', as this option shows only current directory name, and not full path to it. To change bash prompt use:export PS1="\h:\W \u$ "To make it permanent just add this line to ~/.bashrc.

Thursday, February 02, 2006

Unreal Tournament 2004: Make it slower

UT2004 is very nice and one of my favorite games. One nice option it has it is possibility to setup the speed of the game. You cannot do it in game itself, however, to do it, you must edit: UT2004.ini file in: \UT2004\System and change the value of variable GameSpeed Originally: GameSpeed=1.000000

I use GameSpeed=0.650000 My computer is not fast enough to render the game in its original speed. Moreover, with slower action, it is easier to observe all those special effects that game has - you can observer, e.g., rocked heading your way, which is pretty nice.

Tuesday, January 17, 2006

Latex: draft option

Writing some long document/article in latex with a lot of figures can be not very nice; providing that, the more figures you have the more time it takes to render your documents. Therefore, sometimes it is usefully to just switch off graphics. This can be done by using 'draft' option in a document class e.g.\documentclass[onecolumn,12pt,draft]{article}
Thanks to this embedded pictures are not displayed; instead, only an outline of the box taken up by the picture is shown. This significantly improve rendering.

Sunday, January 15, 2006

Matlab: getargs.m

Get arguments function code (getargs.m)
function S = getargs(defaultS, varglist);

if mod(length(varglist),2) ~=0
error('Odd number of variable parameters');
end

S = defaultS;
i=1;
while i <= length(varglist)
if isfield(S, varglist{i})
S.(varglist{i}) = varglist{i+1};
else
warning_wrap('getargs:unknown_param', ...
['Unknown parameter "' varglist{i} '"']);
end
i = i+2;
end

Tuesday, January 10, 2006

Ubuntu: quick setup of vsftpd server

Instead of proftpd it is faster to use vsftpd. After installation (sudo apt-get install vsftpd) just: sudo vim /etc/vsftpd.conf
And uncomment lines:write_enable=YES
local_enable=YES
and comment line: #anonymous_enable=YES
Finally restart server by: sudo /etc/init.d/vsftpd restart