Tuesday, March 1, 2011

Prime Number in Perl with a twist

Just a few days ago, I learned that all prime numbers > 3 can be represented as multiple of 6 +1 or -1.

So here's a code in perl to find nth prime number.


#!/usr/bin/perl

print "Enter the number: ";
chomp($num = <>);
$i = 3;
$no_of_prime = 3;
$prime = 0;
if ($num == 1)
{
print "1st prime is 2 \n";
}
elsif ($num == 2)
{
print "2nd prime is 3 \n";
}
elsif ($num > 2)
{
$index = 1;
$powindex = 1;
$no_of_prime = 2;
while($no_of_prime < $num)
{
$prime = (6 * $index) + ((-1) ** $powindex);
$j = 2;
$is_prime = 1;
while($j <= ($prime ** 0.5))
{
if(($prime % $j) == 0)
{
$is_prime = 0;
break;
}
$j = $j + 1;
}

if ($is_prime == 1)
{
$no_of_prime++;
}

if(($powindex % 2) == 0)
{
$index = $index + 1;
}

$powindex = $powindex + 1;
}
print $num, "th prime is: ", $prime, "\n";
}
else
{
print "Invalid number\n";
}
#END

Monday, February 28, 2011

USB Tethering SPICA on fedora

I just usb tethered SPICA on fedora 14.

Here's what I did (could be ugly than other tutorial but works)
But before that, the following helped me.

http://code.google.com/p/azilink/
http://androidforums.com/samsung-i7500/19510-adb-linux.html
http://idolinux.blogspot.com/2010/06/usb-tether-android-with-linux.html <-- Better read this site, than the below thing.

Part 1: Install the driver:
1. Create a new file /etc/udev/rules.d/51-android.rules
vi /etc/udev/rules.d/51-android.rules
2. Copy and paste the below line
SUBSYSTEM=="usb", SYSFS{idVendor}=="04e8", MODE="0666"
3. Then in the terminal type:
chmod a+r /etc/udev/rules.d/51-android.rules

Part 2: Install the ADB:
1. Download the Android SDK. It is a .tgz file, extract it.
2. On the terminal go to the extracted folder. It has a sub-folder, tools. Go to tools/
3. Run ./android
4. A GUI comes up, on the left panel select "Avaiable Package".
5. Select "SDK Platform Android 1.5, API 3" from it and click on Install selected. Next Accept the license.
6. Now go to the /platform-tools/
7. Just to test adb is working, try
./adb shell
It should open a shell. That is actually your phone. If it didn't work, try reading the above links. Or try
./adb devices
This will show the device connected.
I got the following:
List of devices attached
5700db4ac5a1 device

My device is a Samsung Spica 5700

Part 3: azilink to tether:
Now install the azilink to your phone. Simply type
./adb install /azilink-2.0.2.apk

Follow the above given blog.

Tuesday, January 25, 2011

Mount windows shared drive

Here's a command I keep forgetting.
In order to mount a windows shared folder just try this with root access:

mount -t cifs -o username=Windows-username //ip-of-windows/shared-folder-name /mount/point

And you've got it

For passwords:
mount -t cifs -o username=Windows-username,password=password //ip-of-windows/shared-folder-name /mount/point

Here's a wonderful link:
http://opensuse.swerdna.org/susesambacifs.html

Thursday, September 23, 2010

Android USB Tethering on Linux

Find it here:

http://www.humans-enabled.com/2009/12/how-to-tether-your-verizon-droid-as.html

http://code.google.com/p/azilink/

Simultaneous sound through both speaker and headphones

I installed Fedora a few days back.
I had the same problem of "speaker not muting when headphone plugged in"
I used the following line:
options snd-hda-intel model=laptop position_fix=1
I had used this to fix the issue with OpenSuSE last month.

But somehow it didn't work. I kept looking and looking.
Then http://ubuntu-ky.ubuntuforums.org/showthread.php?p=9405102 pointed out that I was looking in the wrong place.
I went to System -> Prefernces -> Sound -> Output
And selected "Analog Headphones" instead of "Analog Output"
And it worked.
Thanks to everyone who posted there. :)

Laptop: Asus K40AB
Sound Card: VIA VT1708S (00:14.2 Audio device: ATI Technologies Inc SBx00 Azalia (Intel HDA))

Sunday, September 19, 2010

Fedora Guide

Just installed Fedora 13.

Here is a great guide to optimize your computer after installing Fedora

http://fedoraguide.info/index.php?title=Main_Page

Happy hacking