Sunday, March 30, 2008

Prime Numbers Generator

did u know that 34136029 is a prime number?!!
well.. that's what i recently realized :)

I thought of writing a piece of code for that purpose.. wondering how far i can get.

The idea of the code is simple
We know that 2 and 3 are prime numbers
the code checks every following odd numbers to be prime or not.

To verify a prime number, the number divisibility by the prime numbers generated so far is checked. (29 is a prime number.. because it id not divisible by 2, 3, 5, 7, 11, 13, 17, 19 nor 23)

We only need to verify divisibility against the numbers smaller than or equal to the root of the number in hand. (We needn't check the divisibility of 33 with 11, as we already must have found out it is divisible by 3)..

I did not want to go with the mathematical root evaluation as i am not sure about its load. I used bits handling instead. the root of a number uses at most half of the number of bits that the original number uses.

i only made a naive java implementation so far. download the jar file and try it yourself "java -jar prime-generator.jar"


Here i explain the implementation

Generating Primes
This method starts by marking 2 and 3 as primes.. then check the rest of the odd numbers until the upper limit is reached (this is a value passed as a parameter to the class OR the largest number that can be held in a long primitive type)


The longest long value can be found my shifting 1's to fill the bits of a long variable before it converts to a negative number.


to verify a prime number, the number in hand is compared to the identified prime numbers that are less than the assumed root limit.


Instead of evaluating the mathematical root. i used that fact that the root of a number will use at most half the number of bits used by that number.



the output for the program is

1: 2
2: 3
3: 5
.
.
.
485785: 7143883
485786: 7143887
485787: 7143911
485788: 7143931
485789: 7143959
.
.
.
2097148: 34135967
2097149: 34135999
2097150: 34136009
2097151: 34136021
2097152: 34136029

the code generated 2097152 prime numbers.. starting with 2 and ending with 34136029.

i think i can go farther...

it was stopped by ArrayIndexOutOfBoundsException. there must be a way to get a larger array... or i have to find another way to track the numbers instead of having them in memory.

Wednesday, March 19, 2008

MeOwns

"Expressing yourself through your belongings"

This is the main idea of eSpace new product, meowns. It is still currently a beta version. The main part of MeOwns is the widget. you can see that in the right side of the my blog.
well.. simply, that's me; owner of those books, that mobile device, that nice FZ3 digital camera and those cats. does that tell u anything about me. well, i guess yes. at least an impression.
You can ask me about my experience with this stuff too. We can share ideas, thoughts and wishlists. i can find other FZ3 owners or other cat owners, maybe we can be friends.

It is much interesting. i believe the meowns team did a great work here.

You currently need to be invited to make your meowns account, so leave me a note with your email if u want to try.

Thursday, March 13, 2008

Firebug on Firefox 3.0b4

i had installed the beta firefox 3. it seems nice.. and less starving for memory so far (the thing i really hated in FF).
One issue i had is that most addons aren't yet compatible with the new FireFox. including firebug. As a Web Developer, i cannot imagine being with no FireBug available. Firefox 3 couldn't not find a compatible update. and when u search for the addon manually on mozilla addons. u get the old one that is compatible with FF2.

Fortunately. i was able to locate FireBug 1.1 beta that is compatible with FireFox 3. i guess it was not added to the addons list because it is still a beta...

find a website value with dnScoop

I came across dnScoop, an online tool to determine the estimated value of a website depending on several factors. Factors include Domain Age, Page Rank, Inbound Links, Traffic Rank and others.

The power of dnScoop is that it interacts with several other domain lookup tools out there. u only need to provide the domain that you are interested in. unlike other website value calculators like websitebroker calculator and glurk that requires u to enter some data (monthly traffic, and Alexa Page Rank,....)
according to dnScoop this is the estimated value for some websites
www.yahoo.com worth $1,884,000,000
www.google.comworth$1,740,000,000
www.sun.comworth$29,056,000(22 years old)
www.facebook.comworth$263,900,000
www.microsoft.comworth$397,440,000
www.cnn.comworth$29,440,000
www.masrawy.comworth$96,900(8 years old)

Sunday, March 09, 2008

God's Greatest gift...

102 days Ago Allah gave me the greatest gift i ever had... my young Hazem..

i like it when i sit with the 3 month old fellow... talking to him and watching his responses... the best of all.. is that i can see he is totally focused with me in the conversation... his smile is priceless..

i'm really amazed how he made me feel

Monday, March 03, 2008

Using maven with eclipse

As i first started using maven for my projects, I used to add the maven plugin to eclipse. The plugin makes you able to mark a project as "maven enabled". This adds the library maven dependencies to the classpath of the project so the dependency libraries can be visible to your classes.

As i moved further, I found a better way dealing with maven projects using eclipse; maven eclipse:clean and eclipse:eclipse goals.

the goals enables you to make all the configuration and settings through command line which is more powerful and stable. Actually i now never created a new project inside eclipse. It is better to created it outside using maven. Then through eclipse:eclipse u create eclipse project settings files that is ready to be imported to any running eclipse instance.

M2_REPO variable that points to the local maven repository. The pretty thing is that you can add that variable to an eclipse workspace through mvn -Declipse.workspace={workspace-path} eclipse:add-maven-repo

To put things into order. for better use of maven and eclipse:

Setup maven repo variable for the eclipse workspace

mvn -Declipse.workspace=D:\java\eclipse-workspace eclipse:add-maven-repo

Create your new maven project through command line

mvn archetype:create -DgroupId=com.mycompany -DartifactId=MyProject -DarchetypeArtifactId=maven-archetype-webapp -Dpackaging=war -Dgeneratepom=true

Change the working directory to that of the new project and setup eclipse project files

mvn eclipse:eclipse

When you edit your pom file to add/remove dependencies you must resetup the eclipse project files through

mvn eclipse:clean eclipse:eclipse
and then do not forget to refresh ur project in eclipse :)

find more about maven with eclipse