The modulo operation is not that trivial

December 1, 2025 Leave a comment

Surprise

In Python, -1977 % 100 = 23. In JavaScript, -1977 % 100 = -77. WTF?

Explanation

Modulo in different languages has different meaning! It’s not like the plus (+) operator which means the same thing in every language when applied for two integers, for instance.

In Python:

a % b = a - (b * floor(a / b))

In JavaScript:

a % b = a - (b * truncate(a / b))

For example, if a = -1977 and b = 100, then a / b is -19.77. But! floor(-19.77) is -20, while truncate(-19.77) is -19. Hence the difference!

I tested some languages and got the following result:

Group 1 (languages using floor()): Python, Lua

Group 2 (languages using truncate()): C, C++, D, Java, JavaScript, C#, Go, Rust, Nim, Kotlin, Pascal, Swift

Some more examples in Python and in JavaScript

Python:

>>> 1977 % 100
77
>>> -1977 % 100
23
>>> 1977 % -100
-23
>>> -1977 % -100
-77

JavaScript:

> 1977 % 100
77
> -1977 % 100
-77
> 1977 % -100
77
> -1977 % -100
-77

How to imitate Python?

How to have a Python-like modulo in other languages? Here is a C function:

int modulo(const int a, const int b)
{
    return ((a % b) + b) % b;
}
Categories: algorithms, programming Tags: , ,

Giving away my Dell Latitude D410

November 4, 2025 Leave a comment

Today I decided to give away my Dell Latitude D410 laptop. I bought it second-hand when I was in Montréal, Canada. It was 200 CAD at that time. I liked this laptop but it hasn’t been switched on for many many years. I took some photos of it: https://imgur.com/a/dell-latitude-d410-UkcFPzQ

Specs: 32-bit Pentium M processor, 2 GB RAM, 40 GB HDD.

I gave it to a friend who is not a tech guru. I installed LMDE 6 on it. “LMDE is a Linux Mint project which stands for ‘Linux Mint Debian Edition’. Its goal is to ensure Linux Mint can continue to deliver the same user experience if Ubuntu was ever to disappear.” (source) LMDE 6 supports 32-bit systems and it’s suitable for old computers, that’s why I chose it. It’s very similar to the normal Linux Mint (Cinnamon). The only difference I noticed was the GUI software updater. It didn’t have the option to select and install the kernel version you want. Otherwise, it had the same look & feel. And it worked relatively well on this old laptop.

Lesson learned: if you want Debian with the goodies of Linux Mint, try LMDE, which combines the best of both worlds.

I only had one issue: the wifi card in the laptop was not recognized. However, after installing the package firmware-b43-installer , the wifi started to work :)

Goodbye, old little laptop. You served me well!

Notes / Links

  • LMDE 6 “Faye” released! (blog post announcement)
  • LMDE 6 will reach its end-of-life around October 2026. You can verify it here.
  • LMDE 7 is newer but it dropped 32-bit support.

How to compact VirtualBox’s VDI file size?

October 29, 2025 Leave a comment

Problem

I had a Windows 10 in VirtualBox. I gave it a dynamic VDI file of size 100 GB. The file was about 50 GB large. When I upgraded it to Windows 11, the installer downloaded about 30 GB stuff, thus the VDI grew to 80 GB. After the upgrade, I cleaned the system and managed to go back to 50 GB inside Windows. However, the VDI file doesn’t shrink, it remained 80 GB. So I lost 30 GB free space. How to get it back?

Solution

I found the solution here. In short: fill up the empty space with zeroes and then ask VirtualBox to compact the VDI file. During this process, empty space filled with zeroes can be removed. This way I could reduce the size of my VDI file from 80 GB to 50 GB.

Steps:

  • I didn’t defrag my Windows. As I know, NTFS defrags itself regularly. I skipped this step.
  • Fill free space with zeroes. Download the tool sdelete and run it inside Windows. Open a terminal in admin mode and issue this command: sdelete64 -z C:
  • Shut down the Windows system (the guest).
  • In the host (I have Linux), issue this command: VBoxManage --compact Windows10.vdi

It’ll reduce the size of the VDI file. After that, start your Windows box.

Before starting this process, I made a backup of my virtualboxed Windows, but there was no problem.

Upgrade to Windows 11

October 13, 2025 Leave a comment

This is October 2025. Since Windows 10 reached its EOL, I’ve decided to upgrade my machines to Windows 11. I started with a laptop and I summarize here my experiences.

  • I want to have both Windows and Linux on my machines. Windows is Windows 11 25H2, and Linux is Manjaro Linux.
  • My laptop didn’t meet the official requirements for Windows 11 but there’s a solution for that: create the bootable USB with Rufus. Upon creation, Rufus will come up with a list to personalize your Windows stick. You can select to disable secure boot, disable TPM 2.0 check, etc.
  • First I installed Windows 11. There was no problem during the installation. My laptop has an Intel Core i7-4500 processor @ 1.8 GHz (4 virtual cores) and 8 GB RAM with 250 GB SSD. Windows 11 runs fine on it. I installed the Enterprise edition. I gave it a 150 GB partition. It seems to be enough. I also have an external HDD attached to it.
  • I installed with a local account, as shown in this video.
  • After Windows, I installed Manjaro Linux in a separate partition. With btrfs I had some problems, so I chose the ext4 file system.
  • To Enter the boot menu, I had to keep pressing the ESC key. First, the USB option didn’t appear. Then, when I moved the stick to another USB slot, it appeared in the menu and I could boot from it.
  • Under Windows, I installed the updates.
  • I installed Total Commander.
  • With ninite.com, I installed lots of useful programs.
  • To make screenshots, I installed ShareX (available in ninite.com).
  • Some other useful softwares: qbittorrent (version 4.5.5), WinCDEmu (to mount ISO images), and Winaero Tweaker (to tweak Windows).
  • I activated my Windows and then used Winaero Tweaker to customize it.
  • I also installed Avast Antivirus (available in ninite.com).
  • I have some tools written in Go and they launched very slowly. It took about 15 seconds for an EXE to start. Avast was the culprit. Here is how to put a directory to an exception list: start Avast, then Menü -> Beállítások. Under Általános, select Kivételek. Then add your exceptions. (Sorry, I have Hungarian Windows).
  • When you install Go programs with “go install“, they are put here: C:\Users\<user>\go\bin
  • Startup applications are here: C:\Users\<user>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup . I created here some symbolic links.
  • How to create a symbolic link: mklink link original
  • If mklink is not found in PowerShell, use this: cmd /c mklink link original
  • When you put cmd on the Desktop, then actually it’ll be the Terminal with PowerShell. However, in its Settings, you can select Command Prompt to be your default profile. You can also set to center the terminal on the screen.
  • I also enabled auto login, as described in this post of mine.

Linux

  • I installed Manjaro Linux with ext4 (I had some problems with btrfs). I gave it about 100 GB. The installer told me to create another partition that must be mounted as /boot/efi . But the installer provided every detail about it. (I made it 500 MB, FAT32, and gave it the boot flag).
  • Grub starts the operating system that was started the last time. It’s good for me, so I didn’t change it.
  • I’ll customize Linux later.

Updates

  • On another laptop of mine, Windows 10 offered to upgrade my system to Windows 11. I accepted it and it did a great job. All my installed programs remained functional. It was a painless experience.
  • If Windows 10 doesn’t offer the upgrade, you can try the Windows 11 Installation Assistant. If it’s stuck at downloading updates, then just wait. Mine was stuck at 46% for about 1.5 hours but then it continued. (This upgrade failed at the end, but it didn’t ruin my system.)
  • I figured out just later that you can try to upgrade your system by keeping everything. That is, you keep all the programs and settings. Prepare your USB stick with Rufus, launch Windows 10 or Windows 11, and start setup.exe from the USB. It’ll start the upgrade process and you can select to keep everything (programs and settings). This way I could upgrade a Windows 11 23H2 system to Windows 11 25H2. Just make sure that you have around 50 GB free space before starting the upgrade.
  • I could also upgrade a virtual machine of mine that had a Windows 11 23H2. I copied the content of the USB stick to drive C: to a temporary folder and launched setup.exe . The upgrade went flawlessly.
Categories: windows 11 Tags: , , ,

VLC shows some codec error

July 21, 2025 Leave a comment

Problem

After upgrading my Manjaro box, VLC started to show some error message about a codec error. The video and audio played correctly, but there was an error message.

Solution

sudo pacman -S vlc-plugins-all

Links

Categories: manjaro Tags: , , ,

Master thesis of Linus Torvalds

Linux: a Portable Operating System by Linus Torvalds

Written in 1997. 60 pages long.

Categories: linux Tags: , ,

screenlocker

June 13, 2025 Leave a comment

Question

What app. to use use for locking the screen?

Answer

slock . I put it on Ctrl + Alt + L . A very nice, zero bullshit software.

Read the man page of slock. It gives a tip how to make it more secure.

Categories: linux Tags: , , , ,

asciinema: record your terminal session easily

April 7, 2025 Leave a comment

Problem

You want to record your terminal session and you want to make a GIF of it. Why? For instance you want to make a short demo for a command-line application.

Solution

Use asciinema and agg for this purpose.

Usage:

$ asciinema rec demo.cast
# Press "Ctrl+d" when ready

$ agg demo.cast demo.gif

Installation (under Manjaro):

$ yay -S asciinema
$ yay -S asciinema-agg

Links

Categories: linux Tags: , , , , , ,

Midnight Commander tips

April 6, 2025 Leave a comment

At https://hamwaves.com/cli/doc/mc.pdf I found a very useful presentation about MC. I use MC every day but I could still learn a lot from this.

Problem

In this presentation I learnt about the User Menu (F2). I’ve never used it… Here, for instance, you can compress the current directory. However, ZIP compression is missing. How to add it?

Solution

Make sure that you have the “zip” command. Then, copy the file /etc/mc/mc.menu to ~/.config/mc/menu . Yes, it must be renamed to “menu“. Edit it and add the following lines:

z       Compress the current subdirectory (.zip)
        Pwd=`basename %d /`
        echo -n "Name of the compressed file (without extension) [$Pwd]: "
        read tar
        [ "$tar"x = x ] && tar="$Pwd"
        cd .. && \
        zip -r "$tar.zip" "$Pwd" && \
        echo "../$tar.zip created."

Here “z” is a shortcut, and “tar” is just a variable name. I was lazy to rename it (“zip” would be a better name).

How to use it? Navigate inside the folder that you want to compress recursively. Press F2, then press z, and specify a filename. The compressed file will be created in the parent directory.

Links

Compile and run a raylib project on Windows in VirtualBox

March 23, 2025 Leave a comment

Problem

I’m playing with Raylib under Linux. I also wanted to try a simple project on Windows, but I have Windows in VirtualBox. The project is written in C, and it compiles fine. But when I want to start the EXE, I get the following error:

WARNING: GLFW: Error: 65542 Description: WGL: The driver does not appear to support OpenGL
Assertion failed: window != NULL, file external/glfw/src/window.c, line 581

The reason must be that the program wants to use OpenGL, but under VirtualBox the GPU is not available. I also tried the EXE on a native Windows and there it worked well.

Solution

There’s an easy fix for this. Try the Mesa3d Llvmpipe software rendering OpenGL driver. Link: https://github.com/mmozeiko/build-mesa . Under Releases, I downloaded the file mesa-lavapipe-x64-VERSION.zip , which contains just one file: opengl32.dll . I put it in my project folder, next to the EXE and the program started nicely. It wasn’t that smooth, but at least it was willing to start.

Design a site like this with WordPress.com
Get started