How do you create tests for “make check” with GNU autotools

To make test run when you issue make check, you need to add them to the TESTS variable Assuming you’ve already built the executable that runs the unit tests, you just add the name of the executable to the TESTS variable like this: TESTS=my-test-executable It should then be automatically run when you make check, and … Read more

How do I assess the hash collision probability?

Equal hash means equal file, unless someone malicious is messing around with your files and injecting collisions. (this could be the case if they are downloading stuff from the internet) If that is the case go for a SHA2 based function. There are no accidental MD5 collisions, 1,47×10-29 is a really really really small number. … Read more

Why does non-equality check of one variable against many values always return true?

Use &&/AND/and, not ||/OR/or: v != “x” && v != “y” && v != “z” Problem If an if block is always executed, the condition for the if block always evaluates to true. The logical expression must be wrong. Let us consider v != “x” || v != “y” || v != “z” for each … Read more

Is there something like a counter variable in regular expression replace?

FMTEYEWTK about Fancy Regexes Ok, I’m going to go from the simple to the sublime. Enjoy! Simple s///e Solution Given this: #!/usr/bin/perl $_ = <<“End_of_G&S”; This particularly rapid, unintelligible patter isn’t generally heard, and if it is it doesn’t matter! End_of_G&S my $count = 0; Then this: s{ \b ( [\w’]+ ) \b }{ sprintf … Read more

A data structure supporting O(1) random access and worst-case O(1) append?

There is a beautiful structure called an extendible array that has worst-case O(1) insertion and O(n) memory overhead (that is, it’s asymptotically comparable to a dynamic array, but has O(1) worst-case insertion). The trick is to take the approach that the vector uses – doubling and copying – but to make the copying lazy. For … Read more

How exactly do “Objects communicate with each other by passing messages”?

If we are talking about OOP than the term “message passing” comes from Smalltalk. In a few words the Smalltalk basic principles are: Object is the basic unit of object-oriented system. Objects have their own state. Objects communicate by sending and receiving messages. If you are interested in Smalltalk take a look at Pharo or … Read more

How much work should the constructor for an HTML parsing class do?

I normally follow one easy principle: Everything that is mandatory for the correct existence and behavior of the class instance should be passed and done into the constructor. Every other activity is done by other methods. The constructor should never: use other methods of the class with the purpose of using overriding behavior act on … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)