Saturday 31 March 2018

Devilman Crybaby - masterpiece or masturbation?

the Japanese Netflix poster I've watched several lackluster recent Japanese animes from Netflix and I was feeling bored and disappointed with the clichés spouted by almost every character, most of them as cardboard as they can be. So when I started with Devilman Crybaby, a very original show both from the standpoint of the manga it adapts and the animation style, I was hoping for not being bored. And I wasn't. The show is fast, jumping from scene to scene and asking the viewer to extrapolate what happened in between. The characters are complex and seldom critical of one aspect or another of society, or representing such negative treats. Violence and sex are everywhere, although they are often depicted as kinds of vices and impulses that people have to fight against. The animation style is weirdly psychedelic. So did I like it? Not really.

Even from the beginning I was off put by the animation style. It's paradoxically both artistic and very simple. It made me think of Aeon Flux (the MTV animated series), which had several other things in common with this, as well. But I didn't let it bother me and I continued watching. As I said before, the characters are complex and the story is meandering around the peculiarities of each of them, which made it interesting. However, the plot was full of holes! Things that were "revealed" later on were evident from the beginning, people acted in weird ways that were eroding the suspension of disbelief. There were fights, but simplistic in nature and more inline with the symbolism that the author was so hard on. There were substories, but kept to a bare minimum. Do you see a pattern already?

Yes, in its entirety, things that were not important to the philosophical message that the anime wanted to make were abstracted, simplified or removed altogether. It is hard to enjoy any of it after you've got the memo. Even worse, perhaps because of its heavy (handed) symbolism, all the articles and reviews online praise it as a masterpiece. I said it before and I will say it again: just because it is not the usual crap it doesn't mean it's good. There are so many sorts of crap. You read two or three of them, discussing "what they meant", and you realize they are as full of shit as the makers of the anime. If you need to explain what you meant, the joke wasn't very good!

To be less of a dick about it, the show has many redeeming qualities, that is why I can't discuss too much the particulars without spoiling it, and you might want to watch it. However, to me, those qualities were wasted in the pseudo spiritual and moral bullshit that suffused the show. One alleviating circumstance is the source material, written in the 70s, which I have not read, so I can't really compare, but it was the 70s. Weird and wonderful stuff came from back then. This is mostly just weird. And I really hated the title.

Here is the trailer:

Thursday 29 March 2018

.NET Standard gotcha: unit tests don't need to be Standard

You created a library in .NET Core and you want it to be usable for .NET Framework or Xamarin as well, so you want to turn it into a .NET Standard library. You learn that it is simple: a matter of changing the TargetFramework in the .csproj file, so you do this for all projects in the solution.

But .NET Standard is only designed for libraries, so it makes no sense to change the TargetFramework for other types of projects, including some that are in fact libraries, but are not used as such, like unit test projects.

For example if you attempt to run XUnit tests in Visual Studio you will see that the tests are discovered by Test Explorer, but when you try to run them it says "No test is available in [your project]. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.". While this is an issue with XUnit, more likely, it is also a non-issue, since your test project should use the .NET Standard libraries, not be one itself.

Wednesday 28 March 2018

ECMAScript/Typescript gotcha: Map has to be used with set/get not like a Dictionary in .NET

In ECMAScript 6 there is a Map class that looks and feels like a .NET Dictionary. As an extension of JavaScript, TypeScript code like this is totally valid:
let map:Map<number,string> = new Map<number,string>();
map[1]="Category One";
let name:string = map[1]; //name is now "Category One"

However, the code above is wrong. What this does is create a string property named "1" on the map object with a value "Category One". Its "size" is 0. The correct code would be like this:
let map:Map<number,string> = new Map<number,string>();
map.set(1,"Category One");
let name:string = map.get(1); //name is now "Category One", map.size is 1

Similar code for ECMAScript 6, you can just declare the map as let map = new Map();

Just in case you wonder why utilize this hard to use type instead of a normal object, it's a user choice. Most of the pros involve the type of the key (object keys can only be strings or symbols) and ease of counting and iterating, but these issues can be solved trivially in code, if ever needed.

Monday 26 March 2018

Proxima (Proxima #1), by Stephen Baxter

Book cover Proxima is the first book in the Proxima duology, by Stephen Baxter. And it is barely about Proxima! The book starts with multiple viewpoints over several arcs, is split into tiny chapters and volumes, attempts to become something epic and eventually fizzles. It's not that it's a bad book, it's simply not very good.

You have alien technology found on Mars, two different expeditions to Proxima C - if you don't count the first misguided one, a habitable planet in the Proxima Centauri system, several people and their families over a span of several decades, Artificial Intelligences, a nebulous period in the history of mankind called "The Heroic Generation" which seems to have left people in fear of innovation and discovery, alien lifeforms, artificial lifeforms, parallel timelines, etc. And it's all mixed in. It feels like it should be more, like it was meant to be more, but it just comes out as jumbled and directionless. I think what bothered me most is that characters barely have time to change. In order to explain what happens with a zillion people Earth, Mars, Mercury and an alien planet in a single book, their personal development is sacrificed.

But overall the book was interesting. It covered some bits of Earth future history that most sci-fi works quickly get past. The downside is that it went over them really fast, too :) The actual exploration and life on Proxima was on fast forward, too, with a really hard to believe ecosystem for its simplicity. Oh, and that ending was horrid! I will not read any of the works in the series. I feel that Baxter is overambitious, but also very courageous. I usually have a lot of problems with his works, but still read some of them.

Tuesday 20 March 2018

B: The Beginning - averaging anime into obscurity

The main characters What do you do if you want to make an anime that would be successful not only in Japan, but everywhere Netflix is watched? You take a bit of every successful anime and mix it all together. This is how you get the kingdom of Cremona, set somewhere in a nondescript time that has 1960's cars and cellphones and a nondescript place that looks like Europe, where experiments with the bones of god like creatures leads to superpowerful beings that are super crazy fast and shout Nipponisms with every opportunity: win and lose (in life, but seen as a game), protecting (someone, something, anything) just so your life makes some sense, "I will kill you with my own hands" and so on and so on, but also super smart detectives that figure things out, all for the sake of energetic, smart, cute and ultimately pointless much younger girls. But wait, there is more: there are crazy psychopaths that kill people and are super smart. There are arrogant evil people that have a lot of power, but are ultimately crazy, and which act as if everything and everybody is beneath them. And of course, all the fighting is done with magical swords and henchmen die quicker and with less talk than bosses, who are not particularly strong, but they just yap and yap and yap.

The anger that you see expressed in my review is related not so much to the mediocrity of the anime, but to the potential that it had. The animation is well done, the sets are good, the story is... ahem... workable. And yet they press every button that was ever pressed and add absolutely nothing new. B: The Beginning even has the gall to believe it will spawn sequels, so whatever else they had in mind they left it for later. I would say that's typical DragonBall Z, but that should apply to Saiyans not anime shows! You don't leave the good part for the end of the battle! You don't level up your writing only when you see that everybody is bored already.

Bottom line: the writing was the biggest flaw of this series: unimaginative and inconsistent, with tiresome dialogues and brutal switches of emotional context that made even the most motivated viewer break stride. The rest was always just good enough, with no evidence of any effort for reaching greatness. As mediocre as it can possibly be.

Monday 19 March 2018

Being a Dog: Following the Dog Into a World of Smell, by Alexandra Horowitz

book cover I found Being a Dog a bit misleading, as it is not so much about dogs as it is about smell in general. However, as a book about smell it's a concise and very interesting book. Alexandra Horowitz has a steady professional writing style and the information in the book is being related as anecdotes from her very thorough research.

From the very start the book acknowledges that dogs are not visual and auditory like humans are; instead their main sensory organ is their nose. As the author explores the world of smells, we understand more about us, dogs and how we sense the world in general. I liked many sections of Being a Dog, but I found the first part as most interesting. Mainly because it is about dogs :) There we find that the structure of the nose of dogs is as much responsible for their great sense of smell as is the immense number of sensory cells and dedicated brain neurons. Horowitz explains that dogs do not pass the so called "mirror test", but that is because they are not visual. If the experiment is constructed so that the mirror is olfactory, then they easily pass the test. It also tells us where the smelly glands on the dog are, including its paws. And indeed, I smelled my dog's paw and it was concentrated and nice. If you have a dog, smell their paws now!

That doesn't mean that the part about human smell was not captivating. I found myself smell things on the subway - that is a good thing - just because I felt inspired by what the author described. In conclusion, I recommend the book. It's a light read and it is the kind of work that makes us aware of a part of the world that is both near and ignored.

String theory in C#. My own string!

Well, if Java can do it, so can I! Why not make my own C# string class that can do whatever I want it to do? Requirements? Here they are:
  • I want it to work just like regular strings
  • I want to know if the string is empty just by using it as an if clause, just like Javascript: if (text) doSomething(text);
  • I want to see if it's a number just by adding a plus sign in front of it: var number = +text;
  • I want to easily know if the string is null or whitespace!

OK, so first I want to get all the functionality of a normal string. So I will just inherit from it! Only I can't. String is a sealed class in .Net.
Yet there is an abstract class that seems destined to be used by this: ValueType! It's only implemented by all value types (more or less) except String, but I will be the next guy to use it! Only I can't. If I try, I get the occult message: "Error CS0644 'EString' cannot derive from special class 'ValueType'". But it does help with something, if I try to inherit from it, it tells me what methods to implement: Equals, GetHashCode and ToString.
OK, then, I will just do everything from scratch!

Start with a struct (no need for a class) that wraps a string _value field, then overwrite the equality methods:
public struct EString
{
private string _value;
 
public override bool Equals(object obj)
{
return String.Equals(obj, _value);
}
 
public override int GetHashCode()
{
return _value == null ? 0 : _value.GetHashCode();
}
 
public override string ToString()
{
return _value;
}
}

I used 0 for the hash code when the value is null because that's what the .Net object GetHashCode() does. Now, in order for this to work as a string, I need some implicit conversion from string to my EString class. So add these two beauties:
public string Value { get => _value; }
 
private EString(string value) { _value = value; }
 
public static implicit operator string(EString estring)
{
return estring.Value;
}
 
public static implicit operator EString(string value)
{
return new EString(value);
}

EString now supports stuff like EString text="Something";, but I want more! Let's overload some operators. I want to be able to see if a string is null or empty just like in Javascript:
public static bool operator !(EString estring)
{
return String.IsNullOrEmpty(estring);
}
 
public static bool operator true(EString estring)
{
return !!estring;
}
 
public static bool operator false(EString estring)
{
return !estring;
}
Yes, ladies and gentlemen, true and false are not only boolean constants, but also operators. That doesn't mean something like this is legal: if (text==true) ..., but you can use stuff like if (text) ... or text ? "something" : "empty". Overloading the ! operator allows also something more useful like if (!text) [this shit is empty].

Moar! How about a simple way to know if the string is null or empty or whitespace? Let's overload the ~ operator. How about getting the number encoded into the text? Let's overload the + operator. Here is the final result:
public struct EString
{
private string _value;
 
public string Value { get => _value; }
 
private EString(string value) { _value = value; }
 
public override bool Equals(object obj)
{
return String.Equals(obj, _value);
}
 
public override int GetHashCode()
{
return _value == null ? 0 : _value.GetHashCode();
}
 
public override string ToString()
{
return _value;
}
 
public static bool operator !(EString estring)
{
return String.IsNullOrEmpty(estring);
}
 
public static bool operator true(EString estring)
{
return !!estring;
}
 
public static bool operator false(EString estring)
{
return !estring;
}
 
public static bool operator ~(EString estring)
{
return String.IsNullOrWhiteSpace(estring);
}
 
public static decimal operator +(EString estring)
{
return decimal.TryParse(estring.Value, out decimal d) ? d : decimal.Zero;
}
 
public static implicit operator string(EString estring)
{
return estring.Value;
}
 
public static implicit operator EString(string value)
{
return new EString(value);
}
}

Disclamer: I did this mostly for fun. I can't condone replacing your strings with my class, but look at these examples for usage:
EString s=inputText;
if
(!~s) {
var d = Math.Round(+s,2);
if (d != 0) {
Console.WriteLine("Number was introduced: "+d);
}
}

Wednesday 14 March 2018

A.I.C.O. Incarnation - typical Japanese anime

Unfortunately, being typical is not a good thing. All characters in A.I.C.O. Incarnation are manga clichés and the few interesting sci-fi ideas are obliterated by the lack of courage in showing body horror and the obvious gaps in logic. The most promising, yet underdelivered concept is that of consciousness and identity. What would happen if brains and bodies were swapped, changed, mingled, etc. This could have been great if each episode explored some way the "malignant matter" affected biology and consciousness, but in truth, less than half of an episode really approaches the idea.

In short, the story follows a group of "Divers" who go into a biological infested area in order to stop said infestation and save people. They have to battle amorphous blob like monsters and government officials and mad scientists to get to their goal. Obviously they are all young and rash and falling in love and trying to protect people and making honor bound promises and so on. It was so by the book that it became nauseating. I think a heavily cut video edit of the first and last two episodes would more than cover the entire series.

It is good that Netflix is paying for more anime adaptations, but this one is not that worthwhile. Still 29 to go, though :) Here is a trailer, if you are still interested:

Monday 12 March 2018

Boku dake ga Inai Machi (Erased) - an interesting, if kind of predictable, anime

The main character and the girl he saves Literally translating to "The town where only I am missing", Boku dake ga Inai Machi presents (what else?) a manga artist with no life or future who finds out he can transfer his consciousness in the past, fixing things that went wrong. Of course, the worse thing that ever happened to him was living through a killer's series of murders of some of his school classmates. Another traumatic experience makes him, now 29 years old, transfer his consciousness in the past, during his childhood years, and determined to find and stop the killer.

Now, this might not seem particularly captivating, only the solution for saving the children is not to investigate clues or stake out locations or alert adults, but using the tools a mere child has: making friends, being around the lonely people the killer seems to target. This has an impact on the man's life, but also on that of the people around. In the end, it's a call to end self alienation by connecting and doing good things to people close to you. The title is a metaphor to the impact a person has on their environment. What if you never were? Would things change? The English title - Erased - is the one licensed for the US market and has little to do with the plot.

The anime is nicely drawn, if not spectacular, the Japanisms are pretty common, the story is sort of predictable, so the only true positive thing about the show is the mood and moral. I can't recommend it to everybody, but I personally enjoyed it. It has just 12 episodes and so it's like 4 hours in total. Here is a trailer:

Saturday 10 March 2018

Working on npm packages within other npm packages

Update: the initial article was plaing wrong :) I fixed it now. The important change is that you need to npm link the dist folder, not the root folder of the plugin project.

So, the question arises when you want to change a module that is used (and tested) in another module. Let's say your normal flow is to change the version of the child package, then npm run packagr, then npm publish it, then npm install childModule@latest in the parent app. This quickly gets tiresome and leads to unrealistic version numbers.

A better solution is to use npm link. First, you go to your plugin/child module and you run npm run packagr. When it's done, go to the dist folder and run npm link. This will create a symlink in the global node_modules folder for your project's distribution package. Then, move to the parent module and run npm link <name-of-child>. The name of the child is the same as the name of the application. This creates a symlink in the parent module's node_modules to the global symlink created earlier.

Wait! A few gotchas, first:
  • careful with the operations that might change the content of the folder linked in node_modules, as they will change the actual source code of the plugin
  • after you finish with the work on the plugin, then delete the symlink, publish the child and reinstall @latest at the parent
  • make sure that the version of the plugin package in the parent is permissive (something like >=initialVersion), otherwise you might have problems with the version number you set in the plugin package.json file

Hope this helps.

Friday 9 March 2018

npm gotcha: commit and do not delete package-lock.json

NPM is a popular package manager (think NuGet for JavaScript) and the information of the packages that it needs to install is stored in a file called package.json. You run npm install, packages are getting downloaded in a folder called node_modules and a package-lock.json file is generated. Since you can always delete node_modules and package-lock.json and rerun the package install, a common assumption is that they are redundant and they shouldn't be stored in source control. That is wrong in most cases.

The lock file not only stores the progress of the npm installation, but also the actual versions of the packages that it installs (for the entire dependency tree). As opposed to this, package.json contains only the packages directly needed by the project and the acceptable ranges of the versions. One can allow for any version of a package to be used, or maybe anything above a version, or an interval or something that is "the best version" around a specific version. Deleting the package-lock.json file effectively tells NPM that you trust package.json and the developers of each package for the versions of the dependencies loaded.

Here is a common scenario: you create a new application, you need some NPM packages so you npm install thePackage. This gets the latest version of thePackage and installs it, then marks the exact version into package-lock.json as well as the versions of the packages thePackage uses and what they use and so on. Finally, you commit the project, including package-lock.json. Three months later, a new developer comes and gets the project from source control. They use npm install and see that everything works perfectly, because the packages restored are the exact same versions as the ones restored for the original developer. But now they think "who committed package-lock.json? Don't they know it's redundant?" so they remove it from source control. Three months later another developer comes and runs npm install on the source from the code repository, only nothing works anymore. The versions that were downloaded are, depending on what is specified in package.json, the latest version of the dependency or maybe a version similar, but with a different minor version, and with the dependencies that the developers thought best for that particular version.

There is a situation when package-lock.json is entirely redundant and that is when package.json only specifies exact versions. NPM works so that you cannot replace the same version of a software in their repository, so the devs will never be able to change the package versions they used for a specific version. That is why it is safe to assume that the same version of a package will use the same package dependency tree (unless some of the packages are removed, but that's another question entirely).

Summary: If you have any version of a dependency in package.json specified as anything else than a specific version (no tilde, no caret, no asterisks, no intervals), then you also need to store package-lock.json in your source control.

Sunday 4 March 2018

tpbclean.info is dead, but you don't need it

If you ever used The Pirate Bay, you know that a lot of the content there is porn. Even the most popular distribution users share movies or series among tons of porn links. In order to solve this problem, TPBClean.info appeared, as a simple pirate bay proxy that eliminated the porn links. Now that site is dead. I can't say that I am overly sad about it, since it worked very badly anyway. Yet, now, if you want to find movies shared by the likes of xxxlavalxxx or juggs99 (which probably started out as porn distributors anyway, with those nicks), you can't even see where they are in all that sea of xxx.

Well, there is a very simple solution, works in your browser, and all you need to do is install an extension that you probably ought to have had anyway. Now, this article assumes you use Chrome, but it probably works the same with Firefox. For Internet Explorer and Edge I have no idea and I also don't have the time to do the research, so if you feel inclined to help others and you know how to do it, please leave a comment and I will update the post.

This is the solution: install the CJS extension, which is a simple enough tool that allows you to run a script of your own design on any page. After you have installed it, browse to The Pirate Bay, click the extension button and add this script:
document.querySelectorAll('a[href="/browse/500"]')
.forEach(node=>{
while(node && node.nodeName.toLowerCase()!='tr') { node=node.parentNode};
if (node) node.style.display='none';
});

You might be tempted to try to load jQuery and rewrite the script, for better readability, but take into account that most ad blockers (which you probably use, if you use torrent sites) block jQuery on pirate bay domains.

What the script does is hide all the rows that have the Porn (id 500) category. If the site ever changes its ids, you might want to update the script, although that scenario is pretty unlikely.

Update: TPB Clean seems to be back online, but the article still applies.

Saturday 3 March 2018

Personal archaeology

We are changing the furniture and repainting the walls in the apartment, so naturally, the first order of business is to dig into closets, drawers, bags, boxes and various regions under existing furniture and throw away as much as possible. It is a strange feeling, one that makes me remember a past and dead self, one that was hopeful, smart, crazy, in love, using technology and doing stuff that I can't even begin to comprehend nowadays.

I dug into old CD albums, remembering with much nostalgia the movies that I was watching and intending to keep forever. The movies are still around, CD players are almost gone. I had to use my wife's laptop to read the CDs, as mine would only accept a few of them. Well, that's because it's broken, but still. Among the CDs I found old source code and material that I had gathered from friends, jobs, the Internet, hacking. I felt like an archaeologist digging through the remains of old civilizations, ones we hold dear and towards which we feel a strong sense of ownership, but with which we have nothing in common.

Here it is: the Palm VX PDA that was built in 1998 and still works now, with the same battery, if you can just find a way to connect it to a computer so you can upload new stuff to it. Here it is: the Nokia E60 phone that worked flawlessly for more than ten years. I bought a smartphone to replace both of them just five years ago. But also, here it is: an external modem I had forgotten I had; I still wonder where I used it, if ever, and how I got hold of it. Same for the audio/video/infrared wireless transmitters and receivers that allowed me to watch movies from the computer to the TV in the other room. Tens of meters of Ethernet and all kinds of connective cables, forgotten in an age of ubiquitous digital wireless connection just forgotten in the odd corners of the house. Remains of two desktop computers (that I could still make work if I had the inclination) linger like the fossilized bones of extinct creatures.

I feel a mix of gratefulness, nostalgia, loss and that I am fucking old, all at the same time. I wonder where I could find people that still value these things that I dug out from my past and that otherwise will soon become anonymous and amorphous junk. Geez, look at the 6 CDs of utility software, stuff I still remember fondly and stuff I have never used: antivirus, archiving, communication, VoIP, OCR, document processing, all software that is in heavy use today but you would be hard pressed to find people still recognizing these particular incarnations. Music that I still have in my playlist on CDs almost twenty years old. Games that I had worked on that I have forgotten ever doing. Random writing from when I was so young I feel embarrassed just to remember.

And this is just from a 50 square meter apartment that we moved into just ten years ago. I can't even imagine how people do this when they move out from their childhood home, where they and their kids have lived for generations. What do they find? Do they even recognize it? What happened to all the people that I once was?