Wednesday, October 1, 2008

Latex Figure and \label

Always put the label after the caption, otherwise floats wont be referenced in text !!!!

just ridiculous :s

Sunday, July 27, 2008

clear fonts on ubuntu

http://ubuntuforums.org/showthread.php?t=208396

Saturday, July 19, 2008

Google Codejam



I totally forgot that I've signed up for Google code jam (http://www.google.com/codejam/) and I've missed the qualification round... sigh!!

Next time hopefully I'll remember and not miss the qualification round

Saturday, July 5, 2008

Matlab icon


So, I can find it somewhere

Sunday, June 29, 2008

Adding a line at EOF to a bunch of files at once

Some people use horrible IDE's to write some horrible C/C++ code that will give many nasty warnings in gcc/g++ because of a missing line at the end of file

here is how to add a line to the end of each file


for f in `find . -type f | grep ^.*.c`; do echo -e "\n" >> $f; done


It could be a more sophisticated line of bash, but this will do for the mean time

Saturday, May 10, 2008

Installing Matlab on Linux

Unfortunately, Matlab is not free!! and i currently only have Matlab 7 R14 student version. In any case we'll install Matlab on linux..

step 1: insert the CD into the CD-ROM
step 2: go to /media/cdrom (that is in ubuntu)
step 3: sudo ./install_unix.sh
this will run a "nice" installer, it'll prompt you for a root directory for matlab files. If you keep your /home partition separate from the / partition then install matlab somewhere in /home so you don't have to install it every time you feel like getting a new linux version, otherwise /usr/local/matlab sounds like a good choice.
The script will also ask you if you want to create symlinks in /usr/local/bin or whatever directory in the $PATH, it is a good idea to say 'y' so that you don't have to put the full path name every time you feel like Matlabing :)
step 4: install gawk so Matlab will hopefully work, and you also should have java installed preferably java-sun, not the gcj; sudo apt-get install gawk
step 5: go to where ever you installed matalb, say /usr/local/matlab and enter the bin directory /usr/local/matlab/bin and run ./matlab this will ask you for the serial number, enter your serial number and enjoy Matlabing for the rest of the night!!
* Notice that a "student license" is only good for one computer :(

Have fun!

Friday, May 9, 2008

OpenCV stuff 0

Hello world,
we'll do opencv cool things running on Linux, as I have no idea how to do any of the stuff with visual studio

we'll start with a very simple example that will draw nice shapes in an image

#include <opencv/cv.h>
#include <opencv/cvaux.h>
#include <opencv/highgui.h>
#include <stdio.h>
#include <l;stdlib.h>

// a simple example that creates an image and fills it up with stuff
int main(int argc, char *argv[])
{
IplImage *img;
int i, j, step, channels, height, width;
uchar *data;

// WxH, depth, channels
img = cvCreateImage(cvSize(640,480), 8, 1);
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels; // which is 1 (gray image)
data = (uchar *)img->imageData;

for(i=0; i < height; i++)
for(j=0; j < width; j++)
data[i*step + j*channels] = (i*i + j*j) % 256;

// create a window
cvNamedWindow("image", CV_WINDOW_AUTOSIZE);
// show the image
cvShowImage("image", img);
// wait for 'q'
while(cvWaitKey(0) != 'q')
;

// destroy the widnow
cvDestroyWindow("image");
// don't forget to release the image
cvReleaseImage(&img);

return 0;
}

Cool... now to compile the opencv program, it is even easier, we'll use gcc here:

gcc `pkg-config --cflags --libs opencv` -o opencvsimple opencvsimple.c


Done!

Monday, January 14, 2008

Useful BASH string manipulation tricks

A lot of cool bash string manipulation http://www.linuxjournal.com/article/8919

error: cout is not a member of std

What the ....?

Q:What is wrong with this block of code in a program?

std::cout << "HelloWorld\n";


A:
#include <iostream>

Wednesday, January 9, 2008

Zombies

Zombies!! What are they?
Zombies are walking corpses, they sometimes talk but in general they are not very talkative. Zombies being not very talkative is the main problems in dealing with them. However, we can always find them and deal with them. The easiest way to deal with them is to restart, which is not very good in a lot of times.

Zombies
are those children created by a parent process whose parent died before reaping them

In other words, some lousy piece of code written by some lousy programmer that forks children. However, the programmer didn't account for the possibility that the parent might die before its children. The net result of this mess is a bunch of zombies leeching system resources and leaving your machine unsure of the next step.
Reasons to create zombies:
  1. The programmer was really very bored and didn't want to check
  2. The assumption that forked children will be nice and die before their parents
  3. The assumption that the parent will be mean and not die unless kills all children
  4. The assumption that someone will come and kill those children, which actually happens when the init process takes over and clean up things, but this is no execuse
  5. The programmer was out of coffee or time
  6. The programmer needed more time and a more screwed up machine to test his screwed up code
  7. The machine is actually a zombie, so the programmer won't notice more zombies
  8. Zombie infection might have taken over the machine in an unrecoverable way, through open ports. It'll get worse when the infection is done by a tunnel and even worse when the machine doest not have a good antibiotic or vaccinations
Solutions to the above mentioned problems:
  1. The programmer should never feel bored and should keep coding till one of two things happen:
    1. Power outage
    2. Coffee leak
  2. Children are never nice and won't die by themselves. They must be killed and reaped by their parent in a very brutal and gory way
  3. Parents will never bother to reap their children automatically because they are really easy and have the tendency to screw the programmer. The programmer should threaten the parents by issuing random SIG_INT so they'll be afraid of leaving their children alone!!
  4. No one will come and clean zombies processes from your system!! Go wait (kill) them by yourself
  5. Programmer out of coffee is a FATAL error and nothing much can be done about it, responsibility is put on the supervisor! However as for time, the programmer should never relay on the accuracy of time as this electron around the Cesium is not really what you mean by accurate
  6. Time again (please refer to 5). A screwed up machine is very easy (use VISTA)
  7. Programmer is completely responsible for turning the machine into a zombie. The programmer should leave the machine to his/her younger brother or sister if any. If not the programmer should be careful and turn this zombies machine into a coffee machine and proceed to the nearest computer store and to buy some new gear. Things to remember when buying new gear is how easily the new gear is transformable to a coffee machine or cubs holder
  8. Whenever a zombies infection is present on the machine go SLEEP and don't go out under sunlight... it is you the programmer who turned to a zombie
In any event, I was really bored and I wrote this silly shell function to tell me if there are zombies and tried to kill them. Please note that mechanism of killing zombies are beyond the scope of this post. Also, comments are left as an exercise for the reader..

zombies() {
z=`ps aux | awk '{ print $8 " " $2 }' | grep -w Z`
id=${z#Z}
if [ ! -z "$z" ]; then
  echo -e "You have a zombie `whoami`"
  echo "ID: $z"
  ps aux | grep Z
  echo "Killing $id"
  kill -9 $id
else
  echo "No Zombies!!"
fi
}


Ok world, we'll get back to more interesting things like daemons very very soon.. stay tuned :)

Saturday, January 5, 2008

Colors...Grrrrrrrr [frawn]

Hey World...
I have no clue why on earth my choice of colors is really really silly....
i don't even like them.. and I can't find better colors..
Whenever i try to fix it..I just make it worse.. Grrrrrrrrrrr..

I'll get back to fixing colors later..

i hate colors....

Friday, January 4, 2008

Static IP address in Linux

There are many occasions in which you might like to have a static ip address for you machine instead of the one generated dynamically by the router.. Maybe you want to run a webserver, or ftp server, or maybe want to SSH to your machine from any place.. Then you need to now the IP address of the machine, which is not very easy if you are not in the local network... i'm bored of reasons.. let's get to the point:

To assign ur machine a static ip address do this:

Edit /etc/network/interfaces
to have this:

auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.1.10
network 192.168.1.0
netmask 255.255.255.0
gateway 192.168.1.1
broadcast 192.168.1.255

Then, restart networking

sudo /etc/init.d/networking restart

And check the new address by

ifconfig eth0 | grep "inet addr"


Done!!

Testing Code CSS

Finally, let us use CSS to post code, to save time and make it look good
This is only a test for the new style sheet.
-----
The style is subject to change without warning
-----


#include<stdio.h>
int main()
{
printf("HelloWorld!\n");
return 0;
}


Does that look good?
Hmm.... Good enough :)

Change the Default Gnome Terminal size

Gnome terminal comes really small (80x24) which is really small. Further, the GUI provided with it does not let you change the default size easily. So, you have two options:
  1. Keep changing the size manually with the mouse every time you launch a terminal (because Gnome terminal doesn't save its size)
  2. Look for those configuration file and change them
We'll do option 2, apparently option 1 is silly, boring and counter productive.

Gnome terminal follows termcap specifications, so you should find your xterm termcap file and edit it. (We'll get back to what a termcap is in some other posts)

The file in Ubuntu and most other distros is found in
/usr/share/vte/termcap
you'll find this in the file:
:co#80:it#8:li#24:\
change whatever after co# and li# to your desired settings
for me i love this one
:co#90:it#8:li#26:\

And restart you machine..
Done!!!

Other possibilities are also available..
One thing you can do is to right click on the Gnome Terminal launcher in your Gnome Panel and chose properties, which look like something like this:
Then add this next to "Command" --geometry 90x26, so you'll get this:
And this will work also...
At the end of the day, you have permanently changed the Gnome terminal size :)

... Done!!!

Restore your linux

Well.. let's go format Windows... thanks to the nice virus, but this will erase my ubuntu from MBR and I'll not be able to boot into it..
So, after installing windows and wiping out the windows partition. You get the ubuntu live CD and do the following:
sudo grub
find /boot/grub/stage1
This will tell you where are the boot files, something like hd0 or sda1, so you use that in the next step
root (hda0, 1)
setup (hda0)
quit
Remove the liveCD && restart your machine

Now you have a fully functioning Linux partition, if you haven't wiped it out accidentally while reinstalling windows.

More stuff in here:
http://ubuntuforums.org/showthread.php?t=224351

Thursday, January 3, 2008

Awful..!!!

Sorry world for the awful colors in this post :( http://byeworld.blogspot.com/2007/12/bash-loops.html

Just an artifact from the 2007 :P