Tuesday, December 22, 2020

Stripping spaces from filenames

 Here is a handy script for stripping spaces from filenames in a directory and all of its subdirectories:


function strip_spaces_from_files {

  for i in *


    newfilename=$(echo $i | tr -s ' ' | tr ' ' '_')

    if [ -e "$newfilename" ]


      echo "$newfilename does not contain any spaces"


      echo "stripping spaces from $newfilename"

      mv "$i" "$newfilename"





echo "Stripping spaces from current directory $INITIALDIR"


echo "Stripping spaces from sub directories"

for subd in $(find ./ -type d)


  strippingdot=$(echo "${subd}"|sed 's/^..//')

  echo "switching to directory $INITIALDIR/$strippingdot"

  cd $INITIALDIR/$strippingdot

  echo "stripping spaces"


  echo "going back to initial directory $INITIALDIR"



Friday, December 11, 2020

Validating yaml with python

 python -c 'import yaml, sys; yaml.safe_load(sys.stdin)' < url-monitor-extension-config.yml

Thursday, November 26, 2020

Python introspection blog post

 A great blog post about how to use python modules to inspect python code itself can be found here

Thursday, April 16, 2020

Veiryfing ssh fingerprints of a system

When trying to connect to a system via ssh for the first time you will get a message that you need to trust the ssh fingerprint of that system.

How do you know if the fingerprint displayed is the correct one, or if there is a man in the middle attack going on?

If you have another terminal open on the system you have you can go to /etc/ssh and execute the following:

for file in *sa_key.pub
do   ssh-keygen -lf $file

This will diplay the ssh fingerprints valid for this system so you can double check them.

Sunday, March 8, 2020

Enabling multiple displays with Thinkpad P52

When switching to power save mode nvidia disables the graphics card multiple display support.

It does not enable it back when switching to performance mode. This was done by creating a file in /lib/modprobe.d/nvidia-kms.conf and setting modeset to 1.

We can revert this change by changing the modeset to 0 or commenting this line. After rebooting, the external display works again.

Saturday, February 15, 2020

Separating filename from extension in bash

If we want to separate filename from extension in bash this is a neat and useful trick:

filename=$(basename -- "$fullfile")

Wednesday, January 22, 2020

Prioritization of network interfaces

If we have more than one network interfaces and want to prioritize routing via one of them we can do the following:

Check the priorities in the routing table:

/home/nickapos [nickapos@nickapos-ThinkPad-P52] [8:44]
> ip route                    
default via dev enp0s31f6 proto dhcp metric 100
default via dev wlp0s20f3 proto dhcp metric 600

Here we can see that we have two interfaces with different metric values enp0s31f6 has higher priority than wlp0s20f3, if we want to swap them we need to install ifmetric with
sudo apt install ifmetric 
and do:

sudo ifmetric wlp0s20f3 99

After this if we check the routing table:

/home/nickapos [nickapos@nickapos-ThinkPad-P52] [8:45]
> ip route                 
default via dev wlp0s20f3 proto dhcp metric 99
default via dev enp0s31f6 proto dhcp metric 100

we can see that wlp0s20f3 has higher priority so routing will happen by default through it. Only packages that can not be served by it will be routed via enp0s31f6,