Python sys.path[0] is not getcwd

While providing feedback to participants of Online Seminar of Informatics I’ve encountered a code, which used sys.path[0] to get the current working directory. sys.path is a list of folders used by Python interpreter during import resolving. For simple cases sys.path[0] is indeed the current working directory, but beware that there are a lot of things, which can change the sys.path variable - automatic reload of a Flask server is one of them....

February 27, 2022 · 1 min · Ondrej Borysek

Python and global variables

While reviewing codes submitted by participants of Correspondence Seminar of Informatics I’ve stumbled upon the following situation in Python. Care to guess what it prints? x = 42 def test(): x = 28 global x print(x) Not really what I would expect, but makes sense.

February 6, 2022 · 1 min · Ondrej Borysek

When debugging web analytics don't forget about DNT

There used to be an option in browsers (and some still have it) to signal explicit opt-out of tracking - so called Do Not Track. Most advertisers ignore it, because they can. Today I was deploying a more privacy focused web analytics and had the option to respect it, so I did. Than for 20 minutes I was running in circles not being able to figure out why the analytics detected my visit in Edge, but not the one in Chrome....

January 21, 2022 · 1 min · Ondrej Borysek

C lang: array names and indexes can be swapped

#include <stdio.h> int main() { char a[] = {'a', 'b', 'c'}; int b = 1; printf("--%c--\n", a[b]); printf("--%c--\n", b[a]); printf("--%c--\n", 1[a]); return 0; } All three print the same --b--. Why? The direct access would be using pointer *(a + b) and there the plus sign is commutative. The bracket notation is just syntactic sugar and apparently it does not check for the weird swapped notation.

January 17, 2022 · 1 min · Ondrej Borysek

Images with color profiles can break things

Hugo (static website generator tool) has a lot of tools to help resizing/basic editing of images. But be careful about using with sRGB photos with color profiles - the library used by Hugo seems to just discard them, which can be really problematic. In my case the picture just lost of contrast, but it can also cause color shift. It’s a known bug, currently not fixed. I suspect hugo is most likely not the only software with this problem....

January 11, 2022 · 1 min · Ondrej Borysek

Noisy Desktop fans? Maybe just an old CMOS battery.

Several times over the past half a year or so I’ve few issues with my desktop - fans running to fast and therefore noisy, having to reenter the BitLocker key for encryption of Windows drive, RAM profile resetting, and so on. I’ve finally cracked it - the BIOS was getting cleared whenever the PC was disconnected (even just momentarily) from the grid. The weird thing was that several times only some of the settings were lost, not all of them....

December 14, 2021 · 1 min · Ondrej Borysek

DNS over HTTPS breaks WIFIs with captive portals

Private DNS (DNS over HTTPS) on Android can block DNS hijacking. WiFi auth portals are often implemented in such way, so it breaks them. The consequences are rough - not all public WiFi networks are working for you, and also no additional slow (30 kbps) mobile internet from T-Mobile, after your data package runs out. And there is no user understandable error msg. #itsAlwaysDNS

December 13, 2021 · 1 min · Ondrej Borysek

WSL2 by default uses at most 8 GB of RAM

WSL2 has a configuration file .wslconfig, which can contain settings for it. Most of the settings don’t ever need to be touched with maybe one exception: memory. By default it’s 50% of total memory on Windows or 8GB, whichever is less, so with effective max of 8 GB unless you set it manually. It’s a reasonable default, though you might encounter it if you are doing something memory intensive. Link to documentation

November 16, 2021 · 1 min · Ondrej Borysek

Eshop může kontrolovat příjmení

Formulář vyžadující příjmení ho může zkusit validovat, nejspíše vůči databázi českých příjmení od ministerstva vnitra. Když je to jako soft-fail, tak to může pomáhat eliminovat překlepy, aniž by to diskriminovalo lidi, jejichž příjmení nebyla v tehdejším snapshotu DB.

October 17, 2021 · 1 min · Ondrej Borysek

HSTS doesn't block Let's encrypt HTTP-01 challenge

During setup of Netlify I’ve noticed, that they were able to get SSL cert even though my domain has HSTS and they don’t have access to my DNS (Cloudflare). Quick check to documentation of Let’s Encrypt revealed that for HTTP-01 challenge they don’t check the certificates. That not only makes the process potentially a bit safer, as it can go through HTTPS with self-signed cert instead of plaintext HTTP, but also solves the edge case of expired cert / first cert and HSTS with no access to DNS....

October 16, 2021 · 1 min · Ondrej Borysek