A notch above a monkey

Windows

I got a new travel computer this week and so far it is pretty much what I wanted. Nice enough to carry and use, but also faulty and affordable enough that I would not be too upset if something happened to it.

It came with Windows 10 which I have decided to keep so I can use Edge for testing. It is much nicer than abomination that was 8 and I also applaud Microsoft's accessibility work. Although, personally, ballooning whitespace and interface until everyone can read only one line of text at a time, be it on an actual screen or a screen reader, would not be one of my ways of reducing the experience difference in using the system.

I appreciate little touches such as marking connections as metered (and hence off limits for certain traffic) or workaround for updates installation. I still have no idea when updates sneak on me, but at least now I can choose a restart that ignores them.

On the other hand it is really difficult to find out where disk space went and almost impossible to reduce its use significantly. In theory it should be fine with 20GB, in practice I can't get it bellow 30. On top of this Windows defragmenter refuses to move certain used bits and condemns me to a much larger Windows partition than I would pick willingly.

I complain, and it really does bother me, but truthfully it is really not that bad. I think it is actually the best Windows so far that I will not use and certainly a lot better than versions I used long long, my god how long, time ago.

Web skills

While following news about Brexit developments and its impact on FTSE100, my wife and I wondered how many people work for companies that are included in that index. Wikipedia provides a list of FTSE100 companies including their employees numbers, but without the total that interested us.

I did not feel like summing them manually as it is tedious, slow and error prone. Luckily I do not have to as this is a nice example how we can use even limited web development skills to solve every day problems.

All I needed to do is select table cells in last column, transform their values to numbers that Javascript understands and sum them.

On a modern browser this can be accomplished by opening developer tools and executing two lines of code in its console:

var nodes = [].slice.call(document.querySelectorAll("#constituents tbody td:last-child"));
nodes.map((a) => parseInt(a.innerText.replace(/,/g, ''), 10)).reduce((a, b)=> a+b, 0);

What the first line does is select last table cell (td:last-child) in each company row of the table (#constituents tbody). [].slice.call is used to make the resulting list a Javascript array because it is easy to work with.

In second line we first transform the list of page elements to a list of cell values, by picking them with .innerText, removing comma separators (.replace(/,/g, '')) and changing them to numbers using parseInt. This is immediately followed with a call to reduce which sums all the values in our list.

Alternatively I could have also used jQuery library already included on Wikipedia pages and not much more code to get to the same result.

Turns out that according to Wikipedia there are 5,618,496 people working for FTSE100 companies out of 31.59m in total.

image-diet2 and pyimagediet

Couple of years ago I hacked together a small Django app called image-diet which automatically compresses images processed by Easy Thumbnails as they are uploaded to a website. Its code was atrocious with configuration for external tools baked in, it only worked with Easy Thumbnails and Python2 and...I could go on, but it worked and at Aptivate we have been using it successfully ever since.

Well, I finally found time and rewrote the whole thing. New version is now called image-diet2 because it is completely backwards incompatible and I screwed up versioning of the original one. Mea culpa.

It's implemented as a Django storage backend augmenting default one, but can easily be added as a mixin to any other so it should work no matter which tool or backend you use to upload files. Supporting new compression tools or changing configuration of existing does not require a new release or poking in virtualenv anymore. It is better tested, documented and is not limited to 2.x branch of Python anymore. You really should give it a try.

image-diet2 is actually a thin Django wrapper around separately packaged pyimagediet that actually process files. My hope is that others may find it useful enough to use it on non-Django projects. It also comes with a tool to compress images and generate configuration file tailored to your system. If you can think of anything else that would make integration even easier, then please let me know.

There are few bits still missing, but functionality is mostly complete. What I plan to do next is to test different configurations to find how well they work and what are their tradeoffs. Prior useful work such as this exists, but I'd like tests to be more expansive and in reusable format. They need to be easily replicable by anyone as their versions of processing tools might give different results than mine.