The modulo operation is not that trivial

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;
}

Giving away my Dell Latitude D410

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?

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

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.