Grabbing an SSL certificate from a remote server

There are moments when you need to inspect the certificate a remote server is presenting – maybe it’s expired and you’re trying to work out why things are breaking, or maybe you need the raw certificate data for some other reason and don’t have access to the server’s configuration. The quickest way is with openssl s_client: openssl s_client -connect {HOSTNAME}:{PORT} -showcerts Replace {HOSTNAME} with the server address and {PORT} with the port (usually 443 for HTTPS). The -showcerts flag dumps the full certificate chain rather than just the leaf certificate. ...

15 June 2021 · 1 min · 149 words · Shafiq Alibhai

No good deed ever goes unpunished

“No good deed ever goes unpunished.” I’ve said this more times than I care to admit, usually in the aftermath of trying to help someone and ending up with more problems than I started with. It’s a peculiar thing – the people you’d expect to be grateful are often the ones who punish you most for trying. I think about my parents sometimes, how every time I offer to sort something out or take on a burden, it somehow spirals into getting used. The intention is never in doubt but the outcome always ends up feeling used. ...

21 May 2021 · 1 min · 212 words · Shafiq Alibhai

The advantages you've had

“Whenever you feel like criticizing any one, just remember that all the people in this world haven’t had the advantages that you’ve had.” – F. Scott Fitzgerald, The Great Gatsby I read this somewhere and it stuck with me because it’s true in a way that feels obvious until you actually try to live by it, and even then it’s hard. We all have advantages we never asked for and rarely notice – the kind of things that just make life slightly easier, like being born into a family that didn’t struggle to put food on the table, or having parents who went to university and could help you with homework without feeling lost themselves, or arriving in a country where you speak the language and look like most of the people around you. None of these things were earned. They just happened. And they add up in ways that are impossible to quantify but impossible to ignore. ...

20 May 2021 · 2 min · 364 words · Shafiq Alibhai

Replace all dots in filenames except the extension on Linux

Had a directory full of files with dots in the names and needed them all cleaned up. Something like my.report.final.pdf should become my_report_final.pdf, not my_report_final..pdf or worse. This one-liner does the job: for f in *; do pre="${f%.*}"; suf="${f##*.}"; mv -i -- "$f" "${pre//./_}.${suf}"; done Here’s what each part does. ${f%.*} strips everything from the last dot onwards, giving you the filename without its extension. ${f##*.} grabs just the extension by stripping everything up to and including the final dot. Then ${pre//./_} replaces every dot in the base name with an underscore. ...

21 January 2021 · 1 min · 146 words · Shafiq Alibhai

Count directories in the current folder with a one-liner

A common question that comes up when you’re first getting comfortable with the command line: how do you count just the directories in your current folder? The quick answer is: ls -1 | wc -l This pipes a one-per-line listing of everything in the current directory into wc -l, which counts lines. Simple enough. But there’s a catch. This counts everything – files, symlinks, hidden items, the lot. If you only want directories, you need to be a bit more selective. ...

14 July 2020 · 1 min · 188 words · Shafiq Alibhai

Count files in a directory with a one-liner

Another quick command line question: how do you count just the files in a directory, excluding subdirectories and other stuff? The classic answer: ls -l . | egrep -c '^-' This lists everything in long format (ls -l), then counts lines that start with a hyphen – which is how ls marks regular files. Directories show up as d, symlinks as l, and so on, so the regex filters them out. It works, but it’s a bit of a trick and relies on understanding ls output format. A more straightforward approach uses find: ...

14 July 2020 · 2 min · 213 words · Shafiq Alibhai

'Installing Multiple PHP Versions on Debian 9'

Sometimes you need more than one PHP version on the same server. Maybe an old project still runs on 5.6, another one needs 7.2, and you want to test something on 7.4 before committing. Debian’s default repositories only ship one version, so you need a third-party source. The Sury repository is the standard way to get multiple PHP versions on Debian. Ondrej Surý has maintained it for years and it’s trusted by most people running PHP on Debian. ...

14 July 2020 · 2 min · 387 words · Shafiq Alibhai

Fix casks with `depends_on` that reference pre-Mavericks

If you get an error like Error: Cask 'hex-fiend-beta' definition is invalid: invalid 'depends_on macos' value: ":lion", where hex-fiend-beta can be any cask name and :lion any macOS release name, run the following command: /usr/bin/find "$(brew --prefix)/Caskroom/"*'/.metadata' -type f -name '*.rb' -print0 | /usr/bin/xargs -0 /usr/bin/perl -i -pe 's/depends_on macos: \[.*?\]//gsm;s/depends_on macos: .*//g' This strips out all depends_on macos references from installed casks. It’s a blunt instrument – you’re editing Homebrew’s metadata files directly – but it gets things working again. ...

18 May 2020 · 1 min · 110 words · Shafiq Alibhai

How to run VLC player as root user

I ran into this a while back when I needed VLC running as root on a headless server, and the usual --no-sandbox flag didn’t cut it. VLC refuses to start as root by default, which makes sense from a security standpoint but is annoying when you actually need it. The fix is brutal and hacky, but it works: sed -i 's/geteuid/getppid/' /usr/bin/vlc What’s actually happening here? VLC’s startup script checks whether the effective user ID is zero (root). If it is, it bails out. By swapping geteuid with getppid, we’re telling the script to check the parent process ID instead of the effective UID. Since getppid() returns a number way bigger than zero, the check passes and VLC starts. ...

18 May 2020 · 1 min · 168 words · Shafiq Alibhai

A lawyer's Christmas greeting

Please accept with no obligation, implied or implicit, my best wishes for an environmentally conscious, socially responsible, low-stress, non-addictive, gender-neutral celebration of the winter solstice holiday, practiced within the most enjoyable traditions of the religious persuasion of your choice, or secular practices of your choice, with respect for the religious/secular persuasions and/or traditions of others, or their choice not to practice religious or secular traditions at all… and a fiscally successful, personally fulfilling, and medically uncomplicated recognition of the onset of the generally accepted calendar year 2019, but not without due respect for the calendars of choice of other cultures whose contributions to society have helped make the United Kingdom great (not to imply that the United Kingdom is necessarily greater than any other country or is the only “United Kingdom” in the Northern hemisphere), and without regard to the race, creed, colour, age, physical ability, religious faith, or sexual orientation of the wishee. ...

31 December 2018 · 2 min · 364 words · Shafiq Alibhai