Archive for the ‘Uncategorized’ Category

[ C lang] reading a text file line by line

February 22, 2020 Leave a comment

I had a text file that I was reading line by line in C. Every line was tokenized. The file looked like this:

1978	Aachen Cathedral	DE	C	EUR	0	3
1978	City of Quito	EC	C	LAC	70	2
1978	Galápagos Islands	EC	N	LAC	14066514	1

I converted every year to an integer. From the 2nd line I got 1978 (as int), but in the first line the string to int conversion failed.

It turned out that the token “1978” in the first line was 7 characters long, not 4. At that point I opened the file in a hex editor and there were 3 special bytes at the beginning: EF BB BF. This is a byte order mark (BOM).


As a quick fix, I removed those 3 bytes in the hex editor.

I tried it under Python too and it caused a problem there too:

>>> f = open("input.txt")
>>> s = f.readline()
>>> s
'\ufeff1978\tAachen Cathedral\tDE\tC\tEUR\t0\t3\n'
>>> s.split()
['\ufeff1978', 'Aachen', 'Cathedral', 'DE', 'C', 'EUR', '0', '3']
>>> s.split()[0]
>>> int(s.split()[0])
Traceback (most recent call last):
  File "", line 1, in
ValueError: invalid literal for int() with base 10: '\ufeff1978'

If you know how to ignore those bytes during file read, please leave a comment. I’m interested in both C and Python solutions.

How to sync my Sublime Text 3 settings using Dropbox?

February 11, 2020 Leave a comment

You re-install a Linux machine and you want to use your Sublime Text 3 editor settings on this machine too. How to sync your complicated settings?

The answer is here: link.

To properly sync your installed packages across different machines, you actually do not want to sync the whole Packages/ and Installed Packages/ folders. The reason for this is that some packages have different versions for different operating systems. By syncing the actual package contents across operating systems, you will possibly run into broken packages.

To sync the folder, you generally move Packages/User/ into your Dropbox and create a symlink to it from Sublime Text 3/Packages/.
” (source)

TabNine stopped working with Sublime Text

December 21, 2019 Leave a comment

TabNine is an awesome plugin that every developer should use. Unfortunately, it stopped working for me a few days ago.

I found the solution here: . In short: go to the folder ~/.config/sublime-text-3/Packages/TabNine/binaries/2.1.22, create a folder called x86_64-unknown-linux-musl, and copy the binary from x86_64-unknown-linux-gnu to this newly created folder x86_64-unknown-linux-musl. Finally, restart Sublime Text.

Categories: Uncategorized Tags: , ,

How to loop a YouTube video?

December 17, 2018 Leave a comment

You have a favorite song and you want to listen to it in a loop.

Right click on the video and select “Loop”.

[Nim] cross-compile under Linux to Windows

October 23, 2018 1 comment

You are under Linux, and you can produce an executable binary with the Nim compiler. However, you would like to produce a Windows EXE too. We want to stay under Linux and we want to produce the EXE on Linux. How to do that?

On Manjaro, I had to install this package:

$ yaourt -S mingw-w64-gcc-bin

It’s a cross-compiler that we’ll use for producing the EXE.

Let’s take a simple Nim source (hello.nim):

echo "hello windows"

Now cross-compile it:

$ nim --os:windows --cpu:amd64 --gcc.exe:x86_64-w64-mingw32-gcc --gcc.linkerexe:x86_64-w64-mingw32-gcc -d:release c hello.nim

And you get hello.exe .

$ file hello.exe
hello.exe: PE32+ executable (console) x86-64, for MS Windows

If you copy it on a Windows system, you can run it there without any problem. Or, you can also run it under Linux with wine :)

$ wine hello.exe
hello windows

I found this idea in the following blog post: Writing a 2D Platform Game in Nim with SDL2.

Update (20181028)
I found info about it in the official docs too:

moved from KeePassX to KeePassXC

October 13, 2018 Leave a comment

KeePassX served me very well in the last few years. It’s a password manager that keeps your usernames / passwords in an encrypted file and you only need to memorize just one master password.

KeePassXC is the community edition of KeePassX. From its FAQ: “KeePassX is an amazing password manager, but hasn’t seen much active development for quite a while. Many good pull requests were never merged and the original project is missing some features which users can expect from a modern password manager. Hence, we decided to fork KeePassX to continue its development and provide you with everything you love about KeePassX plus many new features and bugfixes.

I tried it and it could open my .kdbx database file without any problem. It has some nice changes compared to KeePassX so I think I’ll use this newer and fresher version. Just like KeePassX, it runs under Linux and Windows too.

Xbox 360 controller not detected

March 16, 2018 Leave a comment

I have a wired Xbox 360 controller that stopped working. Windows 7 doesn’t recognise it and it appears as an “unknown device”.

I tried everything: uninstall and reinstall the driver; reinstall the USB drivers that I got on a DVD for the motherboard; plug it in another USB slot. Nothing. After 1.5 hours, I found the solution: the cord has an inline release and it was not entirely connected… Damn. But the good news is that it works again :)

Lesson learned: if you have a problem with the controller, first check the inline release.