Kae Job Sluder

July 2024, Catchup and Quick Ideas

Catching up after a few months of big life and family changes. Some of what I've been working on includes punting on a bit of yak shedding (over-optimizing process instead of real work), giving up on DIYing everything, and focusing on paid gig work.

/etc/hosts blocking with ex

I like to block certain websites when I'm doing deep focus work or have problems getting into a groove. A simple way to do this on Linux is the /etc/hosts file. This file maps host names to IP numbers, overriding DNS queries where appropriate. For example, the following lines map reddit hostnames to the special IP number 0.0.0.0.

0.0.0.0   www.reddit.com
0.0.0.0   reddit.com

Probably about once a week, a web search will point to a resource on reddit that might be useful. Quick one-liners to enable and disable this are:

# enable filter
# Run ex with the following commands:
# 1. pick all lines with 'reddit' anywhere on the line
# 2. substitute start of line '^' with '# '
# 3. save and quit ('w')
sudo ex -c 'g/reddit/s/^/# /' -c 'wq' /etc/hosts

# disable filter
# Run ex with the following commands:
# 1. pick all lines with 'reddit' anywhere on the line
# 2. substitute '^# ' at start of line with nothing.
# 3. save and quit ('wq')
sudo ex -c 'g/reddit/s/^# //' -c 'wq' /etc/hosts

Why ex? ex is just vi/vim in 'script mode' or 'command mode'. The commands used here are the same as vim commands. You can do something similar with any scriptable text-editing tool. vi/vim just happens to be familiar for me. And I've found significant compatibility issues with sed between bsd (MacOS) and gnu (Linux and others).

neovim didn't come with an ex alias on my system, but similar scripts can be performed with:

nvim -u NONE -es -c '{commands}' {filename}

Apps that I can do in other ways but I feel the need for additional scaffolding.

'AI' and regex

A lot of my gig work involves doing code reviews for AI-produced code. An area where I almost always see AI struggle is using regex. I think some of the reasons are:

  1. Not fully understanding the context of the problem
  2. Too many regex variations
  3. Absurdly compact syntax
  4. Low quality of regex code examples (backtracking, edge cases, nesting, groups).

To be fair, writing regex is difficult for humans for many of the same reasons.