One of the frustrating things about computers is their limited input options. A "standard" PC keyboard only has about 100 keys. Sure, some have some bonus buttons for controlling the machine, but it is becoming clear that there simply aren't enough buttons to efficiently program computers. Most programming languages have the concept of relational operators. How does variable X compare to variable Y? If we want to ask if X is less than or equal to Y, we write X <= Y. Which is a bit weird,…
Continue reading →
An idle thought on a long weekend. Is it possible to create an executable binary which is a palindrome? It's trivial to create a palindromic program in, say, Python: print("hello") # )"olleh"(tnirp Save that as test.py and then run cat test.py | rev | python3 and it'll work. But that's boring! You could do the same by reversing the bits, rather than the characters: 01110000 01110010 01101001 01101110 01110100 00101000 00100010 01101000 01100101 01101100 01101100…
Continue reading →
Given a social media user's username, how do you get a picture of their avatar? I always used avatars.io - but sadly that service has bitten the dust. So I've switched to unavatar. It's dead easy to use. https://unavatar.now.sh/twitter/edent will return @edent's avatar. You can use GitHub, Facebook, Gravatar, Instagram, Telegram, YouTube, SoundCloud, and a couple of other providers. Simple to use, and easy to embed in an <img> element. It's also open source and looks pretty easy to deploy …
Continue reading →
Back in the 1980s, when my family first got a micro-computer, there were only limited ways to program your machine. The Internet was basically non-existent for domestic users. You could buy thick computer manuals, swap cassettes with other enthusiasts, or build a light pen and point it at a flashing square on your TV (Really!) Or, you could go down to your local newsagent, buy a magazine, and laboriously hand-type in a code listing. Sometimes, they would look like this: Yikes! Ah, but…
Continue reading →
I made a little girl cry recently. "But why do I have to learn Python?" She wailed, "I like Scratch!" "I know," I said, "But there are different programming languages for different sorts of tasks." "That's stupid" she said, with all the perception of 6 weeks Code Club experience. "You can do everything in Scratch." I found it hard to argue with the twelve-year-old - you can do just about anything with the child-friendly Scratch programming language. You can even build an entire Operating…
Continue reading →
(For more about the "Falsehoods" meme - read the big list of falsehoods programmers believe.) Do You Want To Phone A Friend? A popular website asked me to confirm my phone number. It "helpfully" pre-filled the country-code with +1. And proudly displayed the Stars and Stripes. Except, of course, the USA isn't the only country to use +1 - our friends in the Great White North also use +1. Thanks to the North American Numbering Plan, a full 25 countries or territories use +1. From …
Continue reading →
As ever, mostly notes to myself. I have a bunch of old images which don't have any timestamp associated with them. This quick Python script will add a DateTime EXIF metadata tag to an image. This uses piexif which can be installed using pip install piexif This simple script reads a photo, adds a timestamp, then saves a copy of the new photo. from PIL import Image from PIL.ExifTags import TAGS import piexif from datetime import datetime im = Image.open("test.jpg") exif_dict =…
Continue reading →
A warning to programmers - try to understand how people will use your error codes. This morning, I was confronted with a rather bemusing error message on my WordPress blog: Ok, so this should "never happen" and yet somehow it has. I wonder what on earth the error code means? I selected the error code and Googled it! I just copied and pasted the error message into Google and got back a set of meaningless results. Why? Most search engines treat the minus sign as an "excludes" operator. …
Continue reading →
There was an interesting discussion on HackerNews last week about the Linux Kernel coding style. During the discussion, I kicked off a minor holy war about whether one should vertically align code. I'm all for it! Let me explain why. What Is Vertical Alignment? Take this trivial example: int robert_age = 32; int annalouise_age = 25; int bob_age = 250; int dorothy_age = 56; I find easier to read as: int robert_age = 32; int annalouise_age = 25; int bob_age = 250; int…
Continue reading →
Update! There's a new way to do this - read my latest post to find out how. Two or three years ago, I was contacted by a recruiter from Google. They wanted to know if I'd be interested in working for the advertising giant. We played the usual game of dancing around salary and schedules, when he dropped the bombshell - they were looking for people to work on Google+. I asked the recruiter if he'd seen my G+ profile. At the time, it had this childish scrawl all over it. We mutually…
Continue reading →
Like many people, I've collected a fair number of CDs over the years. As hard-drives and MicroSD cards have got larger and cheaper, I've gradually been ripping them to FLAC. Most CD rippers automatically tag the music files with the correct metadata and, nowadays, they will also download and embed album artwork as well. (As an aside, it always boggled my mind that CDs don't come with metadata burned onto the disc. Even a single spare megabyte would be enough to hold detailed track listing,…
Continue reading →
How much checking do we perform that our code is running as intended? I found a curious bug this weekend, which made me think about some of the assumptions that we use when programming. Imagine sorting an array using JavaScript. var arr = [10, 5, 66, 8, 1, 3]; arr.sort(); So far, so normal. Create an array of numbers, then sort that array. The result should always be [1, 3, 5, 8, 10, 66]. Would we ever need to do this? if (arr[0] < arr[5]) { // Do something } else { // THIS SHOULD …
Continue reading →