This is a running list of things that I’ve learned. Sometimes they are particular technical facts. I’m a neophyte in a lot of areas; so of these things will seem quite mundane. Sometimes they are more conceptual. Maybe someone will find them useful. Maybe that someone is my future self.

Tuesday, November 22, 2022

Wednesday, February 17, 2021

A couple of terms that deal with perceptual distortions and cognitive bias:

  • apophenia - a tendency to see connections between two unrelated things.
  • pareidolia - the faulty perception of a pattern in an image, e.g. seeing a face in a geologic formation on Mars.

Pareidolia is a specific form of apophenia.

Friday, January 29, 2021

Custom aliases in oh-my-zsh

With oh-my-zsh, you can store custom aliases in multiple (?per application) file under .oh-my-zsh/custom giving them .zsh file extensions.1

¶For example, in my hugo.zsh file, I have:

alias hnewtil="/Users/alan/Documents/blog/ojisan/scripts/newtil.sh"
alias gtojisan="cd /Users/alan/Documents/blog/ojisan; ls -l;"

Executing inline Python in a shell script

It’s possible using the -c command.2

python -c 'import foo; foo.bar()'

  1. https://scottwhittaker.net/posts/oh-my-zsh-custom-aliases/ ↩︎

  2. https://stackoverflow.com/questions/16908236/how-to-execute-python-inline-from-a-bash-shell ↩︎

Thursday, January 28, 2021

A bunch of Unix date scripting things

Unix shell scripting is not one of my better-know areas of programming, but it’s on my list of things to learn. Some interesting bits about the date function.1

  1. Want the long date, like Thursday, January 28, 2021? → date +"%A, %B %d, %Y"
  2. Want something like the above but with abbreviated month Thursday, Jan 28, 2021? → date +"%A, %b %d, %Y"
  3. Time zone in the format of "-05:00" on macOS is:

tz=$(date +"%z" | sd '(\d{2})(\d{2})' '$1:$2')
echo $tz
  1. Long date in the format of 2021-01-28T05:30:48-05:00 that is use by Hugo2:
tz=$(date +"%z" | sd '(\d{2})(\d{2})' '$1:$2')
md_date=`date +"%Y-%m-%dT%H:%M:%S"`
  1. Speaking of dates, this reference has very detailed information on date and time in the Unix shell.
  2. Date in the format of 2021-01-28 is date +"%Y-%m-%d"

Unix slurp command output into a variable

In the UNIX shell, slurping the output of the command into a variable is done this way:3

OUTPUT=$(ls -1)
echo "${OUTPUT}"

echo "${MULTILINE}"

Append or overwrite a file in Unix shell

You can either append to a file or overwrite the contents from the shell.4

To append to a file, it’s echo "hello" >> file.txt whereas to overwrite the contents of a file, it’s echo "hello" > file.txt

Function Symbol
Append >>
Overwrite >

  1. This all pertains to the macOS flavour of the Unix shell. There are important differences, seemingly in the date function, for example. ↩︎

  2. I should know what that format is called, but I don’t. I think it’s ISO 8601. Also, this requires sd. If you don’t have it, you’d need sed instead. ↩︎

  3. Source - Stack Overflow ↩︎

  4. Source - Stack Overflow ↩︎

Wednesday, January 27, 2021

W3schools.com has a CSS library that’s quite nice. I often use Bootstrap; but I like some of the visual features here better. For example, I like their tags because they have more flexible use of colour.

If you want to fetch from a Python dictionary, but you need a default value, this is how you do it:

upos_badge = {'noun': 'lime','verb': 'amber', 'adv': 'blue',}
badge_class_postfix = upos_badge.get(value.lower(), 'light-grey')

I recently learned about DeepL as an alternative to Google Translate. It seems really good.