Monday, April 30, 2012

Google geocoder API without hitting the rate-limit?


While developing my new application which uses reverse geocoding from Google Maps API v3, I came across the problem of rate-limiting the queries. Google happily returns "OVER_QUERY_LIMIT" instead of the result if you fire the requests rapidly. Sadly, the API does not solve this (which is quite stupid as the people must come up with workarounds). Anyway, here is a simple rate-limiter which should work in most cases, just replace

var geocoderService = new google.maps.Geocoder();
with

var geocoderService = {
    geocoder : new google.maps.Geocoder(),
    queue : [],
    delay: 2000, // in milliseconds
    timer: null,
    geocode: function(request, callback) {
        this.queue.push([request, callback]);
        if (this.timer == null) {
            this.timer = setInterval(this.processQueue.bind(this), this.delay);
        }
    },
    processQueue: function() {
        if (this.queue.length > 0) {
            var data = this.queue.splice(0, 1)[0];
            var request = data[0];                                                                                                              
            var callback = data[1];
            this.geocoder.geocode(request, callback);
        } else {
            clearInterval(this.timer);
            this.timer = null;
        }
    },
};

Wednesday, April 25, 2012

Javascript is an exception...

Javascript is an exception ... from any reasonable exception handling. The general construct is

try {
  code_throwing_exceptions();
} catch (e) {
  do_something_with_exception(e);
}

Which seems reasonable. But ... how to catch different exceptions? Well ... it seems that there is only one way and that is manual if-s:


try {
  code_throwing_exceptions();
} catch (e) {
  if (e instanceof RangeError) {
    alert('out of bounds');
  } else if (e instanceof TypeError) {
    alert('type problem!');
  } else {
    raise e;
  }
}

Monday, April 23, 2012

The pleasure of flying

Today I had a pleasure of my first flight to US. And I must say I really enjoyed all the procedures. For example, the questions at Zurich Airport -- I met a very senile lady. She asked me several questions twice, without apparently registering the fact. Maybe I should have tried to answer two different things -- just to cross check if she was at least listening to the answers.

But the jewel of jewels is the Philadelphia Airport. It took me more than two hours to get from the first plane to the gate for the connecting flight. And I do not understand why. I mean, clearly there is some concept of the parallelism. But why the hell they are not using the full power of it? At least half of the stands in both immigration and security checkpoints were closed. Not to mention that I was directed to really slow and really long lane. At the securoty checkpoint, I was directed to get off my shoes. I really hated it. Not the process taking the shoes off but the missed opportunity -- I would enjoy so much taking off my hiking shoes after full one day trip. But because I put off my shoes on the plane, my feet weren't smelly so there was nothing to enjoy too much.

Anyway, let us continue with the story. The connecting flight was scheduled on 4pm. But it would not be fun if the flight was not delayed. For example one hour due to the weather at San Francisco. Oh, did I tell you one hour. Noo, that was really naive from them. The current "departure forecast" is 7:30. And I already dropped of my luggage with what -- with the us power adaptor. So I even cannot use the computer all that time :-(

Friday, April 13, 2012

The war between updates and restart is over :-(

On Thursday night the long-lasting (more than 200 days) war between my machine updates and system reboot ended with the result of my desktop computer dead. Be the god good to the old kernel. It must have been a quick and sudden death. The computer died by a treachery -- it was stabbed right from the back:

Dear Sir or Madam,

This night, between 2 and 3 am, a blackout hit parts of western Lausanne, including our school, following a problem on the network 220/125 kV.

Our intervention team is hard working, and has gradually been able to restore the situation and reset of a number of alarms. However, if you should notice any defect whatsoever, please contact the CPC to 34000.


We apologize for the inconvenience well beyond our control and we thank you for your understanding and cooperation.
Yours sincerely
DII-Exploitation

iGrec


Apple France prĂ©sente 
"Y"
(also known as iGrec)

Submitted!

Finally we submitted our paper to the HotSDN workshop. Frankly speaking, I do not want to see that paper again (after seeing and reading it so many times during previous week). But realistically speaking, I will have to see it again. At least when the reviews will come. And optimistically speaking, these reviews won't be all-negative so that there will be a sense in seeing it again. So, let us hope for the best!

Tuesday, April 3, 2012

Easter -- who said it should be a holiday?

There are just a few things that can increase my mood more than declaring Easter a working week!

-----Original Message-----
Sent: 03 April 2012 04:38
To: hotsdn@lists.noise.gatech.edu
Subject: [HotSDN] HotSDN submission deadline extension to Tuesday April 10 at 11:59pm GMT

Hi folks,

In response to several requests, we're extending Friday's submission deadline for the HotSDN workshop to

 Tuesday April 10 at 11:59pm GMT

Please mention this to your contacts -- we'll also update the SIGCOMM Web pages accordingly, and have already updated HotCRP.

-- Jen