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

Monday, April 2, 2012

Vote for my biking performance!

Weekend after the Easter, I am finally bringing my new bike here into Switzerland. And as you know, I really like the idea of torturing myself and doing all the crazy stuff. For example biking to school.

Biking to school is considered a normal idea unless ... well unless you live in a small village near the end of the world. Or 25 kilometers away from the school. So, you can vote on what will be my first trip time (in both directions).

The planned route below. And it is not the shortest one, as you can see. I adjusted it to overlap with official biking trails (anyway, biking on a highway is not the brightest idea). The length is 31.3 kilometres and I am even giving you the height profile so you can make the most precise prediction!

So, what are you waiting for? Cast your vote on my time!



View Larger Map


Is biking green?

Nowadays, you hear a lot about "being green". And certainly biking is one of the most energy-efficient transportation [1]. But being energy efficient does not mean to be environmental-friendly, does it?

Well, there is this big problem with greenhouse gasses, like CO2. Hmm, CO2? The thing we produce during respiration? So let us estimate how greenhouse-friendly is actually biking to the work.

We need to estimate COproduction during the biking, i.e. we need the difference between CO2 production during the biking and the usual activity. Unfortunately, CO2 production of humans is not very advertised topic. But what comes out must come in. In fact, the CO2 exhalation is preceded by O2 inhalation with the same (molar) amount. Thus we just need to figure out molar amount of O2.

Now, O2 is more studied. There is a lot of sport/fitness research for maximum oxygen consumption (VO2 max). So let us do the estimate.
According to [2] the maximal VO2 for an average person is roughly  35 ml*kg-1*min-1. From [3] we get that the actual difference between rest and biking at 70% of max heart rate corresponds roughly to 25% of VO2 max.

Putting this together for my weight 70kg and time 60 minutes, it is 35 * 70 * 60 * 0.25 = cca 37 litres of oxygen. Moving back to molar amounts - 1 mol of ideal gas under room temperature corresponds to roughly 24 litres [4]. Note that oxygen is not so far from ideal gas in this scenario. This gives us roughly 1.5mol of oxygen.

According to [5] the molar mass of CO2 is 44g/mol. This yelds 66 grams of per COthe one-hour long trip. Now, what is the comparison to other means of transportation? SBB claims [6] that for the same trip, the car would produce 4.2kg of CO2 which is quite a lot. But the train under average utilization will produce only 0.18kg -- only three times as much as bike! (I guess this also includes CO2 production during electricity generation).

So what is the bottomline? Yes, the biking is green. But japanese trains are greener :-)

P.S. As a good scientist, one should always cross-check his results. Especially if the sources are just a random collection from the internet. So let us do the task. According to [1], on the flat ground a normal person expends 1.62 kJ*kg-1* km-1. For my trip of roughly 25 kilometers this is 1.62 * 70 * 25 = 2 835 kJ.
Putting 2800kJ energy inbalance into [7] gives roughly 0.63 kg per week, or roughly 90 grams per day. So, the workout should reduce weight 90 grams, we have 66 grams from CO2, where is the rest? The answer can be found in [8] -- according to the respiration equation with each mol of CO2 we also produce a mol of H2O and some energy. And using [5] again, we obtain that this corresponds to the missing 20 grams. So our results are (quite surprisingly) reliable.

[1] http://en.wikipedia.org/wiki/Bicycle_performance#Energy_efficiency].

Start of running season

After the long winter virtually doing nothing but feeding myself, going to school and writing all sorts of poetry (i.e. python, report, reviews, paper, etc.) I finally decided to once again change my life (by torturing myself). And it would not be me if I did not plan to do it on a grand scale. In fact, I got this fine idea of running ten kilometers. On a perfect plain around my village. 

As I would be bored to return the same way and designing a good cyclic route will be too much, I decided to go with the simple idea of going somewhere and returning by train.  I found a good destination - a rail station Eclepens roughly 10km away. The trains from Eclepens to Chavornay are going hourly so that should make it easy to return. Except ... well except that I was a bit slow in preparations. And it turned out that I have just 1:15 to finish my first 11.5km (by now I put the route into my gps and with the horror looked at the new projected distance) in this season.

Following the motto "start fast and then just accelerate" I started with an unusually fast pace. That said, it was just a matter of minutes until I was virtually dead -- a nice 100m ascent in woods near Bavois changed my running forecast from "speedy with light variations" into "zombie speed with pauses for breath". But you know, the trains are not supposed to wait till some stupid runner in the woods moves his ass towards the train station. Maybe with a divine intervention I managed to climb to the highest point of my journey. Afterwards it was possible to half-resume my running but I still frequently need to cache new air into my lungs and wait for heart-sync. But the overall time was promising. Not as much promising as I would like it to be but at least it was manageable. Till maybe 1 km before the Eclepens, when I had only a few remaining minutes. Suddenly, my GPS was telling me "go left". Excapt for the fact that there was no road. I briefly considered an idea of crossing through woods but ... well, it is not exactly the best idea to do it through the cliff. At least my estimate was that there is far more vertical distance than horizontal for the next 20 meters (which was roughly the distance of the shortcut on my GPS). Damn it! Stupid GPS. But verbally expressing my pleasure about Garmin's decision must be postponed. I am searching for an alternative track and I start running desperately around the obstacle in order to meet the increasingly near deadline (one feature of Swiss trains that they are quite punctual and almost never late). Fortunately, the additional distance is just few hundred meters more...

To keep it short -- I made it. One minute before the train. And with a nice muscle cramp for another 3 days.


View Larger Map