Rick Cogley's Tech Logr

Short Technical Laser Bursts %%

Welcome

Rick’s short, technical tip microblog built with Hugo, powered by Deno Deploy. See also my fabulous repository at Github for this site.

27 Mar 2019

«16:07:02»

When there is a new macOS point release available like today, before you update I recommend running Maintain Cocktail first to clear caches, cruft and so on, and then install via the ยซCombo Updateยป. The combo contains all the patches since the last major release, and maybe it is voodoo but I have always had better luck installing the combo. ๐Ÿ—ฟ๏ฃฟ

RC Logr 20190327 160702 - When there is a new macOS โ€ฆ Rick Cogley

26 Mar 2019

«19:38:01»

When you use bash as your shell, normally your .bash_profile is run once when you log in, and your .bashrc runs for every new shell. But using bash on macOS is a bit odd, because Terminal app will run .bash_profile every time you open a tab or window. ๐Ÿค” To make it act more normal on Mac, source your .bashrc from your .bash_profile, and put all your settings in .bashrc:

1
2
3
4
~ $> cat .bash_profile
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

Also, as a matter of convention, chmod 700 those 2 files to make them accessible to your user only.

RC Logr 20190326 193800 - When you use bash as your โ€ฆ Rick Cogley

25 Mar 2019

«18:29:20»

macOS often lets you set the default app for something, from preferences in their canonical app for that function. For example, you can set the the default browser as Firefox in Safari.app prefs, the default email client as MailMate from within Mail.app, BusyCal as default in Calendar.app, and even the default shell as say zsh in Terminal.app. ๐Ÿ‘

It doesn’t work 100% but it is a common Apple design pattern.

RC Logr 20190325 182919 - macOS often lets you set the โ€ฆ Rick Cogley

«15:05:24»

The zsh that is installed by default on macOS is 3 years old, but you can use homebrew to install the latest. Add the brew installed one to your shells whitelist, and set your login shell to it using chsh. Use the prefix switch on brew to find the path of the shell you installed. ๐Ÿค“

1
2
3
4
5
6
$> brew install zsh zsh-completions
$> sudo echo $(brew --prefix zsh) >> /etc/shells
$> cat /etc/shells
$> chsh -s $(brew --prefix zsh)
$> sudo dscl localhost -read /Local/Default/Users/$(whoami) shell
$> echo $SHELL

Using brew --prefix zsh to find the path of the brew-installed zsh is the most precise, but you may know about whereis or which as well. Bonus trivia - whereis zsh will return the original macOS one since it does not look in your path, whereas, which zsh does look in your path and will find the one installed by brew (try also which -a zsh to see them all).

The above dscl command will reliably return your user shell, but you can confirm your settings in the GUI too. Just ctrl-click on your user in System Prefs, Users and Groups, and select Advanced Options. The echo $SHELL shows the shell at login, but may be misleading because the act of changing shells will not update it.

Update: Rudi mentions that it might work to set the history file’s perms to 700 or the like; a valid point. However, the man file bash shell builtins says the file that source is executing “need not be executable”.

RC Logr 20190325 150523 - The zsh that is installed by โ€ฆ Rick Cogley

24 Mar 2019

«09:15:27»

Saw this tweet in which .bash_history was accidentally re-executed using source. D’oh! You can prevent this by making an alias to redirect that to an innocuous function. ๐Ÿ˜ฅ Not tested yet but I am pretty sure it would be something like this in your .bashrc:

1
2
3
4
5
6
oh_no_you_dont(){
  echo "Stop. You probably should not do that." >&2
}

alias source ~/.bash_history="oh_no_you_dont"
alias scarycmd --silent --killdrive="oh_no_you_dont"

RC Logr 20190324 091526 - Saw this tweet in which โ€ฆ Rick Cogley

22 Mar 2019

«18:36:01»

Vim lets you search in normal mode by simply pressing slash followed by the search word and enter, like /Toranomon. Then, n finds the next while N finds the previous occurrence, and ggn finds the first while GN finds the last occurrence. Using a question mark instead of slash goes the opposite direction. Also, use / or ? then the arrow keys, to check the search history. ๐Ÿ•ต๐Ÿปโ€

RC Logr 20190322 183601 - Vim lets you search in normal โ€ฆ Rick Cogley

«07:25:46»

Ever boneheadedly pasted a password into a terminal command? Restart your terminal, find your history file with echo $HISTFILE, edit it and delete the offending line, then reload. That should do it. ๐Ÿ

More options:

You can delete all lines with a specific string from your history file using sed -i '/badstring/d' $HISTFILE.

Add the zsh builtin option setopt histignorespace to your ~/.zshrc. Now if you enter a single space before a command, it will not be logged in history.

RC Logr 20190322 072545 - Ever boneheadedly pasted a โ€ฆ Rick Cogley

21 Mar 2019

๐Ÿ—“ "Vernal Equinox Day" in Japan

«08:21:39»

Email newsletters have to cater to various email clients that parse HTML differently, using fairly archaic techniques that you ignore at your peril. E.g. you need to set fixed sizes and widths for things in px not rems. Even a cool builder like MJML will ultimately convert to px from its intermediate language, skillfully finding a way to make the result relatively device-responsive. The resulting HTML is complex, but at least it is not horrific like what MS Word generates! ๐Ÿ™€๐Ÿ˜ฑโœ‰๏ธ

Rules I could discern:

  • Container width: 600 or 700px
  • Banner width: same as container, or that less any padding
  • Base text size: 12-14px

RC Logr 20190321 082138 - Email newsletters have to โ€ฆ Rick Cogley

20 Mar 2019

«08:37:44»

I posted about how to remove a key from ~/.ssh/known_hosts using vim, when you have StrictHostKeyChecking yes set in your ssh options and you get the WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED error. Other options: you can do it with sed -i '83d' $HOME/.ssh/known_hosts or more directly with ssh-keygen -R tried.host.com, replacing the hostname with the one that is failing. ๐Ÿค–

RC Logr 20190320 083743 - I posted about how to remove a โ€ฆ Rick Cogley

19 Mar 2019

«12:49:19»

Today I learned about Input Club mechanical keyboards, and the KLL keyboard input language. Looks like another brand of keyboard that has good quality with a good configurator. We are spoiled for choice! โŒจ๏ธŽ๐Ÿ”ฃ

RC Logr 20190319 124917 - Today I learned about Input โ€ฆ Rick Cogley

18 Mar 2019

«19:55:59»

Sys admins you will have seen those messages you get from ssh servers sometimes, saying IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY, and saying the fingerprint for a key is incorrect and cannot be verified. It is easy to fix with a vim one-liner. ๐Ÿค“

The error looks like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:Us12tDB12PGJ12u++F12jQI12wOXQ12S6oh122512bE.
Please contact your system administrator.
Add correct host key in /path/to/.ssh/known_hosts to get rid of this message.
Offending RSA key in /path/to/.ssh/known_hosts:83
RSA host key for [ip]:port has changed and you have requested strict checking.
Host key verification failed.

Fix it like this:

1
vim $HOME/.ssh/known_hosts +"83d|x"

You can have a look at the manual, but the +"??" bit is a plus command, which tells vim to execute “Ex commands” separated by the pipe.

Simply put, it is just a kind of macro that acts on the specified file to press colon, followed by a vim command. In this case, in vim’s “command” mode (enter a colon to switch to it), it is doing :83d deleting the 83rd line in the file, then :x which exits. Note that, because you are running the d in normal mode, the file is saved and you just need x. This is easier to figure out than sed.

RC Logr 20190318 195558 - Sys admins you will have seen โ€ฆ Rick Cogley

«10:37:39»

Is your Japan branch using Era Year Names (ๅ…ƒๅท, ใ’ใ‚“ใ”ใ†, gengou) in any apps? If so, you should look into whether a patch or upgrade is needed, for the upcoming name change in May, from Heisei to something new. My firm eSolia can help, so please do not hesitate to ask us. ๐Ÿ‡ฏ๐Ÿ‡ต

RC Logr 20190318 103738 - Is your Japan branch using Era โ€ฆ Rick Cogley

«08:27:25»

The chips that power our devices rely on EUV or ยซextreme ultraviolet lithographyยป, to draw circuit lines e.g. less than 7 nm in width in the case of the Apple A12 Bionic chip. That is, less than 7 billionths of a meter. The Japan Times introduces Lasertec, the Yokohama firm that makes the equipment to test the needed chip stencils.

And all most of us are doing on our devices is clicking Like and Share! ๐Ÿคช

RC Logr 20190318 082725 - The chips that power our โ€ฆ Rick Cogley

17 Mar 2019

«10:18:18»

Happy St. Patrick’s day! Designers should note the official green and orange of the Irish flag are Pantone PMS 347: Hex #009a49 | RGB 0,154,73 | CMYK 100,0,53,40, and Pantone Orange PMS 151: Hex #ff7900 | RGB 255,121,0 | CMYK 0,53,100,0 respectively.

While you drink your green beer, did you know that the color associated with St. Patrick is blue? There are several associated shades including the one used behind the golden harp on the presidential flag: #23297a.

Beannachtaรญ na Fรฉile Pรกdraig ort!

RC Logr 20190317 101817 - Happy St. Patrick’s day! โ€ฆ Rick Cogley

16 Mar 2019

«09:18:57»

Heard about the #HHKBChallenge in the Bay Area by @taromatsumura? I have used PFU Happy Hacking HHKB keyboards for years, one at work and one at home. I love the form factor because desk space is at a premium here in Japan, the fact that they are not so heavy so you can schlep them on the train without too much trouble, and for the perfect-feeling Topre switches. You can buy a programmable controller to replace the original Topre one, from Hasu.

I’m using Japanese versions of the HHKB to get arrow keys in US English layout, with keycaps swapped to English, and the Hasu controller. A good fit! โŒจ๏ธŽ๐Ÿ’™

In addition: note that the switches are Topre, so keycap availability is limited, unlike with Cherry MX type switches. They are not compatible, so you need to get keycaps from PFU or Topre. I wanted some color when I got my HHKBs, so I got a spare set of yellow Topre key caps in Akihabara, and a kit with just 4 keys in it from PFU - blue and red escape and ctrl keys. When I got the idea to switch to the US English layout, I got the English keycap set from PFU and swapped it in. Also, at first I tried the black on grey color scheme, but that was way hard for me to use. I guess I need the legends.

RC Logr 20190316 091856 - Heard about the #HHKBChallenge โ€ฆ Rick Cogley

«00:03:58»

Haha, is it wrong to get this giddy over software? ยซMonodrawยป is an ascii art editor for macOS by @milend, which is just so slick. Love it! ๐Ÿค–

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—         
โ•‘  SHOULD YOU ยซMAINSPLAINยป THE DIFFERENCE BETWEEN  โ•‘         
โ•‘              "VAGINA" AND "VULVA"?               โ•‘         
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•         
                                                             
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                    
โ”‚Do you have orโ”‚       โ”‚Did they ask forโ”‚                    
โ”‚ did you ever โ”‚โ”€โ”€Yesโ”€โ”€โ”‚  your learned  โ”‚โ”€โ”€โ”€Yesโ”€โ”€โ”€โ”€โ”€โ”        
โ”‚have a vagina?โ”‚       โ”‚    opinion?    โ”‚           โ”‚        
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚                       โ”‚          โ”‚Do you actually โ”‚
        โ”‚                       โ”‚     โ”Œโ”€โ”€โ”€โ”€โ”‚    know the    โ”‚
        โ””โ”€โ”€โ”€โ”€Noโ”€โ”€โ”€โ”€โ”       โ”Œโ”€Noโ”€โ”˜     โ”‚    โ”‚  difference?   โ”‚
                   โ”‚       โ”‚          โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚       โ”‚          โ”‚             โ”‚        
                   โ”‚       โ”‚         No            Yes       
                   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚             โ”‚        
                   โ”‚โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ”‚   โ”‚     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                   โ”‚โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ”‚   โ”‚     โ”‚โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ”‚
                   โ”‚โ–ˆShut up now.โ–ˆโ”‚โ”€โ”€โ”€โ”˜     โ”‚โ–ˆโ–ˆProceed but โ–ˆโ”‚
                   โ”‚โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ”‚         โ”‚โ–ˆkeep it briefโ–ˆโ”‚
                   โ”‚โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ”‚         โ”‚โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ”‚
                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

RC Logr 20190316 000357 - Haha, is it wrong to get this โ€ฆ Rick Cogley

15 Mar 2019

«16:43:07»

Learn what ยซCAPTologyยป is so you can gird yourself against it (I do not care about likes, I do not care about likes). โš”๏ธ

RC Logr 20190315 164306 - Learn what ยซCAPTologyยป is so โ€ฆ Rick Cogley

«08:24:49»

If you tried using bc to do the quick pi calculation I mentioned yesterday, you can also use an internal value SECONDS to calculate elapsed seconds. The SECONDS only tracks whole numbers, so the time calculation is rather rough, but it works in a pinch.

This works in zsh or bash: SECONDS=0 ; echo "scale=3000; 4*a(1)" | bc -l ; echo $SECONDS ๐Ÿค“

This also works, using simple math to do date arithmetic (the $(()) triggers the math):

1
STARTT=$(date +%s) ; echo "scale=2000; 4*a(1)" | bc -l ; ENDT=$(date +%s) ; echo "Took $(($ENDT - $STARTT)) seconds to calculate this..."

Or in zsh, this gives output like 1.92s user 0.02s system 99% cpu 1.954 total:

1
{ time ( echo "scale=2000; 4*a(1)" | bc -l ; ) } 2>&1 

In bash, just replace the () around the command you are timing with {}. Calculating pi using this 4*atan(1) formula is super slow, so anything more than a couple thousand digits will take tiiimeeee.

RC Logr 20190315 082448 - If you tried using bc to do โ€ฆ Rick Cogley

14 Mar 2019

«18:03:53»

Since it is March 14th and Pi day, here is an odd fact: you cannot ever know the exact circumference or area of a circle, due to the nature of Pi. I understand that even space shot calculations do not use all that many digits anyway, so if that is good enough for NASA, I won’t worry about it.

Congratulations to Emma Haruka Iwao and her team at Google for recently breaking the record of the most accurate value of pi, calculated out to 31,415,926,535,897 digits using a program called y-cruncher on 25 virtual cloud servers over four months, and using up 170 TB of data. Wow! ใŠ—๏ธ๐ŸŽ‰

RC Logr 20190314 180352 - Since it is March 14th and Pi โ€ฆ Rick Cogley

«17:04:10»

Happy ฯ€ day. #piday #ๅ††ๅ‘จ็Ž‡ใฎๆ—ฅ It is trivial to approximate pi to say 100 digits using bc, the command line calculator. echo "scale=100; 4*a(1)" | bc -l will do it. Try scales of 1000 or 10000 as well. The former should be reasonable, and the latter will take quite a while. ๐Ÿ”˜

RC Logr 20190314 170409 - Happy ฯ€ day. #piday #ๅ††ๅ‘จ็Ž‡ใฎๆ—ฅ It โ€ฆ Rick Cogley