Nothing to Write? Oh, and neomutt.

So my last post was about how I might start writing more frequently for this site. That was only 4 months ago….

I promised to write a post about neomutt if I got it working. It turns out it was extremely easy to install and configure, and I did not feel as though there was anything interesting to contribute. Well anyway, I recommend it for people who want an old-fashioned email client with modern features.

I have thought a bit about why I can’t seem to generate any content here. When I was in college I thought I would be brimming with ideas about what to write about. At the time I was too busy. Now I have the time, but the ideas are harder to come by.

I encounter plenty of interesting engineering challenges in my job, but I haven’t felt that it was okay to write about them on a public forum. And most of what I work on is very collaborative, so I feel a little uncomfortable writing about the solutions when it was the work of my colleagues that facilitated them. A lot of engineering blogs I read appear to get around these problems by constructing an example just for the post. They do a great job at this, but I worry that if I were to try that, the result would be overly terse or contrived.

What I know I could do, would be to write technological rants. But that wouldn’t be what I started this website for, and wouldn’t be very valuable either. So I will wait for inspiration to write something useful and interesting about my areas of expertise.

It's Been a Long Time

I won’t go into how and why this website has gone silent since its creation almost two years ago. Anyone would understand, I am sure. But why the hopefully-not-so-brief reanimation?

A Surprise Email

I am the maintainer of a few packages on the Arch Linux User Repository (AUR).

Between 2015-06-08 and 2015-08-08 the AUR transitioned from version 3.5.1 to 4.0.0, introducing the use of Git repositories for publishing the PKGBUILDs. Existing packages were dropped unless manually migrated to the new infrastructure by their maintainers.

Some of the packages I had installed at the time lost their maintainership during the transition, so I decided I was as good as anyone to take over. I uploaded the PKGBUILDs and promptly forgot all about them.

…Until today, two-and-a-half years later, I receive an email from a helpful user explaining some problems with my package for tint, the Tetris emulator. After fixing these problems I noticed my AUR account was missing a homepage, and this website is it, such as it is.

Since my last update here, I have become the firmware manager at my company and have been very active on GitHub, though privately. I interact a lot with students, prospective hires, and coworkers who are less familiar with the Unixy world. Between that and the realization that a small group of Arch Linux users may be interested in my work, I figured I should add a direct link to my profile in the sidebar here so people might find e.g. my dotfiles repository more easily.

Everything Breaks

I add a link to my GitHub profile to the sidebar and the styling breaks. So I resolve to debug the problem locally.

First, I could not even remember how to build a locally serve the site. After a quick review, I discover my entire ruby installation is messed up and I cannot run jekyll or bundle.

Gems are installed to your home directory, and this location must be added to the $PATH in order to operate correctly. My $PATH pointed to a directory for ruby 2.3.0 rather than 2.5.0, which is what is now installed on my machine (gotta love rolling releases).

While cleaning up the ruby stuff, I went up one level two high and accidentally issued a rm -r * on my home directory! Luckily the ownership of my ~/bin/cflush was root and rm halted there before wiping everything. Interestingly, while rm seemed to only touch files in my ~/bin directory, the files it deleted therein were randomized before it halted. Anyway, after recovering from my backups, I did a quick pacman update to make sure all the ruby stuff was squared away.

That update broke a dependency of uber-mutt, my email client that last built in 2014 — RIP. I’ll look into neomutt soon, and if successful, will make a post here.

After installing bundle, trying to figure out what was wrong with the json gem build, and eventually getting the website building, I quickly found the culprit:

https://github.com/github/pages-gem/issues/350

Things look like they are working now.

Conclusion

I had been coasting on the relative stability of my Arch Linux installation, and my lack of real computing work to do at home. Even though a large part of my job is now writing software, today’s experience shows me I still thoroughly enjoy hacking away at software in my free time. I have also gained a wealth of engineering experience the last couple years at work, so if I can keep my motivation, I ought be able to write some interesting posts here. We will see.

Quick Directory Navigation in the Shell

I spend a lot of time in the shell. In fact, the only two graphical programs I use at home are my web browser and pdf viewer, and those have vim-like interfaces with extremely minimal chrome.

Without a graphical file manager, good organization is a must. Moreover, in a command line setting, I prefer short filenames and abbreviated directory names to limit my typing. Even with heavy use of tab completion, directory navigation can still be pretty tedious.

Bookmarks

One useful tool is the ability to store and recall directory bookmarks. My use case for this is a deep directory where I’m working on a project and would like to jump there quickly. A good solution is the bashmarks shell script.

This script should be sourced by bash in e.g. your .bashrc file. It provides a few one-letter (abbreviated indeed!) functions.

s <bookmark_name> # Saves the current directory as "bookmark_name"
g <bookmark_name> # Goes (cd) to the directory with "bookmark_name"
p <bookmark_name> # Prints the directory with "bookmark_name"
d <bookmark_name> # Deletes the bookmark
l                 # Lists all available bookmarks

Conveniently, these functions are tied into bash completion so pressing tab will complete with known bookmarks.

Nonetheless, bookmarks are only good for directories you need to access a lot, and need to be created first. One could try to map their entire file system into a flat dictionary of bookmarks but this would basically defeat their purpose.

Up

One navigation operation I found particularly tedious was moving up the directory tree with e.g.

egan@teuthida:~/docs/old/15/q3/eme/185/code/weinbot/src/Drive/Sabertooth (master *)$ cd ../../../../../../..

I would invariably make a typo or miscount the number of levels I needed. The correspondence between the command and the mental operation was not good either. You don’t want to “go seven levels up in the tree”, but rather “go to q3”. So I implemented a shell script upstr.sh that returns a .. path from either a number or a substring of the current working directory path.

To use it, add a bash function to your bash environment:

function up() { d=$(upstr.sh "$1") && cd "$d"; }

Then in the prior example,

up 7

Or better,

up q3

Are equivalent to the pinky-snapping .. path. While I was coming up with the substring concept, I realized that the same principal could be applied in the opposite direction, down the directory tree.

Down

In the prior example, it is not just tedious to back out of the that deep path, but also tedious to get there is the first place. It would be nice to jump straight there. However, a bookmark isn’t appropriate because this is an archived directory in which I am not actively working.

Applying the substring jumping concept from upstr.sh, I developed downstr.sh that searches the child directory tree for a substring and returns the first matching path. To use it, add a similar bash function as up to your bash environment:

function down() { d=$(downstr.sh "$@") && cd "$d"; }

Then, from ~, it is as simple as:

down Sabertooth

To cd all the way into that deep directory. It just so happens that this is the only directory named “Sabertooth” on my entire filesystem. What if I wanted to jump directly the “src” directory in that path?

Doing:

down src

Takes me immediately to ~/src/ because down prefers the shortest path. This is usually desirable because deeper paths are typically less often traveled.

One could do:

down weinbot/src

To get to the correct place, but that requires excessive typing and sometimes you don’t remember the exact directory structure. To improve the experience, I designed downstr.sh to accept multiple substrings:

down 185 src

This is an extremely powerful interaction mechanism because you often remember parts of the path like this — in this case, I would want to go to the source code directory for my 185 project. I don’t have to remember what year or whatever to get to the right path. This means that even obscure paths can be jumped to if you organize your files in a systematic way.

Sidenote: Long Pathnames in the Prompt

I have lots of super long pathnames, as long or longer than the prior example. Eventually the pathname may overwhelm your command line, which is an eyesore. Many times, long pathnames are the result of moving deep directory trees into a deep path. In these cases, you don’t need as much context when working in the local tree.

My solution to long pathnames is to chomp them in the bash prompt once they reach a certain column length:

# Abbreviate working directory if long.
_dir_chomp () {
	local p=${1/#$HOME/\~} b s
	s=${#p}
	while [[ $p != "${p//\/}" ]]&&(($s>$2))
	do
		p=${p#/}
		[[ $p =~ \.?. ]]
		b=$b/${BASH_REMATCH[0]}
		p=${p#*/}
		((s=${#b}+${#p}))
	done
	echo ${b/\/~/\~}${b+/}$p
}

# Show git information in prompt.
. /usr/share/git/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1

# Command prompts.
PS1='\[\033[G\]\u@\h:$(_dir_chomp "$(pwd)" 35)$(__git_ps1 " (%s)")\$ '

The result for the prior example is:

egan@teuthida:~/d/o/1/q3/eme/185/code/weinbot/src (master *)$

Reading Resistor Color Codes

There are various mnemonics taught to help students remember the resistor color codes, such as:

Better Buy Resistors Or Your Grid Bias Voltages Go West!

among many other silly or offensive ones.

I have always found mnemonics of this type to be mostly useless because they don’t actually help you read the colors into numbers. Best case scenario, you could use the mnemonic to write down the sequence and use that as a key to read the resistances. Otherwise you’d probably have to recite it like the alphabet while counting on your fingers.

A few years ago I wanted a way to easily read a color sequence into a resistance and also convert a resistance into a color sequence so I could both identify and specify resistors instantly. At the time I didn’t find any suitable system on the web, so I developed my own using techniques in adapted from my childhood reading of Martin Gardner’s “Hexaflexagons and Other Mathematical Diversions” and the Mentat Wiki.

Since that time, the technique I developed has been developed by others and is now easily discoverable on Google. Anyway, the basic premise that a color should be bidirectionally associated with a number made me think to develop a striking image that incorporated both the number and color. I ended up developing a number shape system.

For each digit, I identified an object that had its shape that also would be strongly associated with the color. Below, the original crayon drawing I made on the back of some scratch paper:

Colored Number Shapes

Unfortunately, there are two snakes of different colors but they are easy enough to remember (and red “comes before” green anyway). The use of a purple veil for seven comes from Martin Gardner’s suggested image for remembering the square root of seven with the phonetic number system:

SHEER LINEN. Seven suggests the dance of seven veils. Think of the veils as made of sheer linen.

My memory may be playing tricks on me, but I always visualized those veils as purple. Come to think of it, the triangles on the square root of three KIMONO were always orange too.

You should use whatever images you find most memorable. This image-association-based technique is a great memory tool for all kinds of things.

Hello World

Well, I have to start with something….

Introduction

For a few years now, I have wanted to publish a website that treats some of my interests in mechanical engineering similarly to the hundreds of great software engineering technical blogs I frequent. As a student I just never got around to it. After just over a year of working as a mechatronics engineer in the industry, I figured I better get around to it before some of my less-used knowledge fades into oblivion. At least now I theoretically have the free time.

As a hobbyist programmer who uses programming mostly out of laziness — some of my first useful programming projects were to automate some tedious high school homework assignments — I have really only built tools for my homebrew Arch Linux setup and for scientific and engineering analyses. As such, the world of web development has been pretty foreign to me. Of course, I knew all the buzzwords that would frequent Hacker News: ruby on rails, nodejs, json, etc.; I just had no idea what they were.

But in order to start this website I had to make my first foray into this world. I was aware the GitHub supported a free web-hosting service but wanted something a little bit nicer than wrangling HTML eyesores in vim. Conveniently, GitHub pages supports the Jekyll content manager. Jekyll is a static site generator, meaning that the web content is pregenerated and static, rather than dynamically generated when the user loads the page. As someone who hates bloated web pages, this appealed to me, and fit nicely into my text-based workflow.

Building the Site

Rather than starting from scratch, I googled around for some tutorials, hoping to find a nice template to work from. I found these two to be quite useful:

Both use poole, a Jekyll template with a couple of nice themes, hyde and lanyon.

I started working from poole only to find that it no longer worked with the latest version of Jekyll. I guess it would have been too easy if everything just worked! Combining information from:

I was able to get the site built. After a little bit of customization drawn from all over the web, I have what I hope is good platform to write content. If you are interested in the web development, you can always check out the GitHub repository.