Rick Cogley's Tech Logr

Short Technical Laser Bursts %%

Welcome

Here be my pithy, short, technical nuggets. Maybe I’m the only one who cares. Who says Hugo can’t be used for microblogging‽

21 Apr 2019

«09:58:01»

Learned about «Working Copy» today, a git client for iOS. Anyone use it? I think it would be cool to combine this with a CI system so that a commit and push would trigger a build and publish. 🤖

RC Logr 20190421 095801 - Learned about «Working Copy» … Rick Cogley

18 Apr 2019

«12:29:25»

You can use a plugin to generate your vim status line, or you could use the «vim statusline generator» from Tom Daly, and just chuck the results into your .vimrc. Cool! 😎

RC Logr 20190418 122925 - You can use a plugin to … Rick Cogley

14 Apr 2019

«13:51:42»

Given a json file, used say for a search index, you can easily use «jq» from stedolan to extract what you need from it. 👻 It is as simple as piping the json to jq, and using its powerful filtering to extract what you need. I generate the search index for this site in json, because that is what lunr requires, but it doubles as a source for the info I use to tweet about a new post.

Given a json like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
[
  {
    "content": "Static site generator «Hugo 0.55.1» was released, with three bug fixes. Go static! 🚀 #gohugo #jamstack #golang #webdev\n",
    "ref": "https://logr.cogley.info/2019/04/12/1555079759/",
    "tags": null,
    "title": "RC Logr 20190412 233559"
  },
  {
    "content": "MacOS or Linux users, you might find log file viewer «lnav» useful. It is for viewing local log files, and requires no server like Splunk. Fire it up, press ? to toggle help or / to search. 🕵🏻‍\n",
    "ref": "https://logr.cogley.info/2019/04/12/1555047850/",
    "tags": null,
    "title": "RC Logr 20190412 144410"
  },
  {
    "content": "The first black hole...

… I use something like this to extract what I want to tweet:

1
cat index.json | jq --raw-output '.[0] | .content[:75]+"... "+.ref' 

That pipes the index json file to jq, gets the 0th (first and latest) node, then pipes it extracting and concatenating the values of the .content and .ref keys, limiting the .content value to 75 characters. With jq, concatenation to string literals is done with a plus sign. The statement within the single quotes is where the work is done, and it can be multiple filters with pipes between.

RC Logr 20190414 135141 - Given a json file, used say … Rick Cogley

13 Apr 2019

«12:16:27»

Apple iCloud Drive has its place and works well for syncing data for certain apps to «all teh devices», but it really causes trouble sometimes. It especially did not play well with some secure .sparseimage files I had stored in $HOME/Documents on my Mac. 😳

To wit, I was sometimes getting unwanted copies of my secure disk images, and other files under $HOME/iCloud Drive (Archive) or $HOME/Documents - rickmac. To fix I created $HOME/docs, outside the paths iCloud drive targets for syncing, and migrated the files there. Anything that is not needed on my mobile devices is getting chucked in this new folder.

Sync is hard and here are a few commands to aid macOS users in no order:

1
2
3
4
5
~ > killall -KILL bird #bird is the sync daemon
~ > killall -KILL Finder
~ > brctl log -w #watch bird log, ctrl-c to exit
~ > rm -rf ~/Library/Application\ Support/CloudDocs
~ > rm -rf ~/Library/Caches/com.apple.bird

You may need to stop and restart iCloud Drive, or restart the computer.

RC Logr 20190413 121627 - Apple iCloud Drive has its … Rick Cogley

12 Apr 2019

«23:35:59»

Static site generator «Hugo 0.55.1» was released, with three bug fixes. Go static! 🚀 #gohugo #jamstack #golang #webdev

RC Logr 20190412 233559 - Static site generator «Hugo … Rick Cogley

«14:44:10»

MacOS or Linux users, you might find log file viewer «lnav» useful. It is for viewing local log files, and requires no server like Splunk. Fire it up, press ? to toggle help or / to search. 🕵🏻‍

RC Logr 20190412 144410 - MacOS or Linux users, you … Rick Cogley

11 Apr 2019

«07:19:28»

The first black hole “photo” is incredible, and before her credit gets sucked into said black hole, it was Dr. Katie Bouman came up with the clever computer algorithm to capture it. She explains how, from the TED stage. (Say it in @GuyRaz’s voice) What an inspiration to young women considering a career in STEM! 👭

A couple of technical tidbits:

  • the black hole is so far away, 53 million light years, that it required use of the planet-sized EHT or Event Horizon Telescope. The EHT is 8 observatories across the globe, using interferometry to combine the data.
  • there was petabytes worth of data, and it had to be ferried around via essentially “sneakernet”, since some of the locations don’t have good Internet connections and there was simply too much data to send via wire.
  • Dr. Bouman herself has said it was a team effort, and indeed it was a team of 200 astronomers world wide.
  • Scientists on the team estimate the mass to be 6.5 billion times as massive as our sun.

Read about it here from MIT news office.

RC Logr 20190411 071927 - The first black hole … Rick Cogley

10 Apr 2019

«09:30:15»

Saw @AdobeType post that they are adding the #Reiwa era single-kanji character to their Japanese type faces such as Source Han Sans. This is the single-kanji version of the era name, like the Unicode ㍻ U+337B «square era name heisei». 🇯🇵

RC Logr 20190410 093015 - Saw @AdobeType post that they … Rick Cogley

«07:51:01»

Turns out birds are not so bird-brained after all, per the «Birdsong» episode of the fantastic 20000 Hz podcast @20korg (20K Hz is the typical upper limit of human hearing). Birds have a pharynx like humans, but sing with their syrinx, an organ at the base of the trachea. 🐦🐧

Some awesome examples from the episode:

  • the New Zealand kokako can produce organ-like chords
  • the African Grey Parrot can mimic human speech
  • Mockingbirds can mimic other birds and even frogs
  • the Australian Lyre bird and its uber-complex syrinx can mimic whatever it hears!

It’s worth a listen, and birds are cooler than you might imagine!

RC Logr 20190410 075101 - Turns out birds are not so … Rick Cogley

09 Apr 2019

«22:45:21»

PSA: A serious bug was discovered in Apache, the web server that powers a lot of the internet. Vulnerability CVE-2019-0211 allows scripts to be executed with root privileges, allowing system takeover especially on shared hosting environments. 🐞☠️

Apache foundation released patched version 2.4.39, so confirm and update (or request an update):

1
2
3
4
5
6
7
8
~ > httpd -v  # or apache2 on some
Server version: Apache/2.4.34 (Unix)
Server built: Feb 22 2019 19:30:04
~ > curl --head https://thesite.com
HTTP/1.1 200 OK
Date: ...
Server: Apache/2.4.34
...

You might need to confirm from your “control panel” in a shared environment. Note that Apache sysadmins can make settings to block these tools from getting any details about the web server. Same caveat applies, but you can also put <?php phpinfo() ?> in a file like info.php, then serve and access it.

RC Logr 20190409 224521 - PSA: A serious bug was … Rick Cogley

«14:44:39»

After upgrading to static site generator «Hugo 0.55.0», building with hugo server -D returns a couple of non-fatal warnings that should be corrected. 🐞

  1. The .Site.Pages includes section pages so you might need to change it to .Site.RegularPages. I was building an index.json for searching and relying on it to supply data to a script, but after the upgrade, the index included pages with no content. To fix, I just changed to the latter.
  2. When you get Page's .Hugo is deprecated you just need to change from something like .Hugo.Generator to hugo.Generator in your <head>.
  3. .GetParam is being deprecated, so see if you can just access the param directly. For example, indicating what posts are in draft form:
1
2
3
4
// before
{{ if .GetParam "draft"}}<span class="bg-orange white">DRAFT</span>{{end}}
// after
{{ if .Site.BuildDrafts }}{{ if .Draft }}<span class="bg-orange white">DRAFT</span>{{ end }}{{ end }} 

RC Logr 20190409 144438 - After upgrading to static site … Rick Cogley

«07:19:04»

Static site generator «Hugo 0.55.0» was released, we got a lot of great new features to play with, and it is even faster and more flexible. Go static! 🚀

RC Logr 20190409 071904 - Static site generator «Hugo … Rick Cogley

08 Apr 2019

«14:55:01»

Today I learned about «Lynis», an agentless security auditing tool for *nix-based systems, that lets you do compliance testing e.g. for HIPAA or SOX, pen testing, vulnerability detection to help you harden systems. I ran it and it appears to work well and returns useful suggestions after it runs, e.g. install this, disable that, confirm the other. 🤖

This is what the first few lines of the results look like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[+] System Tools
------------------------------------
  - Scanning available tools...
  - Checking system binaries...

[+] Program Details
------------------------------------
  - Verbose mode                                              [ YES ]
  - Debug mode                                                [ NO ]

[+] Plugins (phase 1)
------------------------------------
 Note: plugins have more extensive tests and may take several minutes to complete

  - Plugins enabled                                           [ NONE ]

[+] Boot and services
------------------------------------
  - Service Manager                                           [ launchd ]
    - Boot loader                                             [ NONE FOUND ]

[+] Kernel
------------------------------------
...

(via @binitamshah on Twitter)

RC Logr 20190408 145501 - Today I learned about «Lynis», … Rick Cogley

«06:11:37»

«Cargo Cult» programming is a waste of time and effort. The best way is to understand fully, so do not ritually include features that serve no purpose, nor copy-paste code you do not understand. ✈📦

RC Logr 20190408 061136 - «Cargo Cult» programming is a … Rick Cogley

06 Apr 2019

«18:17:30»

I often need to replace dates in the frontmatter of markdown files, in «RFC 3339» format for content in static site generator Hugo. A simple shell function using gnu date, sed, head and pbcopy puts the current timestamp on the clipboard easily. 👻

1
2
3
4
5
function date3339() {
   echo "Putting RFC3339 on Clipboard for Frontmatter"
   gdate --rfc-3339=seconds | sed 's/ /T/' | head -c -1 | pbcopy >&1
   echo "Date in RFC 3339 format on clipboard. Paste away"
}

Here is how it works:

  • Gnu date with the --rfc-3339 switch gives us a timestamp like 2019-04-06 18:38:19+09:00, is piped to…
  • sed which replaces the space with a T, then that is piped to…
  • head to remove the trailing newline, which is finally piped to pbcopy to put the result on the clipboard (MacOS only).

Then just paste it where you need it. By the way, the timestamp means “18:38:19 in the timezone +9 hours ahead of GMT”, or, Japan time.

RC Logr 20190406 181729 - I often need to replace dates … Rick Cogley

05 Apr 2019

«18:21:30»

You can use the Haversine formula to approximate the «great-circle» distance between points on the globe, to get, say, the distance between map locations expressed in latitude and longitude. 🗺

Haversine Distance Formula

You can see it in use in this javascript around line 247, the meat of which is this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
...
calcDistance: function (loc1, loc2){
  var rad = function(x) {return x*Math.PI/180;}
  var R = 6371; // earth's mean radius in km
  var dLat  = rad(loc2.latitude - loc1.latitude);
  var dLong = rad(loc2.longitude - loc1.longitude);

  var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(rad(loc1.latitude)) * Math.cos(rad(loc2.latitude)) * Math.sin(dLong/2) * Math.sin(dLong/2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  var d = R * c;

  return d.toFixed(3);
},
...

RC Logr 20190405 182129 - You can use the Haversine … Rick Cogley

«14:48:45»

To avoid storing a credential in command line history, you can store it in a file and use cat to insert it when you need it. 🤓 Say you have your API token stored in /path/to/token, here is how you might use that:

1
~$> curl -X "POST" "https://service.com/apiv3/msg?content=test" -u '$(cat /path/to/token)'

RC Logr 20190405 144845 - To avoid storing a credential … Rick Cogley

03 Apr 2019

«09:30:57»

If you use Win 10 64 bit, you can install the «Windows Subsystem for Linux» from Control Panel, Program, Turn Windows Features On or Off. Select it, OK and restart, then install your Linux distribution from the Windows Store - Ubuntu, Debian, openSUSE, even Kali for pen testing. 🤖 What else?

  • Install Linux programs sudo apt-get install jq
  • Switch to zsh
  • Mount drives sudo mount -t ...
  • Run shell scripts
  • Use Windows Run, Open to run Linux commands bash -c "somebin"
  • Upgrade your selected Linux

You can even possibly run graphical Linux programs, although this subsystem is not designed for that.

RC Logr 20190403 093056 - If you use Win 10 64 bit, you … Rick Cogley

01 Apr 2019

«13:46:47»

The new Japan era name is «Reiwa» 令和, the 239th such era, which comprises daily-use kanji rei 令 and wa 和, which could be translated as auspicious or orderly or calm or command, and peace or harmony, respectively. 🇯🇵 A couple of data points about the two characters are as follows:

令 Rei和 Wa
Past Eras Containing020
JIS Code4E614F42
UTF16 Unicode4EE4548C
Strokes58
Old Variant
Taught in Grade34
JLPT Level22

These details come from Jim Breen’s awesome WWWJDIC and Wikipedia. Software people can note also that there is a Perl library Date::Japanese::Era for Japan era conversion, by Twitter user @miyagawa. And the Unicode blog has a post about character code U+32FF, the one-character representation of the new name.

There were a few eras which were only a couple years long and even 1 year or less in the case of the Genji era, but the average for the last four is about 37 years. Will I last another era?! 🙀

RC Logr 20190401 134646 - The new Japan era name is … Rick Cogley

«07:35:44»

I was disappointed in this incredible article by Hans van «Hook», because it mentions the low angle of the sun in winter, without citing the angle. It is 30~46 degrees from vertical in Tokyo, so position those solar arrays with abandon. 🌞

RC Logr 20190401 073544 - I was disappointed in this … Rick Cogley