December 28, 2006

Few Linux commands to make hardware work

sometime we find it very difficult to make our linux detect the peripherals connected to the system.
well these few commands will help:-
lspci- this will output the peripheral devices connected to the computer bus. use -v option to see the details of the devices.
Now u have to find the modules for the hardware which u r unable to use in linux. In my case it happened to be onboard soundcard. Search on google to download the kernel modules for the hardware u want to make work. Download the modules for ur kernel version. To find which kernel u r running use uname -r.
I downloaded alsa-modules for my kernel ie. 2.4.27-2-386

now use this commmand
modprobe module_name
to load the module in the kernel.
and u r done.
hope this will give u hint to know wht to do? Well i m new to linux n trying to learn basics. Will post something interesting in next post.

June 20, 2006

A C program which prints itself

main(){char *s="main(){char *s=%c%s%c;printf(s,34,s,34,10);}";printf(s,34,s,34,10);}

cool declaration of 's'.
see here 34 is for ' " ' and 10 for newline.

June 15, 2006

removing duplicates from array

One simple way to do it is sort the array by some efficient algos ie O(N*log(N)).

rather than that you can create a new associative array with indexes as the value of the given array elements .

so to remove duplicate in, say,

A[]={1,3,5,3,8,1,3,5,8,5,5,4}
we create a new associative array B[] such that

for (i=0; i< style="color: rgb(51, 51, 255);"> B[A[i]] = 1;

now you can get the array of keys having value '1' in A
ie
A = getkey(B,1)
where getkey will return the array of keys where value of B[key]=1
so A will not have the duplicates.

swapping two variable without using temp

This is very trivial stuff. Still I thought it could be helpful to someone.

Let two variables to swap be 'a' and 'b'

so,
step 1) a = a + b
step 2) b = a - b
step 3) a = a - b