Tag Archives: bash

Meh Practices Mental Note: Add Category

My did to help me remember what I did

This article was making the rounds this week: did.txt file. Lately, I’ve been having trouble remember what I did, so the timing of that post was perfect.

In the past, I’ve been able to do this in git like git reflog --since yesterday --decorate --author $(git whoami), but these days I’m in many Git repos and a lot of my work isn’t code, so the `did.txt` solution looked great. But following my slogan, “do the same thing you’ve already done, unless you can do it lazier”, I came up with an even lazier method. In my dotfiles, I have this bash function:

# Inspired by https://theptrk.com/2018/07/11/did-txt-file/
did () {
 mkdir -p ~/Documents/did
 if [ -n "$*" ]; then
   touch ~/Documents/did/"$*";
 find ~/Documents/did -type f -printf "%TY-%Tm-%Td %TH:%TM\t%P\n" | sort -nr | head -n 10

You use it like:

$ did Printed my TPS report
$ did Re-printed my TPS report with the new cover sheet

And you use the same command with no arguments to get what you did:

$ did
2018-07-18 10:59 Re-printed my TPS report with the new cover sheet
2018-07-18 10:27 Printed my TPS report


You have to be careful what you type. For example, in “did 10/10 tasks”, the “/” gets treated as a directory separator instead of a forward slash. There’s ways around this but I haven’t found one I like yet.

Eventually, I’ll have to clean out my ~/Documents/did, but that’s just deleting old files. It’ll be fun to relive what I was doing. If it actually becomes a problem, it can be automated too.

A duplicate update erases the earlier entry. In real life, this won’t happen much. And if it does happen, you don’t want the duplicates anyways. I see this as a feature.

OSX users

find on OSX doesn’t have -printf, so you’ll need brew install findutils. I recommend just running it like brew install findutils --with-default-names so find just works the way you expect it to.

Best Practices Patterns

Patterns: don’t mess up the prod db!

With 12factor style environment configs, it’s a very easy to accidentally connect to your production database when you think you’re connecting to dev. Here’s a simple guard you can add to make sure your  DATABASE_URL isn’t somehow pointed to someplace it’s not supposed to (assuming you’re using Amazon AWS):


if [[ ${DATABASE_URL} == *"amazonaws"* ]]; then exit -1; fi


if 'amazonaws' in os.environ['DATABASE_URL']:
   exit('Cannot be run against a production database')


if 'amazonaws' in settings.DATABASES['default']['HOST']:
    raise CommandError('Cannot be run against a production database')

(thanks to x110dc for the bash syntax and 12factor link)

You didn't say the magic word

Life=Boring Nerd

Weekend^H^H^Hday Hack

So today, being stuck in the house, I decide I should streamline some of my things in the unix world. So I picked up some BASH scripting. I got some serious flashbacks to the 90’s. I would have flashed back earlier, but I’m not old enough. It really makes you appreciate the UNIX geeks of yesteryear. Those guys were clever. And this code looks ugly. But it could be worse… I could be doing MUMPS.

Some sites that aren’t Google I found helpful:

And some random grep links: