The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Archive for June, 2020

How to return a string value from a Bash function – Stack Overflow

Posted by jpluimers on 2020/06/17

Cool: you can return strings both as a function result, and by reference: they are explained in the question, second and fourth answer of [WayBack] How to return a string value from a Bash function – Stack Overflow.

Returning them by reference has two important benefits:

  1. it is much faster (especially useful in tight loop)
  2. you can use echo (normally used to return a result) for debugging purposes

I also needed a bit of switch magic which I found at [WayBack] bash – Switch case with fallthrough? – Stack Overflow and array magic (from [WayBack] Array variables) as arrays are far more readable than indirection (on the why not, see [WayBack] BashFAQ/006 – Greg’s Wiki: How can I use variable variables (indirect variables, pointers, references) or associative arrays?).

So here is a function that returns a specific IPv4 octet.

function getIpv4Octet() {
  IPv4=$1
  octetIndex=$2
  outputVariable=$3

  slice="${IPv4}"
  count=1
  while [ "${count}" -le 4 ]
  do
    octet[${count}]="${slice%%.*}"
    slice="${slice#*.}"
    count=$((count+1))
  done
   
  case "${octetIndex}" in
    "1" | "2" | "3" | "4")
      ;;
    *)
      octetIndex="4"
      ;;
  esac
  eval $outputVariable="${octet[$octetIndex]}"
}

You call it like this:

$ getIpv4Octet "192.168.178.32" 3 result && echo ${result}
178

–jeroen

Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »

A Tale of Many Divisions – Naive Prime Factorization Across a Handful of Architectures

Posted by jpluimers on 2020/06/16

[WayBack] A Tale of Many Divisions – Naive Prime Factorization Across a Handful of Architectures

Source code: [WayBack] GitHub – blu/euclid: An extremely naive prime factorizer

Via: [WayBack] Blu looks at how a small piece of code with divisions surprisingly behave on various architecture: #Arm, #MIPS, and #x86. – Jean-Luc Aufranc – Google+

–jeroen

Posted in Assembly Language, C++, Development, Software Development | Leave a Comment »

Being efficient actually holds you back

Posted by jpluimers on 2020/06/16

A while ago, over some period of time, I found a few related posts on being efficient optimising time management, on both professional and personal levels. Fully going the “optiomal” usually isn’t that a good thing.

Basically, you need slack or idle time. Plenty of it. That improves your agility too.

–jeroen

Posted in Agile, Conference Topics, Conferences, Development, Event, LifeHacker, Power User, Software Development | Leave a Comment »

how to count the length of an array defined in bash? – Unix & Linux Stack Exchange

Posted by jpluimers on 2020/06/16

I needed to enumerate all the parameters to a function and access many of them by index in the same function, so thanks to both these:

I got at this:

  declare -a arguments=("$@")
  for index in ${!arguments[@]}; do
    echo $index/${#arguments[@]}:${arguments[$index]}
  done

These are all forms of Array handling or Shell Parameter Expansion with special cases for array variables:

  • ! does indirection, in this case from the array to the index of the array
  • # gets the lengt of the parameter (for arrays: the number of elements)
  • [] acccesse an array variable using an index

Via:

–jeroen

Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »

Victron Energy Quattro 24V 8000VA 200A information

Posted by jpluimers on 2020/06/15

Some links relevant for my Victron Energy Quattro 24V 8000VA 200A setup:

–jeroen

Posted in LifeHacker, Power User, Solar Power | Leave a Comment »

Susan David: The gift and power of emotional courage; | TED Talk

Posted by jpluimers on 2020/06/15

Worth viewing every time: Susan David: The gift and power of emotional courage | TED Talk.

Via:

–jeroen

Posted in LifeHacker, Power User | Leave a Comment »

Raspberry Pi, Tumbleweed, btrfs

Posted by jpluimers on 2020/06/15

I want to use btrfs as filesystem on a Raspberry Pi with opensuse Tumbleweed.

It is hard to find out how, so here are a few links that should help me from “opensuse” “tumbleweed” “btrfs” “raspberry” pi:

–jeroen


Posted in *nix, *nix-tools, Development, Hardware Development, Linux, openSuSE, Power User, Raspberry Pi, SuSE Linux, Tumbleweed | Leave a Comment »

“windows 10” cannot manually set time – Google Search

Posted by jpluimers on 2020/06/12

On my research list: a Windows 10 machine with automatic time settings being 2 hours off.

I tried setting time and time zone, but the new Windows 10 UI did not let me.

List to start

–jeroen

Posted in Power User, Windows, Windows 10 | Leave a Comment »

Create table without header in markdown/reStructuredText?

Posted by jpluimers on 2020/06/12

It looks like few of the markdown parsers can generate a table without a header: [WayBack] Create table without header in markdown – Stack Overflow.

This comes close in some generators as they generate a half-height empty header for it:

| | | |
|-|-|-|
| Normal Key| Value1 |
|__BoldKey__| Value2 |

But [WayBack] reStructuredText Markup Specification: Grid Tables do support it even if a pipe cell delimiter is inside a cell content:

+--------------+----------+-----------+-----------+
| row 1, col 1 | column 2 | column 3  | column 4  |
+--------------+----------+-----------+-----------+
| row 2        | Use the command ``ls | more``.   |
|              |                                  |
+--------------+----------+-----------+-----------+
| row 3        |          |           |           |
+--------------+----------+-----------+-----------+

–jeroen

 

Posted in Development, Lightweight markup language, MarkDown, reStructuredText, Software Development | Leave a Comment »

ssh_config section order is important: the first setting obtained from a Host/Match section applies

Posted by jpluimers on 2020/06/12

Often, configuration files work like this:

  • global settings are at the top
  • detailed settings are further on, overwriting global settings

Not for ssh_config though, so I was right writing I should read more on it in Good read for starting to intermediate ssh users is “SSH Essentials: Working with SSH Servers, Clients, and Keys | DigitalOcean” and pointers to more advanced reading material.

So here is how ssh_config does it as per man page at [WayBack] ssh_config(5) – OpenBSD manual pages and [WayBack] ssh_config — OpenSSH SSH client configuration files at Linux.org:

     For each parameter, the first obtained value will be used.  The configuration files contain sections separated
     by “Host” specifications, and that section is only applied for hosts that match one of the patterns given in the
     specification.  The matched host name is the one given on the command line.

     Since the first obtained value for each parameter is used, more host-specific declarations should be given near
     the beginning of the file, and general defaults at the end.

This means a section Host * needs to come at the end.

I got that wrong and it took me the better half of a morning to figure out the cause of a connection problem ending in this:

debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred publickey
debug3: authmethod_lookup publickey
debug3: remaining preferred:
debug1: No more authentication methods to try.

Somehow, the identity file was never used to try public key authentication at all because of the ssh_config order in ~/.ssh/config.

I’m not the only one confused, as during the search for the cause with “remaining preferred” “No more authentication methods to try.”:

Maybe now I should step up from manually editing the ssh_config file and use [WayBack] GitHub – moul/advanced-ssh-config: make your ssh client smarter to generate it for me.

–jeroen

Posted in *nix, *nix-tools, Communications Development, Development, Internet protocol suite, Power User, SSH, ssh/sshd, TCP | Leave a Comment »