Saturday, November 25, 2006

Hacker Puzzle

A friend told me about this Hacker Puzzle and I found it interesting enough to post it..

OK, it might/probably be very easy for people of our area,
but it's worth trying..

22 levels.. Good luck..

Wednesday, November 22, 2006

PocketPC application with WebService

After spending about 2 days of my life trying to create a PocketPC application that connects with a database through WebServices, I finally made it!

The main problem was that the articles/guides/how-tos that I found on the net, where misleading me instead of helping me. The reason is that some of them didn't mention to which versions they were referring to, and persuaded me to do things that I didn't have to.. So, if you are working with Visual Studio 2005 beta 2, there are some problems that I am not going to discuss. The same goes for VS 2003. What I am using and going to talk about, is Visual studio 2005 and PocketPC 2003 Emulator.

Below I am listing the steps you need to follow and the reason for each one of them. If you don't understand much, just follow the steps and ignore the reason :)

To start with, I need to have a webservice that contains at least a method that returns a Dataset. That dataset is supposed to be filled with a Table from a database.

Then I create a PocketPC project. I add as web reference the webservice to the PocketPC project and then I call the method.. Then I try to build.. Up to here, everything looks normal. But, there are several issues..

1st. The emulator doesn't have internet by default.
The problem is that the emulator considers the device being on hand and not on it's base. What you have to do, is go to Tools->Device Emulator Manager, select "PocketPC 2003 SE Emulator", right click and select Cradle. Now, the Pocket PC device is considered connected with the pc.

But, still that's not enough. You need to download a software the will allow the sharing of your internet connection with the the PocketPC Device (Emulator). This software is freely provided by microsoft, and it is called ActiveSync.

2nd. The Emulator even though is connected to internet, cannot access the webservice.
The problem is that the webservice is running at the localhost(your pc) and your pocketpc is trying to find it at its localhost(the pocket pc).. So, the problem is that both webservice and pocketpc are trying to communicate at localhost, but each one of them mean something different when they say localhost. To fix this, you should define at your pocketpc project, that the web reference that you are using is at your ip and not at localhost. That has to be done in two places. One is the properties of the web reference, and the other one is at reference.cs (at the constructor).

Then everything should work smoothly..
Hopefully :)

Tuesday, November 21, 2006

Get Date from DateTime in SQL Server 2005

Since I spent some time searching for that and I realized that it's not easy/fast to find the solution, I post it here.

SQL Server 2005 with a table that contains at least a DateTime column.
What you want to do, is to check a given date('21/11/2006') with the values of the DateTime column. The problem is that the column contains DateTime (which means Date and Time) data.

This problem could occur (occurred to me) when you implement a flight booking system. You have to save the flights with DateTime because you need the time as well, but when the user searches for flights, you need to create an sql command that checks the date entered by the user with the ones in the database, an ignore the time.

So, what I used is (almost) the sql below
string sql = "SELECT * FROM Flight where "+
"(CONVERT(char(10), DepartureTime, 103)='" + depDate + "')";

I recommend you to read the msdn article about the Convert function in order to understand what it's parameters do..

Monday, November 20, 2006

Je Vais Bien, Ne T`En Fais Pas

This is the next movie I am going to watch..

And that's only because of this..

And because it is French..

Sunday, November 19, 2006

html pre tag

As I was trying to create the previous post, I had a small problem. I couldn't copy-paste the code from Visual Studio to the blogger and keep the formating. The problem is that html do not keep the whitespaces, which are very important to make source code legible.

So, what I did, is that I copy-pasted the code, and wrapped it with a pre tag.
What pre tag does, is forcing the browser to preserve the format of your text.
A nice example and definition could be found here, and at the html source code of my previous post :)

Saturday, November 18, 2006

A simple algorithm

After Lipis's comment on my previous post about the words with shuffled letters, I thought it might be nice to post a simple algorithm for that.

The C# method below takes as argument a string and returns a string that contains the same letters but only the first and the last are guaranteed to be at the right position.

private string shuffle(string word)
Random rnd = new Random();
int index;
string temp = "";

int loop = word.Length - 1;

//loop the word without the first and last letters.
for (int i = 1; i < loop; i++)
//get an int from 1..word.Length-1.
index = rnd.Next(1,word.Length-1);

//add the char at this index to the temp.
temp = temp + word[index];

//delete the char at this index from word.
word = word.Remove(index, 1);

return word[0] + temp + word[word.Length-1];

With the definition I gave, this method is almost correct.
There are some known bugs but I didn't want to make the code difficult to grasp.
Now that the code is easy to understand, I can talk about the bugs and the solutions.

1. If the word is only a letter (such as 'a'), the method returns this letter twice.
The solution is to check the length of the word given. So after initializing loop variable, write:
if (loop == 0) return word;

2. There is a possibility that the word returned is the same with the one given.
As the length of the word increases, this possibility becomes smaller. But for 4-letter words, it's 50%. What one could do, is to check if the word about to return, is the same with the one provided, and loop until they are different.

Friday, November 17, 2006


I couldn't find if this was really a product of a research, but still, I find it quite interesting..

"Aoccdrnig to a rscheearch at an Elingsh uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and the lsat ltteers are at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit any porbelm. Tihs is bcuseae we do not raed ervey lteter by it slef but the wrod as a wlohe."

It's already very famous as I realized..
Some info could be found here.

Wednesday, November 15, 2006

I found out my problem

After talking with some friends and listening to the opinions of some people, I found what my problem is.

* I talk too much. Others get bored, others get lost, others think it's too deep, others think it's self-explanatory. The point is that I talk too much..

* I don't have a standard way/level of talking. I am trying to say something in simple words, and suddently I get excited and go deeper. Some other times I talk more professionally, and once in a while I start explaining in simple words, which might result in some of the above.

So, let's try a new approach..
I will be as short as possible..

Visual Studio 2005 Rockz!!
-- Great intellisense, Great debugging information..
-- And much more.. But if I start, nobody will follow :(

Tuesday, November 14, 2006

Should I change topic?

Thanks to Google Analytics I saw that there were many people that visited my blog yesterday. Then I checked at the comments and I realized that maybe they all had the same comment as Nikos: "Nice things, but I don't understand them"..

Maybe I am not very good in describing..
One problem is that I don't know how deep I should go and how much explanation on what I am saying I should give.
Another problem is that I am starting to be convinced that I am not very good in describing(maybe because of the first problem).

So, should I start talking about something else? I think I have made about 7-8 posts about programming and projects and most of the comments were something like "nice, but I don't understand"..

Maybe I can start writing about god. It seems more easy to grasp and discuss about it..

So, I don't believe in god.
There is no reason for god to exist. Reasons such as "how we were born/came to earth/evolve" can be answered by science.
I don't believe in miracles. They can or will be answered by science(and that goes to all miracles such as "I clinically dead and doctors said that only a miracle could save me, and suddenly I was alive!").
I believe in free will. If god knows everything, then he knows what we are going to do, so we don't have a free will.. That goes against what I believe for free will, so I don't believe in god(at least he shouldn't know everything:D)

I guess I will go back to computer science now.. I cried enough :)

Sunday, November 12, 2006

Merge vs Hashing

Last semester I did search engine project. That included the implementation of a search engine and a report where I had to do some theoretical analysis of the problem and describe my methodology and implementation. My previous post about this project could be found here.

I went to the exam and I got about 8(with base 5 and maximum 10). I didn't like the grade and the external examiner wanted to defend his opinion. So, he told me why I didn't get a higher grade. Let me explain the problem first.

Suppose that we have two sorted tables with integer values. At one part of the implementation I had to write an algorithm to find all the common integers at the two tables.

What I did, was something like the implementation of Merge algorithm. That algorithm is used in Merge sort in order to take two sorted tables and combine(merge) them into one, that will still be sorted. The complexity of this algorithm is O(n), where n is the total number of the elements(the sum of the lengths of the 2 tables).

What he said that I should have done in order to make it faster, is to use hash tables. What he suggested was that I can use hash tables instead of arrays, then check which one is the smaller, then take it's elements one by one and check if they exist at the other table. That will result at maximum half "operations" comparing to the Merge algorithm, because it will check only the n/2 elements and each check can be done in O(1) since we use Hash tables. The complexity in terms of big O notation is still O(n), but if we want to be a bit more precisely, we could say O(n/2).

Unfortunately for me, I didn't know much about branch predictions at that time and I couldn't defend my algorithm, which seems slower at first glance. But since they are both linear complexity algorithms, one could go more into comparisons.

Now, at my thesis, I am working again with these, and I can show by experiments and by theory based on branch predictions that my algorithm was faster. The cpu's architecture benefits predicable loops instead of accessing random blocks at the memory.

Below I have a graph of the results of some of my experiments.
The first raw of the table is the number of elements at each table(1.000,2.000..)
The numbers in the table is the time in milliseconds that each algorithm spent to find the amount of common elements.

Monday, November 06, 2006

Shivaree - I Close My Eyes

Το video clip το έχω δει πάνω από 7 φορές και κάθε φορά ανατρίχιαζα..
Τι να πω;
Φωνάρα! Στίχοι που σε αγγίζουν.. Βλέμμα που μιλάει μόνο του.. Τέλεια συνδεδεμένη μουσική..

I'll dream of ways to keep you occupied
So I can lock you up we'll call it classified
So right
You're mine tonight love when I close my eyes.

Saturday, November 04, 2006

Multiple booking

The project that I am working with at the moment is a flight booking system that could allow the user to book many seats at once. That means that the user should be able to select the flight and the number of seats that he wants to book, book these seats, and then start filling the details of the passengers one after the other.

The obvious problem is that if you don't lock some tables somehow, it is possible that while the user fills in the details, another user could book his seats, and that could cause that there are no more seats available even though the user has entered his information and thinks that he booked..

The table that are used here are [ Passsenger, Flight, Booking ]
Where obliviously Passenger has the details of the passengers, Flight has the details of the flights and Booking has the PassengerID and FlightID to uniquely identify a booking.

The only "nice" solution that I found is the following.
When the user presses the button to book( s seats at f flight), I create s Passengers with only temp data(actually only firstname='temp'). Then I create s Bookings of these Passengers. Then the data layer returns a List that contains the newly created PassengerIDs and BookingID. This list will be used to fill in the data of the passengers and some more data about the booking(delivery address, meal choices etc)

Do you have any better solution?
Mine is working, but I don't like it a lot. I need to access the database many times and that costs when we are talking about a web application. However, I think that you have to access the database at least twice if you want to do something like that since you want to book in advance and fill in the data later.

I am working with aspx and c# with .Net Visual Studio 2005 and SQL Server 2005.

Friday, November 03, 2006

FireFox 2 (updated)

I like FireFox 2.

There are many many improvements and new features in Firefox 2.
The official website describes them better than I could possibly do :)

The only (but important for me) thing that I didn't like, is that opening many tabs would cause a scroll bar to appear to "help" me navigate thought tabs. That will result in preventing me from having an overview of my tabs.

Since most web pages have an icon(logo) that appear on the tab, even with very small tabs you can see where is what you are looking for(from your own reading history). Furthermore, with the old version you could know how many tabs you have opened(how much more you have to read :D)

For these two reasons, I thought it was worthy to spend some time trying to find how to switch to the 1.5 view of the tabs(without tab scrolling). And I found it.
Maybe you agree with me and you also want to do the same, so, here is how you can do it.

To disable tabs scrolling do:
- Enter "about:config" in the url bar and press enter
- Type at the filter "tabm"(the only result should be "browser.tabs.tabMinWidth")
- Double click on it and change the value from "100" to "0"
- Restart Firefox


You will need the above only if you open more than (screen width / 100) tabs..
And that's because the default width for each tab is obviously 100.
And what I like very much, is that you can "undo close tab", which is REALLY good if you are a person like me (you open a lot of tabs and close them before the information of the tab is sent from your eyes to your brain :D )