March 9, 2023

sed macos pihole networking

Whitelisting with Pi-hole

I set up Pi-hole on my home network, and had the first chance to do some whitelisting. My wife uses Mixpanel for her product’s analytics. After loading up some blacklists, she discovered the next day that Mixpanel was not loading. Mission accomplished! But not in a good way :-\

Here’s what I did to get it working.

First pass

  1. Open the management page for Pi-hole which is on my network.
  2. Whitelist and all subdomains. Really important to check the Add subdomains as wildcard option so that you get a regex whitelist like this: (\.|^)mixpanel\.com$ otherwise it…doesn’t work!

Spot the problem

Now the Mixpanel site loads but there’s barely anything at all on it. I wonder why…

  1. ssh into the pihole: ssh pi@

  2. Tail the log to only what is getting actively blocked by Pi-hole: sudo tail -F /var/log/pihole.log | grep

    1. Better than pinhole -t because you only see the blocked stuff vs. the whole log which is too noisy.
  3. Notice that and similar subdomains are being blocked.

    tailing the pihole log

  4. Add * and all it’s subdomains** to the whitelist.

    regex-based whitelisting subdomains

After clearing the browser cache for the last hour on my wifes computer and refreshing a few times we have success! Mixpanel now loads just fine.

I followed the same process to get search working on my AndroidTV.

sed on MacOS

I want to replace the default title of new Today I Learned (TIL) posts. TIL posts are just markdown files in the content/til directory. Each one in an file in a sub-directory for the date, like 2023-03-07. And in Hugo, that content/CONTENT-TYPE/DATE/ becomes a web page called CONTENT-TYPE/DATE, where CONTENT-TYPE for me is til and DATE is used to create the title of the post as YAML front-matter:

title: 2023 03 23

So, the title for TILs is currently a date in the YAML file, like title: 2023-03-07 but I wanted it to read title: My TIL Post or similar. I added a sed command to find the title text on the second line of the content/til/DATE/ file and replace the whole thing with the title passed in from the command line TITLE="my til post" task til. Unfortunately my first few attempts at using the inplace -i flag for sed failed. It really did not want to replace the contents inline. Stack Overflow to the rescue! Turns out, on MacOS you must provide the -i parameter with a backup file extension so that you can, in a sense, overwrite your current file but only if you also make a backup copy of it first. Ugh.

So if you look in the Taskfile.yaml file now it has the -i.bak argument to make sed on MacOS happy, and then an immediate command to delete the backup file: rm the/path/to/the/

- hugo new til/{{.DATE}}/
- 'sed -i.bak "2s/title.*/title: $TITLE/" content/til/{{.DATE}}/'
- rm content/til/{{.DATE}}/

The final comment: using an environment variable $TITLE in the sed command requires that the entire search-and-replace clause is contained in double-quotes. And so, therefore, the entire command is wrapped in single quotes to make YAML happy.