For the English part of the blog, see Content AND Presentation.

2018-02-19 A console.log gotcha in Node.js

I’ve been writing a certain Node.js script recently, and I was caught by surprise with an innocent-looking console.log. So, here is my warning to all unsuspecting Node.js script writers.

Since the script is under development, I do not bother with outputting the results to a file with fs.writeFileSync, but just console.log them to stdout. (And at some point, the output was a huge object, written out with JSON.stringify.) So far, so good.

For certain reasons (mainly my sloppiness) I ended the script with a process.exit(0). This is probably bad practice, and I switched to properly closing my database connections afterward –this is what you should do anyway. (If you don’t close your connections, or leave some other non-blocking operation turned on, your script will seem to hang and you’ll have to Ctrl-C out of it.) So far, so good – this is WiP, so a process.exit(0) won’t do any harm, right?

Well, wrong. It turns out that console.log (and its ilk) is sometimes non-blocking! I didn’t expect that. And it wouldn’t be that bad if not for the fact that the synchronicity of writes to stdout (and stderr, for that matter) depend on two things: whether the output is linked to a terminal or e.g. to a pipe, and whether you are on Windows or on a POSIX operating system. This doesn’t make sense at all to me, but it is what it is. Be warned.

CategoryEnglish, CategoryBlog, CategoryJavaScript

Comments on this page

2018-02-12 append-next-kill

Today I’d like to share a simple trick which I learned a few days ago. It is well-known that if you perform a few killing commands in a row (like C-k or M-d), only one entry is put into the kill ring. Sometimes, however, I want to kill things in different places and still combine them into one kill ring entry. Enter C-M-w, or M-x append-next-kill. It makes the next killing command append its prey to the last kill ring entry. (If you do something, erm, non-lethal after append-next-kill, it has no effect.)

Actually, it does even more. If the next kill command kills backward, then the killed text is prepended to the kill ring entry. And in case of C-w (kill-region), the “direction” of killing is determined using the relation of point and mark: if the point is after the mark, the kill is considered a forward one, and if the point is before the mark, a backward one.

You may wonder how all this is actually implemented. It turns out that append-next-kill is actually very simple. Go look up its definition, it’s very instructive. (In particular, it utilizies a nice way of determining whether it was run interactively and acting accordingly. If not for that, it would actually be a one-liner!)

What can I say? Happy killing! ;-)

CategoryEnglish, CategoryBlog, CategoryEmacs

Comments on this page

2018-02-05 The death camps in Poland issue

In the spirit of another PSA about Poland, I would like to mention to everyone that haven’t yet heard about it the issue of death camps in Poland.

Note that the introduction to this is longer than the actual message. I can’t do it another way without assuming you know a bit about Polish history, and I do not want to assume that.

Poland was the very first country invaded by Germany in 1939. On September 1, German armed forces entered Poland without even declaring a war. Two days later, as Poles hoped, Great Britain and France – our allies – declared war on Germany. Unfortunately, this was not followed by a real action.

On September 17, another of our neighbors – the Soviet Union – invaded us from the east. (Neither did they care enough to declare a war, even though the SU had a non-aggression pact signed with Poland at the time.) Imagine terrified families fleeting from the western part of Poland only to find another army attacking them…

If that was not enough, for the next few years a large part of Poland was under German rule. While we had the secret “underground state”, we could not do a lot – most if not all activities of this “underground state” were illegal and punishable by death. (This did not prevent us from accomplishing or at least attempting quite a few things, including the – unfortunately unsuccessful – Warsaw Uprising.)

During that time, on the territory of Poland (and also Austria, Germany and a few other countries), Germany built more than twenty extermination and concentration camps. They became very effective “death factories”, were people were mass killed at an unprecedented rate. It is well-known that Jews were the primary target, and perhaps lesser-known that there were other groups persecuted in a similar fashion: Poles (and several other nationalities) were also considered subhumans, and Catholic clergy was another group which was especially persecuted. Overall, close to three million Polish Jews were killed in these camps and elsewhere; it is estimated that about 2.8 million Poles shared their fate.

Yet, many people know about the former, but not about the latter. This would not be so bad if not for the still circulating lie about the “Polish death camps”. After all, they were located in Poland, weren’t they?

Well, saying “Polish death camps” in front of a Pole is a bit like saying about “the American terrorist attack of 9/11” in front of an American. Not only extremely offensive, but also an outright lie.

Yet this is what people say all the time. (This is also what e.g. Barack Obama said a few years ago. One might think that when a president of a country heavily offends his country’s ally, he will promptly apologize. The apology never happened, though, only an “expression of regret”, which is beyond my comprehension. But this is only a digression.)

So, after this lengthy introduction, what I want you to do? Well, not much. Just please never speak about “Polish death camps”, and correct people who might do so (most often out of ignorance, not malice, I presume).

And if you want to learn a bit more about the issue, you may start here. If you are afraid of some kind of bias (which is a legitimate concern), ask Wikipedia or any history textbook.

Thank you.

CategoryEnglish, CategoryBlog

Comments on this page