Still Slow After Fork

A simple paradigm for speeding up code is to use multiple processes created by fork. Unfortunately this doesn't always work as we can see in the following example. Calculating Tons of MD5 A simple case would be brute forcing MD5. Using Math::Cartesian::Product it's easy to generate all the 5 letter combinations and calculate an MD5 sum from each of them. If we were searching for the sources of the following MD5s: 5d41402abc4b2a76b9719d911017c592 3899dcbab79f92af727c2190bbd8abc5 9aeaed51f2b0f6680c4ed4b07fb1a83c 96e25e3c6373262faae824dc5a16cce1 We could use the following perl program to brute

Read more

Fixing Legacy Perl Functions With Decorators

Function decorators give us a way to modify a function's behaviour without changing its source. This is useful in changing the behaviour of complex or legacy functions that you don't want to touch. Although perl does not have a built-in syntax for creating or using decorators, typeglob manipulations are used to easily fill the gap. Reasons To Decorate Take the following implementation for fibonacci calculating function: sub fib { my ($n) = @_; print "DEBUG - calculating fib($n)\n"; $n < 2 ? 1 : fib($n-1) + fib(

Read more

Tutorial: Writing Multi Threaded Application in Qt

Like most GUI frameworks, event handling in Qt by default happens on the main thread. This works well for small UI related changes, but breaks when we have to perform more work. In this tutorial we'll write an image converter application that uses background worker thread to perform CPU intensive operation while keeping the GUI responsive. We'll also discuss processEvents and its advantages and disadvantages comapred with background thread. A Single Threaded Image Converter Our simple image converter will allow the user to select image files

Read more

A Simple CMake + Qt Widgets Starter Template

Starting a new Qt project in Qt creator is a breeze thanks to its built-in templates. But, what about those times you prefer working from terminal or vim? Here's my starter template for QtWidgets + CMake. Feel free to use and expand for your own needs. tl;dr My CMake + Qt Widgets starter template on Github: https://github.com/ynonp/qt-widgets-template Or as a zip file: https://github.com/ynonp/qt-widgets-template/archive/master.zip Building Instructions To build the template you'll need to have Qt installed and

Read more

Adding Negative Indexes to JavaScript Arrays

Every time I return from ruby/python to JavaScript I'll fall into the same mistake of writing arr[-1] and not getting the last item. JavaScript has a weird way of stringifying object keys which leads to stringifying array indexes which renders the above nonsense there. Luckily JavaScript is also great at monkey patching, so let's see if we can fix negative indexes there. Take 1: -1 Is A Valid Index Since JavaScript stringifies keys -1 is just as valid array index as foo, bar, 2

Read more