Archive

Author Archive

C compiler for Windows

January 15, 2020 Leave a comment

Problem
You need a C compiler under Windows.

Solution
At https://nuwen.net/mingw.html you can find a MinGW distribution, which is x64-native and contains GCC and Boost. Download the installer, install it, and add its “bin” folder to your PATH.

Then you have a C compiler under Windows.

Using sqrt in C lang.

January 3, 2020 Leave a comment

Problem
The following code compiles with “gcc in.c“:

#include 
#include 

int main()
{
    double result = sqrt(9.0);
    printf("%lf\n", result);

    return 0;
}

The following code drops an error if you try to compile with “gcc in2.c“:

#include 
#include 

int main()
{
    double value = 9.0;
    double result = sqrt(value);
    printf("%lf\n", result);

    return 0;
}

The error message says: “undefined reference to `sqrt'”.

Solution and Explanation
In the second case, compile it with “gcc -lm in2.c“, which links the math library. But why does the first example work? In that case the compiler figures out (knows) the value of the square root operation and replaces the function call with a constant 3.0 value. The optimizer is that clever :) In the second case however it tries to call the sqrt() function but it’s not found. If you link the math library, it’ll find it.

Force Avast NOT to scan my EXEs

December 29, 2019 Leave a comment

Problem
Currently I’m working on a C tutorial and thus I write lots of small C programs. I compile and try all of them to see that everything works fine. Unfortunately I need to do the tutorial under Windows. It wouldn’t be a big issue, but whenever I launch an EXE, Avast starts scanning my EXE because it’s suspicious :( I always lose several seconds with this shit. How to disable this “feature”?

Solution
In Avast you can exclude a directory. So I produce my EXEs in the folder C:\work and I told Avast not to scan this directory. Here is how to do it:

Open Avast, select Protection on the left, then select Virus Scans. On the right side you’ll see a small gear (cog) icon, click on it. On the tab “Full Virus Scan”, go down to the bottom and click on “View exceptions”. Click on the button “Add Exception” and specify the folder that you want to exclude (it was C:\work in my case). Done.

Categories: windows Tags: , , ,

TabNine stopped working with Sublime Text

December 21, 2019 Leave a comment

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

Solution
I found the solution here: https://github.com/zxqfl/TabNine/issues/207 . 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: , ,

get the ASCII code of a character

December 21, 2019 Leave a comment
man ascii
Categories: bash Tags: , , ,

image viewer for rotating images

December 14, 2019 Leave a comment

Problem
I needed a simple image viewer with which I could rotate some images quickly. And then, of course, save the images after rotation.

Solution
The image viewer Mirage did the job for me. Under Manjaro, I could install it from AUR.

Links
See https://itsfoss.com/image-viewers-linux/ for a list of alternative image viewers.

Categories: linux Tags: , ,

[rust] fast hashmap

December 4, 2019 Leave a comment

Problem
In Rust, the stdlib’s HashMap is quite slow. It’s secure, resistant against DOS attacks, but slow. If I write a tool that I want to use myself, it doesn’t have to be cryptographically secure. I want it to be fast.

Solution
I tried several alternatives and fxhash proved to be the fastest. I compared the stdlib, hashbrown, ahash and fxhash, and fxhash proved to be the fastest.

Usage
In Cargo.toml:

[dependencies]
fxhash = "0.2"

In your code:

use fxhash::FxHashMap as HashMap;    // after these renames, it can be used
use fxhash::FxHashSet as HashSet;    // as a drop-in replacement

fn main() {
    let mut map: HashMap = HashMap::default();    // !!! it's called ::default(), not ::new()
    map.insert(1, "one");
    map.insert(2, "two");

    println!("{:?}", map);                  // {2: "two", 1: "one"}
    println!("{}", map.get(&1).unwrap());   // one
}

Credits
I asked on GitHub how to have a fast hashmap in Rust, and the author of hashbrown directed me to these crates. As Amanieu explained, FxHashMap and AHashMap are aliases of the stdlib’s hashmap with custom hashers.

Categories: rust Tags: , , ,