sRGB↔L*a*b*↔LChab conversions

Posted by Michał ‘mina86’ Nazarewicz on 21st of December 2022

Chronological order of The Witcher

Posted by Michał ‘mina86’ Nazarewicz on 11th of December 2022

Ever since Witcher games took off the franchise skyrocketed in popularity. Books, comics, TV show, games, more comics, another TV show… The story of Geralt and his marry company has been told in so many ways that it’s becoming a wee bit hard to keep track of chronology of all the events; especially across different forms of media.

In this article I’ve collected all official Witcher works ordering them in chronological order. To avoid any confusion, let me state up front that if you’re new to the franchise or haven’t read the books yet this list might not be for you. If you’re looking for the order to read the books in, I’ve prepared a separate article which describes that.

Skip right to the chronology

URLs with // at the beginning

Posted by Michał ‘mina86’ Nazarewicz on 4th of December 2022

Just a quick reminder that relative URLs can start with a double slash and that this means something different than a single slash at the beginning. Specifically, such relative addresses are resolved by taking the schema (and only the schema) of the website they are on.

For example, the code for the link to my repositories in the site’s header is <a href="//github.com/mina86">Code</a>. Since this page uses https schema, browsers will navigate to https://github.com/mina86 if the link is activated.

This little trick can save you some typing, but more importantly, if you’re developing a URL parsing code or a crawler, make sure that it handles this case correctly. It may seem like a small detail, but it can have a big impact on the functionality of your code.

Secret command Google doesn’t want you to know

Posted by Michał ‘mina86’ Nazarewicz on 20th of November 2022

Or how to change language of Google website.

If you’ve travelled abroad, you may have noticed that Google tries to be helpful and uses the language of the region you’re in on its websites. It doesn’t matter if your operating system is set to Spanish, for example; Google Search will still use Portuguese if you happen to be in Brazil.

Fortunately, there’s a simple way to force Google to use a specific language. All you need to do is append ?hl=lang to the website’s address, replacing lang with a two-letter code for the desired language. For instance, ?hl=es for Spanish, ?hl=ht for Haitian, or ?hl=uk for Ukrainian.

If the URL already contains a question mark, you need to append &hl=lang instead. Additionally, if it contains a hash symbol, you need to insert the string just before the hash symbol. For example:

  • https://www.google.com/?hl=es
  • https://www.google.com/search?q=bread+sandwich&hl=es
  • https://analytics.google.com/analytics/web/?hl=es#/report-home/

By the way, as a legacy of Facebook having hired many ex-Google employees, the parameter also work on some of the Facebook properties.

Reading order of The Witcher

Posted by Michał ‘mina86’ Nazarewicz on 31st of July 2022

Without beating around the bush, the reading order for the Witcher books is as follows:

1.The Last WishShort
stories
2.Sword of Destiny
3.Blood of ElvesThe Witcher Saga
4.Time of Contempt
5.Baptism of Fire
6.The Tower of the Swallow
7.The Lady of the Lake
8.Season of Storms

Curious case of missing π

Posted by Michał ‘mina86’ Nazarewicz on 28th of June 2022

π is one of those constants which pops up when least expected. At the same time it’s sometimes missing when most needed. For example, consider the following application calculating area of a disk (not to be confused with area of a circle which is zero):

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
	for (int i = 1; i < argc; ++i) {
		const double r = atof(argv[i]);
		printf("%f\n", M_PI * r * r);
	}
}

It uses features introduced in the 1999 edition of the C standard (often referred to as C99) so it might be good to inform the compiler of that fact with a -std=c99 flag. Unfortunately, doing so leads to an error:

$ gcc -std=c99 -o area area.c
area.c: In function ‘main’:
area.c:8:18: error: ‘M_PI’ undeclared (first use in this function)
    8 |   printf("%f\n", M_PI * r * r);
      |                  ^~~~

What’s going on? Shouldn’t math.h provide the definition of M_PI symbol? It’s what the specification claims after all. ‘glibc is broken’ some may even proclaim. In this article I’ll explain why the compiler conspire with the standard library to behave this way and why it’s the only valid thing it can do.

Pro tip: You can put URLs in C & C++ code

Posted by Michał ‘mina86’ Nazarewicz on 1st of April 2022

Documenting source code is important part of software engineering. Code is read more often than it’s written making it crucial to provide enough context for reader to understand what the implementation is doing. This can come in the form of links to external resources providing description of an algorithm, reference for an API or historic context justifying the code.

As it turns out, C and C++ languages offer a little-known feature which allows URLs to be included directly in the function source code. For example:

static float rsqrt(float x) {
	https://en.wikipedia.org/wiki/Fast_inverse_square_root
	static_assert(std::numeric_limits<float>::is_iec559);
	auto i = std::bit_cast<uint32_t>(x) >> 1;
	auto y = std::bit_cast<float>(UINT32_C(0x5F375A86) - i);
	y *= 1.5f - x * 0.5F * y * y;
	return y;
}