Posts

Be careful when you cast

There was a bug which indicated itself when something was saved to sqlite and then queried back. It turned out that we were saving int which got bind to int64 but when binding value in query we (tada!) used unsigned int! The catch could be demonstrated with the following small example: #include <iostream> #include <stdint.h> using namespace std; int main() {   int src = 0xFFFFFFFF;   int64_t x = src;   uint32_t req = 0xFFFFFFFF;   int64_t y = req;   cout << "x = " << hex << x << endl;   cout << "y = " << hex << y << endl;   cout << (x == y) << endl; } x = ffffffffffffffff <- what we are saving y = ffffffff <- what we are searching for 0 In here, x and y get literally the same value but after converting to int64, totally different values get saved to the database! Fix? Bind to int - it's 4 bytes and in this case! And maybe use uints/int more consis...

On Writing Well

The new book on my bookshelf, On Writing Well by William Zinsser. Helps clear up the head a lot in terms of writing. Main thoughts: No clutter - just minimal amount of words for what you want to say Rewriting/editorial is not only normal but essential (example with the real manuscript edits is golden) You are writing for yourself in the first place Write for people, with people In detail: Verbs - active, precise, colorful No redundant adverbs or adjectives Contractions are totally fine (I thought not!) He/she is the real problem: use plurals ('they', 'we') or change wording to address What struck me: just "friends" vs "work friends" + "close friends" (no distinction sounds a lot better!) See a lot in common with writing good code - say only what you want to say, no more, no less.

QTCreator for x86

Historically, we were using 32-bit Ubuntu (16.04) for development and all was good... until we discovered that maximum QTCreator version you can officially get (without building from sources  of course) is 3.5.1 ! Which, while not too bad, had some nasty crashes fixed only in the later versions. And only after some time and luck, we discovered that ubuntu-sdk-ide is QTCreator with plugins. What's important, it gets updated for x86, too! (latest version is 4.1.0 for 16.04) see here . As a result,  sudo add-apt-repository ppa:ubuntu- sdk-team/ ppa && sudo apt update && sudo apt install ubuntu-sdk-ide. Solved!

Failure Is Common

Just read the James Altucher's Choose Yourself . Very inspiring piece of work. Inspiring in a sense that many other books are talking about: failure is not only normal but failure is very-very common. Almost-evident wisdom but still it takes to read many-many books talking about this in one or the other fashion (and heck a lot of practice of failing) to really feel that with your own bones. Great book!

Travelling Idea

When I was driving from Los Angeles to San Francisco, I had to find the place or places where to stay for the night. I was wondering if, given the data from all the people travelling this route, it is possible to find the best places to stay considering few parameters you can choose like "Days travelling - Awesome places to see - Cheapest stay on the route". If you want cheapest trip, algorithm will find the optimal route prioritizing this criteria, or if you want just the route people usually take - see it and decide for yourself whether it is what you want. For example, if booking.com has, for example, lots of data of anonimized user IDs, it should be possible to implement something like that, isn't it? Or there is already such a service and I had just totally missed it?

sqlite + multiprocessing?

Just implemented simple test (mostly using examples from the internet). Yes, sqlalchemy+sqlite crashes when more than one thread is trying to access the database file. Need to move to MySQL to have a few processes (like Tornado) access the DB...

Rabin-Karp Algorithm

Random thought: i t turns out that Rabin-Karp is based on quite simple things - first, knowing the hash function and, second, understanding that the previous hash of the substring could be used to calculate the next one (when including next symbol) in O(1) instead of calculating the next hash anew in O(n).