Category Archives: Articles

Compressing a PDF file on macOS

Sometimes people create PDF files with large images, resulting in files that are too large to email or sometimes even upload on web forms.

A quick and dirty way to compress such files is using ghostscript in a terminal, which you can install on macOS using homebrew (brew install ghostscript):

gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/screen -dEmbedAllFonts=true -dSubsetFonts=true -dColorImageDownsampleType=/Bicubic -dColorImageResolution=192 -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=144 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=144 -sOutputFile="${1%.*}.compressed.pdf" myfile.pdf

Replace “myfile.pdf” with the file to compress.

For convenience, you can create a function:

pdfc() {
  command gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/screen -dEmbedAllFonts=true -dSubsetFonts=true -dColorImageDownsampleType=/Bicubic -dColorImageResolution=192 -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=144 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=144 -sOutputFile="${1%.*}.compressed.pdf" "$1"
}

Use like so:

pdfc myfile.pdf

And a smaller pdf file will be written to myfile.compressed.pdf.

This isn’t without cost. The resulting PDF file will contain lower resolution images which have less detail and will look worse zoomed in, but you can tweak the resolution settings to see what works for you. Generally I find the above settings acceptable for most documents at normal reading size. It will reduce a file with 3 large images captured with a phone from 6Mb to around 100Kb.

Home Server – new HBA edition

Some long time readers of this blog may remember my home server articles, the most recent being “Ubuntu Home Server 14.04 – A DIY NAS“. There haven’t been any more recently because there’s not been much to report. The server described in that article, built in 2014, has been backbone of my home network ever since.

Since then, I have swapped out hard drives a couple of times (it now contains 2x16TB Seagate Exos and 4x4TB Seagate IronWolf), doubled the ram to 8GB, and added a NVME riser card (along with a cheap 128GB NVME SSD), so I could have a separate boot drive while using all 6 SATA ports for hard drives.

Along the way it also lost HTPC and media player duties to an Apple TV, so now it’s little more than a file and backup server with Plex Media Server, Syncthing, and Duplicati installed. And the operating system has been upgraded from Ubuntu 14.04 to 16.04, 18.04, 20.04 and now 22.04.

A couple of weeks ago though, it failed. And by failed I mean, all I got was blank screen when powering on. No post, and no signs of life other than spinning fans.

My immediate thought was a loose connector, or possibly memory or motherboard failure, so I disconnected everything, blew the dust out and plugged everything back in. With the hard drives unplugged, everything worked. With 4 hard drives plugged in it still worked. Then it failed again when I connected the last two.

By now I figure I’m looking at a dodgy SATA cable, SATA port, or hard drive, but the core components are obviously fine. So why not give it a minor overhaul at the same time?

Continue reading

How to run an ethernet cable in your home, and save your relationship

My partner and I live in a 2-bedroom flat with our very young daughter. After a couple of weeks of working from the living room, which is where the WiFi is, and where I typically keep my computer, I decided, for the good of our relationship, to move my office to the spare bedroom.

There’s just one problem:

I can connect to the Wifi, but performance is abysmal

I’m not alone in spending a lot more time working from home recently, and if my Slack calls at work are anything to go by, I’m also not alone in struggling with poor WiFi reception. Urban areas tend to be densely packed with WiFi signals at the best of times, let alone while everyone’s cooped up at home full-time.

In my case, the WiFi connection in the spare bedroom is totally unusable for work, but continuing to work from the lounge would risk my relationship (and possibly my general safety).

So what’s a self-isolating telecommuter to do?

Continue reading

Guide to Buying a Dell Latitude Laptop on eBay

It’s hard to go past eBay for a second-hand laptop (full disclosure – I own some shares in eBay). There’s a huge range, and it tends to be the outlet of choice for ex-corporate machines which are replaced on a regular cadence – more regularly than most consumers would replace theirs.

But buying a second-hand Latitude can be a bit of a lottery if you don’t know what you’re getting, as the lines are confusing with many different models. Here I’ll try to break it down, so you can make a more informed decision.

I’ve focused on small and light models, as that is what I bought for myself and thus was what guided my research. If you’re interested, check out my article on upgrading to a Latitude 7300 from a Macbook Pro.

Continue reading

The 80/20 Rule Applied to Personal Finance

It’s hard to watch The Big Short, and not come away thinking that the odds are stacked against you as a would-be individual investor. It’s a great film that makes some very valid points, but leaves you thinking.

Surely if there are all these hedge funds that mismanage their clients’ money, and getting a seat at the big-boy’s table requires vast amounts of capital, there’s a gap in the market for cooperatively run mutual funds that actually act in their clients’ interests?

It turns out that there are already companies in this space, but the chances are you wouldn’t hear about them from a financial advisor.

Continue reading

Improving your privacy with a custom email domain

This blog post is a follow-up to It’s Time to Ditch Gmail. It began as a review of Fastmail, and my experience of moving to it from Gmail, but I quickly found myself going on a tangent. Since privacy was the main driver in my decision to move to Fastmail, and using a custom domain is one of the ways that I protect my privacy, I figured it was important enough to warrant its own post.

One of the factors that made it easier to move away from Gmail is my use of a custom domain for most of my mail. Before moving to Fastmail, this domain was tied to a GSuite account which forwarded everything to my standard Gmail account. This made switching in anger much easier, as I had fewer accounts to log in to and update my email address, and those that were still pointing directly at Gmail tended to be older low-value accounts that I no longer use anyway.

In this article though, I want to take a detour to explain why I use a custom domain, and how it can aid your privacy. Continue reading

Provisioning Vault with Code

A couple of years ago, Hashicorp published a blog post “Codifying Vault Policies and Configuration“. We used a heavily modified version of their scripts to get us going with Vault.

However there are a few problems with the approach, some of which are noted in the original post.

The main one is that if we remove a policy from the configuration, applying it again will not remove the objects from Vault. Essentially it is additive only, and while it will modify existing objects and create new ones, removing objects that are no longer declared is arguably just as important.

Another problem is that shell scripts inevitably have dependencies, which you may not want to install on your shell servers. Curl, in particular, is extremely useful for hackers, and we don’t want to have it available in production (in our environment, access to the vault API from outside the network is not allowed).

Finally, shell scripts aren’t easy to test, and don’t scale particularly well as complexity grows. You can do some amazing things in bash, but once it gets beyond a few hundred lines it’s time to break out into a proper language.

So that’s what I did.

The result is a tool called vaultsmith, and it’s designed to do one thing – take a directory of json files and apply them to your vault server.

Continue reading

Building and Packaging a Python command-line tool for Debian

python-logo-notext-svg

Python packaging has a chequered past.

Distutils was and still is the original tool included with the standard library. But then setuptools was created to overcome the limitations of distutils, gained wide adoption, subsequently stagnated, and a fork called distribute was created to address some of the issues. Distutils2 was an attempt to take the best of previous tools to support Python 3, but it failed. Then distribute grew to support Python 3, was merged back in to setuptools, and everything else became moot!

Unfortunately, it’s hard to find reliable information on python packaging, because many articles you might find in a Duckduckgo search were created before setuptools was reinvigorated. Many reflect practices that are sub-optimal today, and I would disregard anything written before the distribute merge, which happened in March 2013.

Continue reading

Kiwis, London, and expectations

Recently there’s been a conversation in the expat community about Kiwis making the move to London. Alex Hazlehurst’s article, which set out to dispel the myth that finding a job in London is easy for kiwis, attracted a fair bit of commentary (she also has a nicely designed blog here). Some of it was nice, some not so nice, and one reply was well written but somewhat condescending.

This conversation is not about people coming for an extended holiday. It is not about coming to London on the two-year visa, with nothing but travel plans and maybe a bit of bar or temp work here and there. It’s about young Kiwis moving to London to start or continue their careers, as I and many others have done. Continue reading

Ubuntu Home Server 14.04

I had grand intentions.

This home server article was to be a detailed masterpiece, a complete documentation of my home server setup.

It hasn’t turned out that way, and many pieces are missing. Turns out, that writing a detailed article on setting up a server is much harder than just doing it! So what you see here is what I finally managed to publish, 5 months after actually building it. I hope you find it useful, and I don’t rule out the possibility that I may update parts of it in future. Continue reading