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

How Not To Encrypt Files With Qt

A recent google search I typed for qt encrypt file led me to Qt wiki only to find how bad encryption can live forever. Let's examine the code there to learn what went wrong. What Is Strong Encryption The first result in my search was of course Simple encryption with SimpleCrypt. Truth must be said they did mention the code described in the page does not offer strong encryption, but they didn't say what strong means in the context, and thus we need to dive in

Read more