When programmers get it right

Technology makes our lives better to the extent we don’t have to think about it.  Robert Pirsig makes this point in Zen and the Art of Motorcycle Maintenance, and it’s still true: technology that draws attention to itself has failed (except to a very hard-core audience of which I am probably part 😉 ).

For the last two years, I have been using Google Chrome to view PDFs at work.  Dozens a day, usually with at least five open at a time.  For the last two years, every time I have rotated the view clockwise or counterclockwise, my page has shifted off-screen and I have had to scroll to get back to it.  Has that stopped me from doing my job?  No.  Has it drawn undue attention to the underlying technology?  Yes.  Very yes.

I cannot express my delight at finding, after a recent Chrome update, that I wasn’t the only one with this problem — and that it has been fixed!  I rotated my PDF and reached for the scrollbar, but then I noticed the underlying technology in a good way: I was still looking at the same page I had been.  Now each day is a bit smoother, and my job is a bit easier, because the fix has reduced, rather than increased, my mental workload.

My sincere thanks to everyone involved in pdfium bug 116297.  Special thanks to thestig at chromium.org for making the fix!  If you read this, thestig, please know you have succeeded.

Note to programmers: sometimes small fixes are big wins.  It took thestig two lines of code to save me several minutes of wasted effort per work day, every work day, possibly for the rest of my career.  Fix the small things — your users will thank you!

Minimizing Collateral Damage

This cool article about how software engineer Thanassis Tsiodras rooted his Android tablet reminded me of some things I’ve been thinking about for a while.  We have spent decades learning how to minimize collateral damage in technology.  For example, on Thanassis’s tablet, getting shell access wasn’t enough because the SELinux configuration provided another line of defense.  Why haven’t we applied what we have learned in the tech space to the wider world?

The US elections are tomorrow.  No matter who wins, hundred of millions of people are going to be unhappy.  Let’s revisit how we can apply technological structures and design patterns (not technology itself, for once!) to minimize the collateral damage our leaders do.

I write this now so you’ll know it’s not sour grapes.  No matter who wins tomorrow, I will be working on this series.   Continue reading

An R3G3B2 palette for GIMP, and how to use it.

Part of this answer to a Stack Overflow question by s.gang.

Here’s a GIMP palette file for R3G3B2 pixel packing of RGB images into one byte per pixel.

  1. Copy the below block into a file called “r3g3b2.gpl” somewhere convenient on your disk.
  2. In the GIMP Palettes panel, right-click and select “Import Palette.”  Choose the “Palette File” option and navigate to r3g3b2.gpl: GIMP "Import Palette" example
  3. Open your image as Indexed.
  4. Select the Colors menu | Map | Set Colormap…
  5. Click the palette-name button and then choose “r3g3b2”:Set the colormap of a GIMP indexed image from a palette
  6. Hit Close, then OK, and you should have color!

Note: R3G3B2 is a very low-color-resolution format, so the image will probably look terrible.

r3g3b2.gpl

GIMP Palette
Name: R3G3B2
#
 0 0 0
 0 0 85
 0 0 170
 0 0 255
 0 36 0
 0 36 85
 0 36 170
 0 36 255
 0 72 0
 0 72 85
 0 72 170
 0 72 255
 0 109 0
 0 109 85
 0 109 170
 0 109 255
 0 145 0
 0 145 85
 0 145 170
 0 145 255
 0 182 0
 0 182 85
 0 182 170
 0 182 255
 0 218 0
 0 218 85
 0 218 170
 0 218 255
 0 255 0
 0 255 85
 0 255 170
 0 255 255
 36 0 0
 36 0 85
 36 0 170
 36 0 255
 36 36 0
 36 36 85
 36 36 170
 36 36 255
 36 72 0
 36 72 85
 36 72 170
 36 72 255
 36 109 0
 36 109 85
 36 109 170
 36 109 255
 36 145 0
 36 145 85
 36 145 170
 36 145 255
 36 182 0
 36 182 85
 36 182 170
 36 182 255
 36 218 0
 36 218 85
 36 218 170
 36 218 255
 36 255 0
 36 255 85
 36 255 170
 36 255 255
 72 0 0
 72 0 85
 72 0 170
 72 0 255
 72 36 0
 72 36 85
 72 36 170
 72 36 255
 72 72 0
 72 72 85
 72 72 170
 72 72 255
 72 109 0
 72 109 85
 72 109 170
 72 109 255
 72 145 0
 72 145 85
 72 145 170
 72 145 255
 72 182 0
 72 182 85
 72 182 170
 72 182 255
 72 218 0
 72 218 85
 72 218 170
 72 218 255
 72 255 0
 72 255 85
 72 255 170
 72 255 255
109 0 0
109 0 85
109 0 170
109 0 255
109 36 0
109 36 85
109 36 170
109 36 255
109 72 0
109 72 85
109 72 170
109 72 255
109 109 0
109 109 85
109 109 170
109 109 255
109 145 0
109 145 85
109 145 170
109 145 255
109 182 0
109 182 85
109 182 170
109 182 255
109 218 0
109 218 85
109 218 170
109 218 255
109 255 0
109 255 85
109 255 170
109 255 255
145 0 0
145 0 85
145 0 170
145 0 255
145 36 0
145 36 85
145 36 170
145 36 255
145 72 0
145 72 85
145 72 170
145 72 255
145 109 0
145 109 85
145 109 170
145 109 255
145 145 0
145 145 85
145 145 170
145 145 255
145 182 0
145 182 85
145 182 170
145 182 255
145 218 0
145 218 85
145 218 170
145 218 255
145 255 0
145 255 85
145 255 170
145 255 255
182 0 0
182 0 85
182 0 170
182 0 255
182 36 0
182 36 85
182 36 170
182 36 255
182 72 0
182 72 85
182 72 170
182 72 255
182 109 0
182 109 85
182 109 170
182 109 255
182 145 0
182 145 85
182 145 170
182 145 255
182 182 0
182 182 85
182 182 170
182 182 255
182 218 0
182 218 85
182 218 170
182 218 255
182 255 0
182 255 85
182 255 170
182 255 255
218 0 0
218 0 85
218 0 170
218 0 255
218 36 0
218 36 85
218 36 170
218 36 255
218 72 0
218 72 85
218 72 170
218 72 255
218 109 0
218 109 85
218 109 170
218 109 255
218 145 0
218 145 85
218 145 170
218 145 255
218 182 0
218 182 85
218 182 170
218 182 255
218 218 0
218 218 85
218 218 170
218 218 255
218 255 0
218 255 85
218 255 170
218 255 255
255 0 0
255 0 85
255 0 170
255 0 255
255 36 0
255 36 85
255 36 170
255 36 255
255 72 0
255 72 85
255 72 170
255 72 255
255 109 0
255 109 85
255 109 170
255 109 255
255 145 0
255 145 85
255 145 170
255 145 255
255 182 0
255 182 85
255 182 170
255 182 255
255 218 0
255 218 85
255 218 170
255 218 255
255 255 0
255 255 85
255 255 170
255 255 255

makepal.py

This is the Python script I used to generate r3g3b2.gpl.

#!/usr/bin/python3
# makepal.py: Copyright (c) 2016 cxw. CC-BY.

print("""\
GIMP Palette
Name: R3G3B2
#""")

# Print an R3G3B2 palette
for red in [int(x*255.0/7) for x in range(8)]:
    for green in [int(x*255.0/7) for x in range(8)]:
        for blue in [int(x*255.0/3) for x in range(4)]:
            print("%3d %3d %3d"%(red, green, blue))

# vi: set ts=4 sts=4 sw=4 et ai: #

 

Why Assumptions are Important

Every piece of technology is built to work provided its assumptions hold.  Every piece of electronics, for example, assumes it will have power.  No power => no function (as famously noted by The IT Crowd).  By breaking those assumptions, you can do some amazing things:

In this video (~36 min), scanlime finds exactly the right microsecond to drop the power supply — just enough! — to cause the processor built into a graphics tablet to dump its entire memory over a USB connection.  This is not a function the tablet was supposed to provide!

By painstakingly, scientifically defeating the assumption of a stable power supply, the tablet’s firmware control program, intended to be kept within the tablet, becomes available to inspect.  And, as scanlime points out at the end of the video, that control program may well open other doors.  Analyzing the control program may reveal other assumptions the tablet makes — assumptions that can be broken to change the tablet’s function to what she wants it to be.

Every system is only functional, secure, reliable, or any good at all, as long as its assumptions hold.  Whenever you think about the latest gizmo, don’t just ask what it will do for you.  Ask what it won’t do for you when you least expect it — when the gizmo assumes wrong.

git: showing within-line changes … within a line!

Just found this while looking for a way to show changes within a line rather than on separate +/- lines.  “git diff –word-diff” does the trick!  Thanks to A few git tips you didn’t know about by .

For an extra-clean diff, the final command I used was:

git diff --word-diff --ignore-space-at-eol --patience -b -w --ignore-blank-lines <file1> <file2>

My git installation (version 2.8.3 on cygwin) defaults to a color diff, which makes it extra-easy to read.

Edit: to use this on local files rather than files in your git repo, you can add the “–no-index” option:

git diff --word-diff --ignore-space-at-eol --patience -b -w --ignore-blank-lines --no-index <file1> <file2>

I added an alias called “fsdiff” for this and now can say “git fsdiff <file1> <file2>” for a very nice diff!