Sunday, 22 March 2020

The Man with the Iron Heart

Last week I watched this excellent historic film about one of the most notorious monsters of the last century, Reinhard Heydrich, and the heroes that sacrificed their lives to eliminate him.

In these times of fear, uncertainty, horror (the images of the queue of military trucks carrying coffins in Bergamo has shocked me) it's good to remember the last time when Europe was drowning in horror, and how in the end it managed to overcome it. It's been a long time since me reading anything about the WWII, and I had started to forget some things, so this film serves also as a fast reminder of several essential moments and actors: The Night of the Long Knives, the Einsatzgruppen, the Wannsee Conference...

In my first visit to Prague and its amazing castle (in 2005) I did not know that one of the most brutal Nazi leaders had set office there. In my second time in 2010 I was already aware of it, and walking along the beautiful courts of that castle gave me some of an odd feeling. This visit coincided with the volcanic eruption that closed the European airspace for several days, so Prague was unusually empty, and this increased the bizarre feeling. 10 years ago some volcanic ashes made us feel as if our world was collapsing because we could not fly for a few days, now a fucking virus prevents us from leaving home and brutally reminds us of how absolutely fragile and uncertain everything is.

Tuesday, 10 March 2020

The New Poor

I've recently watched Les nouveaux pauvres : Quand travailler ne suffit plus/The new poor: when working is not enough. An interesting documentary about something well known (I've watched some other French documentaries on the same topic), poverty in Europe is not only suffered by those that can not find a job, but also by those that have a work that does not pay enough. Of course this is a "soft-poverty", these people are not homeless and do not starve, but they strive to manage to pay their rental and get decent food and clothing, and have to renounce to many small things that make life worth. Furthermore, they live in a constant state of insecurity and stress, not sure about whether the next month they'll have yet that source of income or things will get much worse. This population subject to this constant insecurity, precariousnes, is called the precariat.

The part that shocked me the most is the story of the Swedish retired woman striving to make ends meet. I was already aware of how retirement days can be rather far from being a golden age in some "advanced" countries:

  • In Spain retired people with a very low income are usually either self-employed workers (that are the absolute parias of Spanish social system) or people that did not manage to work for at least 20-25 years (if less that 15 years you are not entitled to a normal pension, but you are supposed to get access, under certain circumstances, to a very, very basic "social pension"). Otherwise Spanish retirement pensions are, as far as I can see around, pretty fair.
  • Regarding France, I'm aware of farmers that after a whole life of very hard work, all they can get is a 1000 euros retirement!
  • As for Germany, I watched a documentary some time ago where they explained how those old people picking up used glass bottles on the street (this has become a part of the German urban landscape) are usually people with a low retirement that need extra money to make things work. Similar things happen in Israel, where old people need to continue to pick up jobs after the official retirement age.

But the case of the Swedish woman shown in the documentary really caught me by surprise. This woman worked most of her life (as a social worker precisely), raising her child as a single mother (for that she stopped working for a couple of years, which seemed to hurt badly her retirement rights), and now she has a 1000 euros retirement (that's not bad in Spain, but we're talking about Sweden!). She is entitled to renting a social flat, but well, life in Sweden is not cheap, so that still means paying 600 euros for that rental... so not much left for the month. She is also entitled to having lunch for a "cheap" price in a restaurant managed by social services (the same social services where she worked most of her life), so well, she gets by... but that's far from the life quality that you would expect for someone in the Scandinavian paradise...

What infuriates me more is that I'm pretty much aware of the enormous amounts of money spent by the Swedish social system in recent migrants. I continue to don't give a shit about someone's skin color or place of birth, but I think there are things that should give you higher entitlement to receive help from the Social System. Having contributed with your taxes to that System: you, your parents, your grandparents... or in a broader sense, having contributed to that society, make you part of it, and it's more than fair that you receive from it. However, a person freshly arrived is a new citizen that has not given anything yet to that society, so it's for sure good and necessary (of course I'm talking about immigrants willing to assimilate) that this society helps you, I call it solidarity, but I honestly think that the "old" citizen should have some privileges over you, I call it fairness.

Sunday, 23 February 2020

The Art of Dying

I'm a big fan of Spanish cinema. This has nothing to do with what my passport says or my feelings of identity (these feelings have changed over the last decade, but my high consideration for Spanish cinema remains the same). Spanish Dramas or Social films are well known, but there are also many pretty good terror films (and thrillers, crime, even film noir). I've recently watched for a second time (the first time was around 12 years ago) a quite unknown piece, El Arte de Morir/The Art of Dying. I remember how much I enjoyed it the first time, and this second time the experience has been similar.

The aesthetics are pretty nice (of course I very much appreciate the references to El Bosco), the pace and the story are good and the acting of Fele Martinez (this guy will always have my huge respect after his performance in Tesis) is excellent. The key element in the film that makes of this film one to be remembered for me is the concept revealed at the end, that dying can be a gradual process, same as the process of being born takes 9 months, dying could take a long time. This does not refer to how we get close to death as the time passes by and our body ages, they are talking about what happens after the moment one person is considered dead. The body has turned off for sure, but maybe it's not the same for consciousness. Maybe this awareness is not immediately switched off, it just starts to decay, it starts to lose its memories and references until the moment all of them are lost, and then the real death occurs... Well, a pretty interesting idea I think.

Sunday, 16 February 2020

Extending Async Iterables

A few months ago I did a POC about extending Iterables with chainable common functional style methods like map and filter. Doing the same for Async Iterables is really simple, it's mainly a matter of replacing the internal for-of loop in each method with a for-await-of loop, and replacing [Symbol.iterator] with [Symbol.asyncIterator]!
I've put the code in a gist, I'll paste here just one section:

class AsyncExtendedIterable{
    constructor(iterable){
        this.iterable = iterable;
    }

    
    async *[Symbol.asyncIterator](){
        for await (let it of this.iterable){
            yield it;
        }
    }


    map(fn){
        //I need to use the old "self" trick, cause we can not declare a generator with an arrow function
        //so as we are using a normal function, "this" is dynamic, so we have to trap it via "self"
        let self = this;
        async function* _map(fn){
            //printDebug("_map");
            for await (let it of self.iterable){
                //printDebug("inside _map");
                
    //we can await in a non Promise value, so if we do "yield await" rather than just "yield", we are contemplating both a sync and an async fn mapping funtion
    //yield fn(it);
    yield await fn(it);
            }
        };
        let newIterable = _map(fn);
        return new AsyncExtendedIterable(newIterable);
    }

What is really sweet is that thanks to the fact that for-await-of loops work both with normal Iterables and AsyncIterables, we can use this AsyncExtendedIterable class with Synchronous Iterables. Furthermore, once our internal _map, _filter... functions have been declared as async, we can make them work fine with an async iteratee function (the function that we pass to the map, filter methods), by just adding an await to the call. This will work fine with sync and async iteratees because we can await synchronous calls without problem (the runtime just wraps the returned synchronous result in a resolved Promise). Just check the example in the gist.

Saturday, 15 February 2020

The Wind that Shakes the Barley

I've recently watched Ken Loach's The wind that shakes the barley and it has shocked me and ashamed me. It has shocked me cause the story is so powerful, gripping and emotive, it's a real piece of art. There are few films that have made such an impression on me, I can think of Gattaca, Incendies... It has ashamed me because it has taken me 14 years to watch it, and because it has reminded me again how many essential parts of world's history remain unknown to me.

The story in the film is of particular interest these days, as due to the recent elections in Ireland and the important change in the power balance, with the Sinn Feinn winning the elections in votes, newspapers have been mentioning the Irish Independence War and the Irish Civil War, and how this latter still plays an important role in current politics, with allegiances that still today are inherited from those times. I think the Irish Civil war is a rather unknown conflict to outsiders, particularly if we compare it to the Spanish Civil War. It's normal, the Irish one was a local conflict, with a "relatively low" number of casualties, while the Spanish one had an international involvement as one initial step of the global war against fascism that would be unleashed immediately, caused the almost destruction of a society, and had as aftermath a dictatorship that oppressed Spaniards for 40 years. All this said, there's an element of brutality in the Irish conflict that I think we don't see in the Spanish one, people that months before had risked their lives together sharing common hopes and a common enemy, suddenly found themselves on different sides shooting each other...

I think an accurate word to define this film is brutal. First we have the terrible violence exerted by the British soldiers and their enormous despite for the Irish population. Then the strict treatment of the Irish revolutionaries to their traitors, and finally, the devastating part, the violence between brothers in arms (and real brothers) during the civil word between those that accepted the "partial independence" treaty with the British and those that rejected it, aiming for full independence, a reunified Ireland and a socialist state.

The films has also confronted me with how much I've changed in these years. If I had watched this film at the time of its release, I'm pretty sure the radical leftist that I was would have totally sided with the anti-treaty side, now, this "almost conservative", law abiding citizen that I am, understands pretty well the pro-treaty side.

When I travel somewhere I try to read as much as possible about the history of that place and watch some related movies, so bearing in mind that I was in Ireland for a few days in 2007, it feels really odd to me that I had not watched this film and had almost forgotten about the Irish Civil War. At that time I was really busy at work with a project that we had to have ready, so I guess I had not much time to do "my homework".

Thursday, 13 February 2020

Grands Travaux Inutiles

Some days ago I was discussing with some people about the MetroTren Asturies project. This project involves several kilometers of underground tunnel with several stops in my town, Xixón, so many people think of it as a sort of Metro. That's the main reason why there is a common perception of it being an unnecessary project for a city of this size. People have not understood that this has nothing to do with a local Metro, but with a section of a light rail system (think of Parisian RER, Berlin s-Bahn...) for the Central Asturies metropolitan area. I think this can be a really useful project and I'm rather happy that after too many years on hold due to financial problems now the project seems to have been resurrected.

This reminded me of the Charleroi Metro, also a light-rail system that was on hold for a very long time. Reading again about this work I ended up finding one really interesting wikipedia page, the list of Grands Travaux Inutiles/Big useless projects. The French language entry contains an impressive list (nothing to do with the skinny English entry), with particularly rich sections for France, Quebec, Spain (quite expected :-) and even a separate page for Belgium. Checking that list one learns about the failed Liege Metro, that with a built tunnel reused as storage space reminds me a lot of what could have been the future of the Xixon's Metro Tunnel (but as aforementioned, hopefully the project seems to have been restarted).

It's important to note that such list of "useless projects" is not exempt from subjectivity, as it does not only contain projects that were never completed or never entered into service (or never achieved any success among users), but also projects that the green-red totalitarianism has deemed unnecessary and has managed to cancel (even if the average, not far-left-far-green citizen was in favor) like the Notre Dame des Landes Airport or the Sivens reservoir.

Sunday, 26 January 2020

Proxying an Object with sync and asycn Methods

The other day came to my mind the idea of how to intercept asynchronous method calls. I'm talking about JavaScript and the typical case where we use a Proxy and a get trap to intercept all method calls to one object, running some code before and after calling the original method.

First we have to check if the intercepted method is sync or async (we'll just check if it returns a Promise). If it's async, the main issue is with the "after call" action. We have to run this extra code after the async method is completed and before the client receives this result. Well, it's just a matter of adding a .then() call to the original promise, running our code inside this "then", and returning to the client the promise created by "then" (promise that we'll resolve to the value returned by the initial promise). All in all, we can write a proxy that intercepts properly both sync and async methods in an object like this:

let proxiedObj = new Proxy(obj, {
 get: function(target, property, receiver){
  let it = target[property];
  if (typeof it !== "function"){
   return it;
  }
  return function(){
   console.log("before invoking");
   
   //we're not trapping additional calls done from this method, so we invoke the original method via "target" rather than "this"
   let result = target[property](...arguments);
   //let result = it.call(target, ...arguments);
   
   if (result instanceof Promise){
    return result.then(res => {
     console.log("after completion of async function");
     return res;
    });
   }
   else{
    console.log("after completion of sync function");
    return result;
   }
  };
 }
);

There's an interesting point. We could think of using await in the returned function rather than then(), something like this:

  //I can not do it like this, cause with the async I would be returning a Promise in both cases, so for the invoker of a sync function he gets a promise of X rathern than X, so that's not what he's expecting
   return async function(){
   //I'm not trapping additional calls done from this object
   console.log("before invoking");
   
   let result = target[property](...arguments);
   //it.call(target, ...arguments);
   
   if (result instanceof Promise){
    let resolvedResult = await result;
    console.log("after completion of async function");
    return resolvedResult;
   }
   else{
    console.log("after completion of sync function");
    return result;
   }
  };

This will work for asynchronous methods, but will break synchronous ones. As we know when a function is marked as async, the compiler modifies the function so that it returns a Promise that resolves to the value returned by the return statement. So if a client is calling a function that returns a string and we intercept it by means of the above get trap, he will receive a Promise of a string...

I've uploaded it to a gist