Posts

Mindset

Carol Dweck's book has simple thought: growth vs fixed mindset is the core of learning process, how we face the challenges. Because of simplicity, this thought really feels true. The corollaries of the mindset are huge. Literally - the general path in life we choose when using one mindset or the other. As a father, chapter about praising effort and not the talent in the children is especially helpful (done something very fast and without effort? Then it was too easy for you, let's do something challenging!)

Born A Crime

My first audio book turned out to be amazing childhood stories of south african-born comic Trevor Noah. Totally different experience of a man growing up in different country, sometimes funny, sometimes sad but amazingly true.

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).

Getting POSIX TZ strings from Olson tzdata

Problem at hand: we are having IOT device which does not have the IANA/Olson tzdata package but we would like users to be able to select their time zones from the list, but not enter the TZ string in form of PST8PDT... After a lot of searching, I could not discover the way of obtaining any sort of the TZ string database which would work for most of the cases. The closest I got was the momentjs  JSON data generated from the old good Olson tzdata but, alas, it was still missing the simple TZ strings. Now it was pretty much evident that solution should still somehow include the Olson database but I did not know how. Final step had come up when I actually have taken a look at the tzinfo file format and discovered that in the current version (v2), the TZ string lies right in the end of each file, conveniently separated by the new line symbols at start and in the end! So the final solution for now is: download latest tzdata build it with zone info compiler (or just zic) ...

Visual Studio Code: Fixing Python Intellisense

Today my colleague, Dmitry Efremov, got an issue after installing the latest VSCode and Python extension - intellisense plainly stopped working for all packages except few very basic. After enabling logging for the extension ("python.devOptions": ["DEBUG"] in user settings), it turned out that jedi, tool used for intellisense, fails with the next message in the output: --------------------------- stderr jediProxy Error (stderr) Traceback (most recent call last):   File "completion.py", line 313, in watch   self._process_request(self._input.readline())   File "completion.py", line 294, in _process_request   script.goto_assignments(), request['id']))   File "/home/dmitry/.vscode/extensions/donjayamanne.python-0.3.17/pythonFiles/jedi/api/__init__.py", line 382, in goto_assignments   results = self._goto()   File "/home/dmitry/.vscode/extensions/donjayamanne.python-0.3.17/pythonFiles/jedi/api/__init__.py", line 438, in ...

Kubuntu 16.04 and Dell Inspiron 7559

Problem: Recently, I was more and more than fascinated by development convenience under the modern Linux distributions, not in the last place because I started to use Ubuntu on daily basis at work. So I decided to try Linux on my home laptop (Dell 7559). Options were: Install it as a virtual machine Dual boot At first, I tried installing Ubuntu/Kubuntu inside VM but it turned out to be a bad decision because of the 4K display of the laptop - interface was too slow for the normal usage. I tried both VMWare Player 12 and VirtualBox, tried even setting the scaling of the display in the latter to 200% so Ubuntu will have only 1080p virtual screen but it lagged even more. No go. Then I decided to try the dual boot approach. Luckily, when moving my system to SSD, I had to shrink the Windows partition and had about 200 Gb of the free place in the end of the disk where I decided to put the Kubuntu 16.04. Why Kubuntu? When trying out Ubuntu and Kubuntu inside VM, I found the scal...

AngularJS under lighttpd: fixing 404 error in html5Mode

Problem: If you let angularJS use its nice-url $locationProvider.html5Mode(true), you won't be able to normally refresh the page because all the url changing thing goes on the client side. Solution: The solution is quite simple - use the correct redirections in the lighttpd's rewrite module. For example, you've got four pages in angular stored in subdirectory "/data/" and would like to see them on refresh. Main angular app residing in index.html Here is what your rewrite rules may look like: url.rewrite-once = ( "^(/(?!(page1|page2|page3|page4)).*)" => "/data/$1", "^(/(page1|page2|page3|page4).*)" => "/data/index.html/#/$1", ) Of course, you can have a totally different setup but the idea is simple - exclude all the pages when requesting static html/js/css and route these pages to main angular app's code via "#". Solved!

Converting image to compressed texture (DXT1) using D3DXCreateTextureFromFileEx

Problem at hand was displaying many images as hires textures in 3D scene. Current algorithm was using uncompressed 32-bit pixel format to render which led to the giant amount of RAM consumed for each - 2048 x 2048 x 32bit = 16 Mb. It was not the problem when image count was low (1 to 20) but after image count hit 100, application started to consume more than 2 Gb of RAM and on x86 it had become the source of very real "out of memory" error. The idea of solution was simple - use compressed textures. This way, there will be a ceiling for image count but it will be high enough to satisfy most of the needs. The main questions emerged was how to actually compress textures and which compression format should we choose? Due to engine used, we were limited to DXT1, DXT3 or DXT5 compression formats. Chose DXT1 as soon as it gives the best compression rate (8/1) and its limitations (1-bit alpha) are not critical for our application. The next question, actually how to comp...

ADFS 2.0 - Fixing Broken FederationMetadata

Problem: Active Directory Federation Services's FederationMetadata once failed to be published. Just out of the blue. Whether it was updates or anything but A is A. The usual URL like "https://adfs.server.com:443/FederationMetadata/2007-06/FederationMetadata.xml" was not working so any federated partner will fail to get any changes from local ADFS automatically. After brief search, the reason was found: the Access Control List for FederationMetadata/2007-06/ was removed, hence IIS was redirecting the request to the static file, and not to the adfs service endpoint: >> netsh http show urlacl     Reserved URL            : http://+:80/adfs/services/         User: NT SERVICE\adfssrv             Listen: Yes             Delegate: Yes     ...

Neat way of doing async HTTP request using WinApi

Recently, I needed to implement rather big part of the software based on HTTP requests with C++ and WinAPI. As soon as the old-school blocking APIs are not the way to go in the 2014, I was choosing between COM-based WinHTTP and WinInet. I chose the latest because I read this  (there is a lot more "yes" there on the WinInet side;)) and I software was not a service. So here we go. C-style asynchronous API and OOP. Need to make a wrap, and good one - I will use it later almost everywhere! But how could I do it the best way in the world (I am currently aware of, of course;))? I decided to use the next schema: 1) Any class that needs to make an HTTP request, derives from "AsyncHttpRequest::Host" class 2) "AsyncHttpRequest::Host" class has the special static method making requests and special virtual method used as a callback 3) "AsyncHttpRequest::Host" also should take care of the request creating and destroying, i.e. memory management - to mak...

Lync Server Call Handling and Transfer Using UCMA

Microsoft Unified Communications Managed API? Never heard of it? Yes, it's not that common for programmer to integrate with Lync, especially - its server part. Though I had (still have?) an opportunity to work with it (UCMA 3.0) and now I will tell you one of the interesting stuff I was able to implement using it. I am not talking about really advanced (say, "advanced advanced") things like changing/looking at the SIP headers or implementing custom codecs for media but something more advanced than starting a conference. Here is the scenario: I need to move (transfer) the incoming (dialin) audio call from conference to conference endlessly, with no bounds. Once moved to one conference, you should be able to kick the user to another conference as much times as he(she) desires. For the unpatient, I'll say that the trick here is to use the call self-transfer. But let's get to the sample. Sample is called "Locations" and is freely available at GitHub Wh...

DXGI fast screen capture

Task at hand was capturing desktop or monitor contents under Windows really fast. Actually, the faster is better because the real contents of the buffer I am writing to will be displayed/rendered in real time. There are several options of screen capture in Windows. The oldest and the easiest one is using GDI. The minus of it is that it's really slow. The second way of performing capture is DirectX Graphics Infrastructure - you command video card to store the whole screen or one/several monitors's contents inside separate part of its memory (surface). After that, you can either command video card to draw it somewhere else (for example, on texture). Or lock this surface and copy its contents to the main memory. Looks a lot more promising, huh? Of course I chose the DXGI way! To keep the actual DXGI-based implementation away from the main sources, I had created DXGIManager object incapsulating the actual capture stuff and opened up only a few basic methods: HRESULT SetCapt...

Firefox: building from source and trying out the incremental build

Task at hand on the job required me to understand how does the Mozilla Firefox's plugin system works in detail. Although there is a lot of documentation on the protocol used there (it is called NPAPI ), the task required not only understanding the interface but to have an opportunity to see what data is passing between some plugin and the browser itself. So I decided a pretty straightforward way in here - build Firefox from source and debug browser or have some additional logs added to the source. Building Firefox turned out to be not so scary or complicated - I used the official knowledge base:  https://developer.mozilla.org/en-US/docs/Developer_Guide/Build_Instructions In short: - I chose not to download the zipped sources over HTTP - using source control system looked more appealing in case if there will be any need in rolling back my changes or pulling new changes from the server. I simply cloned the main repo of the Firefox: hg clone mozilla-central - Downloaded ...

Using C# code in C++: CLI

C# codebase on other hand (old project) and the necessity to reuse its code in C++ (WCF, WIF, some SDKs are purely .NET) led our team to the question "how would we be able to reuse this code fast"? Ideas of implementing pipe interface is too clumsy and finding the unmanaged alternatives of the WCF and WIF will take too much time. And here the solution that come up: use the interim C++/CLI library which will use purely managed C# libraries on one hand and will expose purely unmanaged CPP interfaces on the other. Here the sample project is: https://github.com/pgurenko/CLIDemo CLIDemo solution contains three projects: CSharpLib – pure C# assembly with one class we will use from CPP CSharpLibCLR – C++/CLI wrapper for the CSharpLib CLIDemo – purely unmanaged C++ console project using CSharpLibCLR as a statically linked library CLIDemo is creating the interim class, subscribing to events and invoking events/receiving event callbacks using purely man...