Saturday, February 23, 2008

Macedonia - It's All In The Name

The Macedonia naming dispute has been around for almost 15 years now. It is currently in top international news thanks to another 'diplomacy magician', Mr Matthew Nimic (or Matthew Nimitz if you prefer), again re-proposing a menu of composite names for FYROM, from which we should select one (like a multiple choice). It is a battle that Greece lost some years ago but still keeps haunting its public affairs.

To begin with, the problem has two players: Greece on the one side and on the other side the-how-should-I-call-it, former Yugoslavian Republic Of Macedonia(FYROM). The problem is really complex and lies not only in the naming of FYROM, but also in the historical distortions and nationalist allegations it might yield. It is so important that is alive for some decades now and has triggered significant political events in both countries.

I am from Greece and it is a dispute I have lived with, throughout my entire life. I can still remember the ridiculous rallies that as a student I was engaged in (at the age of 9 or 10) during which we kept saying to ourselves: "Hell yeah, Macedonia is Greek!" and then went to our homes being sure we had done our job. In the meanwhile, Greek diplomacy was losing the one battle after the other and now we are engaged in talks of the so-called "composite naming". In other words, the naming dispute is a battle we have already lost. But let's take things from the beginning.

The whole buzz started in 1991. Tito's Yugoslavia is being teared apart and a new nation arises claiming to be the "Republic Of Macedonia". Kiro Gligorov is FYROM's Prime Minister and Costas Mitsotakis is Greece's. EU is using the name 'Macedonia' to which Greece objects and the dispute has just been born. In April 1992, Mr. Pineiro, Minister of Foreign Affairs of Portugal attempts to solve the problem, by suggesting the name 'New Macedonia', Greece says 'Yeah right' and a fierce political warfare begins. In the key UN General Assembly of 1993 FYROM enters United Nations with the provisional reference "former Yugoslav Republic Of Macedonia" hence FYROM. Both terms here are important. Provisional means that this is temporary situation and reference means that FYROM is not the name of the state. UN washed its hands and said that the name was an issue to be resolved. China is the first to recognize FYROM as 'Republic Of Macedonia'. In the course of 1993 and 1994 all EU countries and USA, Japan and Russia also do the same, resulting in the loss of the naming battle. Greek diplomacy had tragically failed leading to political instability and the eventual fall of the government in October 1993. Whatever followed was just talks and talks, without any substantial political importance. The course had been drawn in 1993.

However, a key-development in the dispute was the 'Intermediate Agreement' in New York,1995. Greece lifted the economic embargo on FYROM that Andreas Papandreou had imposed as soon he had been elected Prime Minister and FYROM, on the other hand, abandoned a whole series of ridiculous actions: Using the Vergina Star (Ancient Macedonian symbol) as the national flag, correcting their constitution that was referring to 'Macedonian people and their rights in adjacent countries' and many other nonsense. While all other issues were solved the naming dispute was not, and it was agreed that the two countries should do that under the auspices of UN. In the agreement, Greece agreed not to refrain FYROM from entering international organizations, provided that it would enter with the name FYROM.

Now the news is that, our neighbor wishes to enter the NATO alliance while Greece says it will not agree and will impose a veto on FYROM's bid, if the naming dispute is not resolved beforehand. One of the criterions for entering NATO is 'good behavior and relationships whith neighbors' , which is Greece's front line of defense. This also is not in contradiction with the New York Intermediate Agreement, since this was an out-of-NATO agreement and hence does not affect in-NATO affairs.

Whatever might happen, today almost 123 countries have recognized FYROM as 'Republic Of Macedonia'. For the most of the foreigners, it is hard to understand the significance of this dispute. Anyone should be free to choose the name he desires, right? If people leaving in Skopje want to use the name 'Macedonia' for self-definition, so be it, right? Well yes, as long as this does not hurt anyone, this is true. For Greeks, Macedonia is a part of the land's history to be proud of. I will not try to give proofs that Macedonia is closely tied to Greek history. It was just another city-state like Athens or Sparta hence it is absolutely ridiculous to try to give any historical proof that Macedonia is Greek. For me it is.

As a little boy, I couldn't understand why this should even be a 'dispute'. It seemed to me that it was so easy to prove that Macedonia was Greek (Macedonians were speaking the Greek language, they lived in the area of Vergina which is a Greek town blah blah..) that it should not be an issue in the first place.

Well, now I know to some extent of course, that international diplomacy works otherwise. Some countries simply do not care about history but about business. For example, China.Who cares in China about the Macedonia dispute? The quickly recognized it (I am sure they didn't even have to look at the name) and started making business with the new country (FYROM was the usual entrance of Chinese products to the European market) Some on the other hand, follow USA which generally is busy creating problems in the Balkans area and carefully maintains a hot-spot inside Europe's heart by promoting Albans allegations (support of Albans during Serbia's civil wars then NATO bombings then support of Kosovo's independence, seems to me as a nice strategic plan)

However we are not cry-babies nor do we wish spending our lives correcting anyone who uses the term 'Macedonia' instead of FYROM. After all, our economic relations have flourished , proving once again that economy players live in their own world. Despite all the political heat and the tension between the two countries, the volume of our financial transactions has been up 1500% from 1995 to 2006 (50 million $ in 1995 and 800 million $ in 2006) Imagine what will happen if we start franchising other ancient Greek names. Then our economy will skyrocket!

In summary my view is this: I look with sympathy our neighbor that is trying to find an identity to be proud of. However, the distortion that this causes is much more significant. People might connect the term 'Macedonia', 'Alexander The Great' and others with a territory that had nothing to do with Ancient and Modern Macedonia but also more importantly with people that have a negative DNA match with Ancient Greece. If this sounds nationalist so be it. I will keep on spending my time for this cause nonetheless. And we will keep on editing ridiculous Wikipedia articles like this one about FYROM:
"Over the centuries the territory which today forms the Republic of Macedonia was ruled by a number of different states and former empires, but Macedonian blood has always run in the genes of the Macedonians living in this region."

How ridiculous does this sound?? If anyone wishes to play on blood terms he can try understanding this:
"Αλέξανδρος Φιλίππου και οι Έλληνες πλην Λακεδαιμονίων"

That's all Greek to you? I am sure it is.


P.S - Not important since it has historical truths
To be serious it is all in the name: Macedonian comes from the Greek "μακεδνός" (makednos) meaning someone which is tall. Greek Macedonians are generally tall people compared to the 1.65 average of the other 'edition'

Sunday, February 17, 2008

Gmail: How Slow Can We Go?

Today, I received a call from a friend asking me if I got the e-mail she had wrote a half an hour earlier to my Gmail account. I said no, and assumed that she had sent it to a wrong address.

However, 3-4 hours later, I received the mail we were talking about and became suspicious after remembering some other similar incidents in which I had suspected delivery delays from Gmail. I made a quick search and found out that this is a 'hot' subject recently, both in blogs and discussion groups. For example this Gizmodo post from Feb 2008 or this recent article, raise the exact same question and the users ' feedback indicates that there is actually a Gmail delivery problem.

I only hope that it is Google to blame and not anybody else..(who said NSA?)

Wednesday, February 13, 2008

How To Download YouTube Videos with PHP

[Update #1: In a next post you can find the full Youtube Download PHP scripts. However browsing through this article will help you understand the technique hidden in the source code. your choice!]

As everybody else I suppose, I have used some software but also sites to download YouTube videos. I used to made a wrapper software that used this techcrunch tool. There is a vast collection of tools available that could do the job as easily as this. However, there is some time now (1 or 2 months) that all these have...stopped working. You can see for yourself. Try searching for 'youtube video download tool' and roam on the results for a while. You will find out that the vast majority of these sites are basically 'out-of-service'. Perhaps because of legal issues.

Anyway, to hell with 'cloud computing', I said, and decided to write my own code for downloading videos from YouTube. You may have noticed a small iframe in the right bottom corner of the blog with the name 'DOL Gadgets' (under the categories section). It basically hosts some PHP code that runs in my machine and can provide download links for YouTube videos. Regardless, the language you use to write the code, one has to overcome a small problem. The initial YouTube video link does not contain explicitly a link where the video actually is hosted. So, there are some small tricks you have to employ.

First thing is to discover how your browser finds the content to play. As an example let's say you click on the Eric Prydz's Armed video with the URL being:
http://www.youtube.com/watch?v=T0XIMkuo81Q

In Firefox, I used the Live Http Headers add-on to make a little spying. Using this tool we can watch in real time the http communication that is going on while you are browsing (GET/POST requests, responses, headers etc) The first thing to notice is that the browser finally makes a request like this:
GET /get_video?video_id=T0XIMkuo81Q&t=OEgsToPDskJW2DY1pibC1Tu7D7tVOZrE
If you put it directly into the browser this will open a Save File Dialog for you to download it. Saving the file with an flv extension finishes our job. But to create a request like this?

There are 2 parameters in this: the video_id and t. The first is what you already know from the initial URL. The latter, which I tend to call it ticket, is not available but somehow the browser locates it (or the player). So the plan is clear: get the video_id from the initial URL and then try to find the ticket.

Let's begin from the harder one. Since there is no other alternative the ticket should be communicated in the initial request or some subsequent. Opening the source of the page that is returned from the initial video URL we can find that the ticket is actually there. To get the video_id we simply process the initial URL. Now we are done. The scenario is complete:

1. Get the page returned from the initial URL
2. Retrieve the ticket from this page
2. Retrieve the video_id from the initial URL
4. Create the GET request using the video_id and the ticket

This is exactly what the PHP code does. (Excuse me for the poor PHP syntax and coding, but I am far from being comfortable with the language) If $location has the initial URL then :

To execute step 1. we can use the following PHP snippet:
$handle = fopen($location, "r");
if($handle) {
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192); }

fclose($handle);
With this, we read the stream to the variable $contents which now has the YouTube landing page.

To execute step 2.
$result1 = preg_match("/&t=([\w]*)&/",$contents,$tickets);
$ticket = $tickets[1];
The preg_match is a regular expression matching function in PHP. Basically we match a pattern that can extract the ticket against the YouTube page. It returns true when there is a match and the matched groups (if any) are returned in the $tickets. After this snippet the $ticket variable has the needed string to construct the GET request.

To execute step 3.
$result2 = preg_match("/v=(\w*)/",$location,$video_id);
$id = $video_id[1];
The same reasoning holds here. $id has the video id(first parameter)

To create the GET request and execute the last step we can use the php snippet
echo "<"; echo "a href = \"http://www.youtube.com/get_video?video_id="; echo $id; echo "&t="; echo $ticket; echo "\"Download link.";
This creates a hyperlink that when followed prompts to download the video file.

That's all! One networking function, two simple regular expressions and ...done, we have a YouTube video downloading on our PC. Now, it is easy to expand the service. In subsequent posts, I will try to give code for the Javascript version, but also other enhancements like entering the video name rather than the video UR etc. Till then, feel free to use the tool in the blog site or adjust the code to your needs.

Tuesday, February 12, 2008

Let's Celebrate For A Little - 1K Visitors!

This is a special day for the Developer On Line-DOL- blog. Today the number of unique visitors on this blog reached more or less the astronomical amount of 1024! Before making a little fun a sincere thanks to everybody that has visited this page and specially to anybody that is subscribed on the blog's feeds. Now I think it is time to introduce better, but in short, the story behind this blog and prove why it should keep ...existing!

It started in early September with the first 'Hello World' post. Initially I planned to keep it strictly technical but it is not easy to resist broadening the subjects (sticking your nose everywhere is the right expression!). One thing I have kept is the blog being ad-free and I plan to keep it that way. It is nice to have a clean place for me to write and for you to read.

Trying to post original material is also in the 'routine'. The book stacking problem post is a good example on that. I won't say that everything here is 100% 'cotton' (this is your job!) but I confess having canceled posts that I found that had nothing new to add compared to other web sites. There is no meaning in reposting news, or republishing articles or code that is already there and is freely accessible.

Despite being around for almost 6 months, it is true that I have not been so productive. There are a total of 20 posts in this period that equal to less than 1 post per week. DOL promises to intensify the posting process and has already masterminded and executed the perfect business plan for that. I only have to wait for today's lottery and these six numbers to come up and I will be devoted in this blog for the rest of my life...!

Some statistics now. You may have noticed that this blog is using Google Analytics to measure blog traffic. It is an easy and nice way to keep track of how people find our page and how they navigate inside it. By understanding how people get to your page, you can increase blog traffic and although I do not earn money from this, it helps me in asserting the quality of the content. Here is some statistics of the countries that have visited this blog. US and Greece stands out, much ahead than other countries(UK, India etc) The main sources come from search engines in which DOL generally ranks pretty well.
DOL visitors in six months


Once again, thanks to everybody.

IMPORTANT:
PS. Now that DOL has this enormous influence, it officially endorses Barack Obama for President of the US!

If he loses, DOL invites him to Greece; we urgently need a Prime Minister and we desperately need change...

Sunday, February 10, 2008

Bidding In The Name Of...

One of the most important 'events' worldwide in mobile communications is the currently open FCC auction for the 700Mhz band or Auction 73 in short. It started in January 24th and among things that make it interesting, is the diversity in the participants' list. While participants and bidders will not be known until the auction finishes, some of them have already expressed publicly their interest in the auction, the most interesting being Google Inc.

The band auctioned off covers the spectrum from 700MHz to 800MHz and is one of the last bands that are of interest to wireless communication carriers due to its physical properties (ability to penetrate walls, buildings etc) The spectrum in auction is divided into 5 zones, names as A,B,C,D and E blocks legally divided into 1000+ licenses. The Holy Grail seems to be the C block, since it is the largest 'strip' (of total 22Mhz, almost double than any other block in auction), it is the least segmented (total of 12 regional licenses among 1099 licenses) and also the best suitable for building wireless networks.

Google has decided to enter the mobile market. This has been obvious for a long time now, since basically it is easy to notice how carefully the company launches the mobile version of its services (search and mail were always available for mobile phones)The company also has much interest in collaborating with different vendors and platforms. For example, the iPhone was the first to host the mobile Ajax version of Google mobile services: Search, News, Blog, GMail and others.

However, above all comes the Google mobile platform currently under development: Android. The platform basically tries to bring the Open Source culture on mobiles. First, it is a Linux based platform (or according to Symbian's CEO Yet Another Linux Platform!) Second, it is free to vendors that choose Android to build their phones on. On the road its adoption from the industry, Android will have to face multiple challenges: a segmented market with many big players (Symbian, Micosoft, Sun,Apple) but also a different world where mobile wireless carriers are the dominant players.

It isn't clear however, if Google wants to own the band, to use it for building wireless networks to host the Android and gPhones or just to assure open access to these networks. The latter was very clear from the beginning and it is speculated that Google was the 4.7 billion $ bidder that guarantees that whoever wins the C block will provide with an open-access network.

If Google wants to take it further it will have to play against big names, the most motivated being Verizon Wireless. But this is not all. There is a hundred other participants in auction 73, among them, AT&T, CableVision and EchoStar (to provide with wireless services) and even Chevron corporation, maybe interested in creating a network among different company departments.

Recently the auction for the C block took a wild turn. In February 5th it was the first time when nationwide bidding was under the aggregate of the 12 regional biddings. As a result, the block might be segmented into different winners, leading possibly to a Babel of incompatibilities that will make it useless. As an antidote bidders should win every region or agree later on an open and free network. It is a commonly expressed opinion that if Google wins the auction, we will witness big changes in the way which the mobile industry works. Taking into consideration the open nature of Google's Android platform this is not science fiction, however reality is much harder for Google. With its recent moves the company has caused a lot of frustration, even to traditional allies like Sun or Apple, for different reasons to each. Android is also problematic (see here for example) and has not yet convinced mobile developers that it is the revolution it preaches to be.

No industry analyst makes better predictions than time, so we will have to wait for a clear view. Until the auction finishes anything else (including this post) is speculation..!

Tuesday, February 5, 2008

Google Interviews Part IV

This is the 3rd interview I had with Google. You can find the previous and the questions asked here:
* First Google interview
* Second interview

Update: Fourth Google Interview

In the 3rd interview I talked with a woman software engineer from Mountain View. As usually it lasted for about 45 minutes but there was a surprise waiting at the last question..But let's take things from the beginning.

The first question was a hard test for my memory: "How do you test your code?" This is a fair one for software engineers. But not for my style. I personally like things that are quick and dirty. For larger projects I use some of my own class libraries that employ some kind of logging, measure method execution time and so on. But saying "Well, I use my own class libraries." I thought would not be a good answer. Nor a professional one.

So talking about Java, I made the mistake of mentioning the JUnit framework. I had used for some time (long ago) but the time had passed so I had forgotten even the basics. And of course the interviewer started the questions (How the JUnit handles exception and others) To tell you a secret I had already opened in my browser a JUnit site (some kind of tutorial I guess) but this didn't help at all. So, don't do it. It will only make things worse. Trying to think logically didn't help either. The interviewer kept pushing, until I 'broke' and admitted that I couldn't answer. That was it. We moved to the next question.

All next questions were really typical, the kind you find in tech interview sites:
* "What is a Unix kernel?"
* "What is the difference between interfaces and abstractt classes?"
* "What is the difference between threads and processes?"
* "What is inheritance, polymorphism and encapsulation?"
* "What is overriding and what is overloading?"

I think there is no need to elaborate further on that. You most probably have come across these concepts and have your own mind.

Which brings us to the last question. Actually it was a puzzle including programming with handicaps, i.e. with small processor, low memory etc. The puzzle was this:
"You have 1000 integers. All are less than 1000 and greater or equal to 1. Among them, 999 are distinct and there is one that is found twice. How can you find the duplicate?" To this I gave an answer I think is optimal. The idea is simple. If you denote the duplicate number by d and the sum of all the integers by S then the following equation holds:
S-d= 499500 since S-d is the sum 1+2+3...+999 which is equal to 499500 by applying the formula 1+2+3...+n = n*(n+1)/2
Now the good thing is that we can be able to find the duplicate even we have capacity for one integer, or when reading from a stream and so on. We can optimize even if we apply modulus to the first equation: d = (S-500) (mod 1000) Now if d is equal to a positive number mod1000 then this is the duplicate, otherwise the duplicate is the negative part plus 1000. For example is 1 was the duplicate, then d=1(mod 1000) and the duplicate had to be the 1. If the duplicate was 600, then d=-400(mod 1000) so the duplicate had to be -400+1000=600. This means we do not need to have storage for integer (int type) but only the byte type is enough.

While fairly easy to grasp the interviewer had difficulties in understanding how this would work, so she asked for an example when we have 10 integers. I replied this would transform the equation to d =S-45 but then the counter question was disappointing: "How did you compute 45?" It is quite obvious however that I had to compute 1+2...+9 which is equal to 45 when applying the formula that Gauss found when he was 8. But the interviewer started computed 'by hand' the sum, adding the numbers from 1 up to 9, which left me speechless for some seconds. I mentioned that there was a formula for that but she didn't listen, still being concentrating on her computations. I didn't bother elaborating on the modulus idea since obviously would not give me any more credit.

After that, the interview had finished. I didn't ask anything, saying something like 'I have many questions but I do not wish to spend any more of your time' and we ended the conversation. In overall the last incident was really awkward. To that time I believed that all Google engineers had a good mathematical background. The engineer that I spoke with, did lack elementary skills. So in my eyes, the myth had been destroyed and it is a good advice to anybody, not bother berating himself more than he should. If you already knew the formula for the sum of consecutive integers, you have a good reason to feel more confident.

Update: Go to the last Google phone interview