instasort 4.0.1

in code


One bad programmer habit of mines is that I tend to duck type when there isn’t a strict need. I ask whether the object doesn’t fit conditions, or evaluate it against some rules, at times when I have the ability to check its actual type. I thusly duck typed images in the previous version of my instasort shell script when I asked: is the image square? Instagram images are square, therefore a square image is an Instagram image.

i r logic

My assumptions led to a whole bunch of false positives in results, because Instagram images are no longer square, and sometimes I take square images anyhow. I poked into the problem this morning and discovered I could test the exif:Software key:

# Was File Created by Instagram?
#
# @example
#
#   exif:Software: Instagram
#   exif:Software: Layout from Instagram
#   exif:Software: 10.3.1
#
# Files created by Instagram will be marked so in EXIF. I downcase the exif:software
# value and test it against 'instagram'.

function is_instagram {
    local SOFTWARE=$(identify -format '%[exif:software]' $1)
    [[ ${SOFTWARE:l} =~ 'instagram' ]]
    echo $?
}

So there you have it: assumptions are bad. You can find the less-assuming version of instasort here on GitHub.



Replace Odd Numbers of Spaces Only

in code


Your email address will not be published. Required fields are marked *