Archive for the ‘Scripting’ Category
Posted by jpluimers on 2020/08/13
WSD seems the way Microsoft Windows 8+ does printing, which makes it a lot harder to find the IP address of a printer, for instance to configure a Mac to print to it.
The key seems to be enumerating over HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\SWD\DAFWSDProvider.
Some links that should help me doing this:
–jeroen
Posted in Development, PowerShell, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2020/08/11
Since I keep forgetting that PowerShell is part of WMF (Windows Management Framework) and about the compatibility/installation matrix: [WayBack] Installing Windows PowerShell | Microsoft Docs:
The installation package for PowerShell comes inside a WMF installer. The version of the WMF installer matches the version of PowerShell; there’s no stand alone installer for Windows PowerShell.
If you need to update your existing version of PowerShell, in Windows, use the following table to locate the installer for the version of PowerShell you want to update to.
For historic reference:
Downloads
To upgrade to WMF 5.0 from 4.0 you need to install .net 4.5 or later on your machine first. Then install WMF 5.0 RTM.
–jeroen
Posted in CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2020/08/05
From the update process:
==> Caveats
==> hub
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
zsh completions have been installed to:
/usr/local/share/zsh/site-functions
==> python
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
If you need Homebrew's Python 2.7 run
brew install python@2
You can install Python packages with
pip3 install
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
==> youtube-dl
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
zsh completions have been installed to:
/usr/local/share/zsh/site-functions
==> mpv
zsh completions have been installed to:
/usr/local/share/zsh/site-functions
==> node
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
–jeroen
Posted in Apple, Development, Home brew / homebrew, Power User, Python, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2020/07/09
Various ways are explained at [WayBack] linux – How do I use sudo to redirect output to a location I don’t have permission to write to? – Stack Overflow.
Some are for simple commands and can be a one liner (for instance using tee, or executing a secondary shell).
Others are more suited for longer command sequences.
–jeroen
Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2020/06/25
From a while back, but still relevant as the speed of the GMail web-UI still has not improved.
[WayBack/Archive.is] Peeking under the hood of redesigned Gmail – Boris – Medium
Via:
–jeroen
Read the rest of this entry »
Posted in CSS, Development, GMail, Google, HTML, JavaScript/ECMAScript, Power User, Scripting, Software Development, Web Development | Leave a Comment »
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:
- it is much faster (especially useful in tight loop)
- 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 »
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 »
Posted by jpluimers on 2020/06/10
A while ago, I had to execute a series of aliases of which the names were stored in an array. A simple for loop with en eval call did the job.
Then I found out there are at least two more ways of evaluation in bash, so here are just a few links giving me a head start if I ever dig this up again:
Note that looping over parameters is different than over an array: [WayBack] Loop through an array of strings in Bash? – Stack Overflow
ou can use it like this:
## declare an array variable
declare -a arr=("element1" "element2" "element3")
## now loop through the above array
for i in "${arr[@]}"
do
echo "$i"
# or do whatever with individual element of the array
done
# You can access them using echo "${arr[0]}", "${arr[1]}" also
Also works for multi-line array declaration
declare -a arr=("element1"
"element2" "element3"
"element4"
)
–jeroen
Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »