Sunday, January 06, 2008

latex and footnotes

In latex if you have a footnote and a figure with b (bottom) placement attribute on the same page, then the figure will be placed under the footnote. The result is really ugly....

I was searching for a way to fix this. Of course the straight-forward solution is to use the h (here) attribute in the figure and put the figure's code in the position you want, but this is not the best thing to do.

Well.. there is a way to force the footnotes to be always placed at the bottom of the page. You can do this by using the footmisc-package. By using this package you can change the default typesetting of footnotes. If you include the line:
\usepackage[bottom]{footmisc}
in latex preamble you get the desired footnotes behavior.

Thursday, January 03, 2008

Bit Operations: find first zero bit

If anybody cares here is an algorithm to find the first zero bit in a number:
  1. Invert the number
  2. Compute the two's complement of the inverted number
  3. AND the results of (1) and (2)
  4. Find the position by computing the binary logarithm of (3)
e.x.
For the number 10110111
  1. 01001000
  2. 10111000
  3. 01001000 AND 10111000 = 00001000
  4. log2(00001000) = 3
But in a x86 processor environment there is a more simple way to do this since Intel provides a specific assembly instruction for this purpose called bsfl. This instruction return the position (index) of the least significant bit set to 1 in a 32-bit word. By using inline assembly, someone can easily create a function that finds the first zero bit by inverting a number and feeding it to this instruction. For 8-bit numbers, the code for this in gcc would look like this:
/*
* find the position of the first 0 in a 8-bit array
*/
inline unsigned short find_first_zero(uint8_t bit_array)
{
unsigned pos = 0;

__asm__("bsfl %1,%0\n\t"
"jne 1f\n\t"
"movl $32, %0\n"
"1:"
: "=r" (pos)
: "r" (~(bit_array)));

if (pos > 7)
return 8;

return (unsigned short) pos;
}

Wednesday, December 05, 2007

forkbomb

have you ever seen this:
:(){ :|:& };:

This is a bash fork bomb.

It's the same as writing:

func()
{
func | func&
}

func

but it looks a lot more cryptic.

Thursday, May 10, 2007

Matlab R2007b ugly bug

Just installed the latest Matlab software on my Slackware 11 PC and after using it for less than 120 seconds it crashed. I tried to replicate the conditions under which matlab crashed and it was really easy. In matlab's main window in the menu I went to File->Preferences... and in the Preferences window just pressing Fonts in the left navigation bar was enough to crash Matlab.

It must have been a java related thing, because I managed to fix it by just updating matlab's java jre. OK, well here is a solution:

  1. Download java's latest jre and select the Linux (self-extracting file).
  2. Extract the jre: "sh jre-6u1-linux-i586.bin". This will create a jre1.6.0_01 directory. I did not want to update slackware's java. I leave mr. Volkerding to do that for me :). Matlab comes with a local copy of jre and this is what is used by default unless the MATLAB_JAVA enviromental variable is set to point to an external jre directory when $MATLAB_ROOT/bin/matlab script is executed. The matlab's local copy of java is under $MATLAB_ROOT/sys/java/jre/glnx86, at least for the linux x86 version.
  3. I copied the jre1.6.0_01 directory there and updated the jre.cfg file of the directory with the new jre version "echo jre1.6.0_01 > jre.cfg". The old version was 1.5.0.
  4. I also removed the old jre directory: jre1.5.0 but this is optional.
After this everything worked fine.
Happy "Matlabing"

Wednesday, November 01, 2006

Mplayer rc1

Mplayer entered in rc state. It must have been more than 2-3 years it was on a pre-release state.
I guess 1.0pre8 must have been the last pre-release version.
8 pre-releases is not that much... Links 2.1 is in pre-release 23 :)

Monday, May 29, 2006

slackware-current and TV-Card

Ok, After having for years a TV Card hooked on one of my motherboard's PCI slots and never using it I decided to configure it and make it usable. My card is an old PixelView PV_BT878P+ (REV .9F) card with a TPI8PSB02D tuner on it, or at least that what it is printed on the tuner :).

It wasn't hard at all. I just open /usr/src/linux-2.6.16.18/Documentation/video4linux/CARDLIST.bttv and the most relative card values for my case were:
16 -> Prolink Pixelview PlayTV (bt878)
37 -> Prolink PixelView PlayTV pro
50 -> Prolink PV-BT878P+4E / PixelView PlayTV PAK / Lenco MXTV-9578 CP
70 -> Prolink Pixelview PV-BT878P+ (Rev.4C,8E)

For the tuner I opened /usr/src/linux-2.6.16.18/Documentation/video4linux/CARDLIST.tuner and since I couldn't find the exact model I tried those values:
tuner=28 - LG PAL_BG+FM (TPI8PSB01D)
tuner=29 - LG PAL_BG (TPI8PSB11D)

To make the modules load correct through hotplug I just created a new file in /etc/modprobe.d/, I named it v4l with those options in it:

# i2c
alias char-major-89 i2c-dev
options i2c-algo-bit bit_test=1

# bttv
alias char-major-81 videodev
alias char-major-81-0 bttv
options bttv card=70 radio=1 tuner=28

card=70 and tuner=28 gave me the best result I think. The signal is a lot weaker than the one I have on my TV and if I remember correct it's also weaker than the one I had in windows years ago, but at least the card works. I use tvtime as a TV application.

What exactly is the problem? the card, the modules, tvtime, me?

Tuesday, April 11, 2006

strange problem with Greek subtitles in mplayer

Ok, a few days ago, I compiled mplayer again, using the source from the CVS this time. Everything seems to be fine, until I discovered a really strange problem when displaying greek subtitles in avi movies.
The Greek were sort of inverted horizontaly.
Instead of displaying:
"Τι κάνεις" it looked more like "ςιενάκ ιτ".
English were displayed fine, so "Τι κάνεις John" looked like "ςιενάκ ιτ John".

I tried using a windows arial.ttf font with the same results. What I had to do is keep the font encoding to Modern Greek (ISO-8859-7) but change the Subtitle encoding in Subtitle & OSD tab to Western European Languages with Euro (ISO-8859-15). I don't know why but after doing this it worked.

Thursday, March 30, 2006