Selenium Stopped Working 2019 Python Selenium Geckodriver Sock Error: Cannot Connect/Create Connection to Browser

I recently upgraded Firefox to the latest build.

Then, my geckodriver binary stopped working in Python.

1
2
3
4
5
6
7
8
firefox --version
Mozilla Firefox 71.0

python --version
Python 3.8.0

/bin/geckodriver --version
geckodriver 0.24.0

The main problem, I had an outdated Geckodriver version (from the distro repo)

1
2
3
sudo pacman -R geckodriver
/bin/geckodriver --version
bash: /bin/geckodriver: No such file or directory

Find the latest version

https://github.com/mozilla/geckodriver/releases/

1
2
3
4
5
6
7
8
9
10
cd /opt
sudo wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz

sudo tar -xzvf geckodriver.tar.gz && rm -f geckodriver.tar.gz

sudo chmod +x geckodriver

sudo chmod 755 geckodriver

sudo cp geckodriver /bin/geckodriver

Geckordriver should be updated to the latest version:

geckodriver --version
geckodriver 0.26.0

OneLiner: Upgrade All PIP and PIP3 Python Packages to Latest Version

“pip3 list –outdated” shows us all installed packages that are currently out of date.

1
pip3 list --outdated

Sample Output

1
2
3
4
5
6
7
8
Package
------------------
certifi
h11
httpcore
importlib-metadata
lit
...

xargs –update, excluding the “Packages” and “——…” header lines

1
2
3
4
sudo pip3 list --outdated | \
awk -F" " '{ print $1 }' | \
grep -v "Package\|------------------" | \
xargs sudo pip3 install --upgrade

And as a one-liner:

1
sudo pip3 list --outdated | awk -F" " '{ print $1 }' | grep -v "Package\|------------------" | xargs sudo pip3 install --upgrade
Auto Upgrade Python PIP Modules Libraries
Auto Upgrade Python PIP Modules Libraries

Install Docker on CentOS 8 – Automatically!

Docker doesn’t come with “stock” repos on CentOS, some variations of alias programs are installations like podman.

These lack many of the core commands of the “real” Docker.

Here is a guide to install Docker Latest Version on CentOS.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
yum clean all -y
yum update -y
yum upgrade -y

dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

DOCKERVERSION=$(dnf list docker-ce --showduplicates | \
sort -r | \
grep "docker-ce.x86_64" -m1 | \
sed -e 's/docker\-ce\.x86\_64//g' -e 's/docker\-ce\-stable//g' | \
tr -d [:space:])

echo "Installing docker-ce-$DOCKERVERSION"

# remove this line in auto environments
read -p "Does this look right? Ctrl C to stop."

dnf install containerd -y

dnf install docker-ce-$DOCKERVERSION -y

# if the above fails, try the latest compatible via
dnf --nobest install docker-ce-$DOCKERVERSION --nobest -y

Generate Random Numbers on Bash or Shell Using Builtins $random

As we all know, the shell builtin variable $RANDOM is a pseudo random number generator.

Today, we will be looking at some creative ways to generate psuedo random numbers, trying to use shell builtins as much as possible.

The Best Solution is shuf (not exactly builtin though)

1
2
3
4
# Shuffle and return n'th line of range
shuf --head-count="1" --input-range="1-10000"
shuf -n1 -i1-10000
9523

Ways to generate various strings of numbers in BASH

1
2
3
# Generate a number between 0 - 32767
echo $RANDOM
7469

$RANDOM Caveats

From the 2 above scenarios, we analyse the distribution of the digits and find out the frequency of each value in order to see how random they really are:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Count the frequency of numbers in a 10000 samples
# cut -c1 chops the first digit from our variable

for i in $(seq 1 1000); do
    RNUMS+=($(cut -c1 <<< $RANDOM))
done

### OR

while [[ $COUNTER -le 1000 ]]; do
     RNUMS+=($(cut -c1 <<< $RANDOM))
     COUNTER=$COUNTER+1
done

# show RNUMS array length, should be 1000
echo ${#RNUMS[@]}

Now, we want to test the frequency of each digit:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
for n in ${RNUMS[@]}; do
    case $n in
        1 ) ((ones++))
            ;;
        2 ) ((twos++))
            ;;
        3 ) ((three++))
            ;;
        4 ) ((fours++))
            ;;
        5 ) ((fives++))
            ;;
        6 ) ((sixes++))
            ;;
        7 ) ((sevens++))
            ;;
        8 ) ((eights++))
            ;;
        9 ) ((nines++))
            ;;
        0 ) ((zeros++))
            ;;
    esac
done

echo $ones $twos $threes $fours $fives $sixes $sevens $eights $nines $zeros

Strangely, the output expected should be ~100, ~100, ~100…

However, the output is totally different:

330 367 108 22 41 28 30 42 33

Creative Ways To Generate Bad Random Numbers In Bash

The second digit from $RANDOM$RANDOM

cut -c2 <<< $RANDOM$RANDOM

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# cut the 2nd digit from RANDOMRANDOM
# $RANDOM's minimum value is 1 therefore the second digit should always be there
# Do not use this value on its own though, as it clearly is not random
while [[ $COUNTER -le 1000 ]]; do
     RNUMS+=($(cut -c2 &lt;&lt;&lt; $RANDOM$RANDOM))
     COUNTER=$COUNTER+1
done
# frequency test
111 114 92 97 86 87 89 95 105 125

# again
120 100 108 93 100 97 78 83 97 125

# CLEARLY NOT RANDOM

A digit from $(date +%N)

cut -c9 <<< $(date +%N)

1
2
3
4
# Print the time in nanoseconds of the current moment
# Do not use this value on its own though, as it clearly is not random
date +%N
277936336
1
2
3
4
5
6
7
while [[ $COUNTER -le 1000 ]]; do
     RNUMS+=($(cut -c9 &lt;&lt;&lt; $(date +%N)))
     COUNTER=$COUNTER+1
done
# frequency test
103 89 105 92 102 104 100 106 91 109
# DECENTLY RANDOM

A digit from cksum <<< $RANDOM$RANDOM

cut -c2 <<< $(cksum <<< $RANDOM$RANDOM)

1
2
3
# Checksum $RANDOM$RANDOM
echo $(cksum &lt;&lt;&lt; $RANDOM$RANDOM)
277936336
1
2
3
4
5
6
7
8
9
10
11
while [[ $COUNTER -le 1000 ]]; do
     RNUMS+=($(cut -c2 &lt;&lt;&lt; $(cksum &lt;&lt;&lt; $RANDOM$RANDOM)))
     COUNTER=$COUNTER+1
done
# frequency test
128 123 91 78 101 95 85 86 92 122
# again
124 111 110 79 82 91 100 103 84 117
# and again
126 118 104 92 101 85 88 87 86 114
# CLEARLY NOT RANDOM!

A digit from cksum <<< $(($RANDOM*$RANDOM))

cut -c2 <<< $(cksum <<< $(($RANDOM*$RANDOM)))

1
2
3
4
5
6
7
8
9
# Checksum $RANDOM x $RANDOM
while [[ $COUNTER -le 1000 ]]; do
     RNUMS+=($(cut -c2 &lt;&lt;&lt; $(cksum &lt;&lt;&lt; $(($RANDOM*$RANDOM)))))
     COUNTER=$COUNTER+1
done
# and analysis
112 127 107 103 88 84 106 85 81 108
126 106 97 99 85 99 88 83 105 113
# CLEARY NOT RANDOM!

Shuf 1-10

shuf -n1 -i1-10

1
2
3
4
5
6
7
8
9
# Shuffle 1-10
while [[ $COUNTER -le 1000 ]]; do
     RNUMS+=($(shuf -n1 -i1-10))
     COUNTER=$COUNTER+1
done
# and analysis
95 107 76 93 113 88 116 109 110
101 95 116 100 107 109 83 91 103
# GREAT RANDOM NUMBER GENERATOR


Fibonacci Counter In Pure Bash

The Fibonacci sequence is a mathematical sequence of numbers such that the result is the sum of the previous two numbers in the sequence starting at x=0 and y=1. Hence,

z = x + y

We can write a script to calculate this function in bash or shell commands.

First, I needed to visualize the idea:

1
2
x + y = z
z + y = z2

To help us figure this out we need to see what happens after the first iteration to work out how to change our variables and then send them through a loop.

1
2
3
4
5
6
7
x=0
y=1
z=0
# first time
z=$(( x + y ))
echo $z
Output~:$ 1

After the first time the sequence happens we need to add “x and y” again. On the second run z should be increased too. So how do we assign them?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# when we add x + y, then z became 1
# but now we need to to be replace y and then x for the second run.
# We can build a small tree to see what's happening

x   y   z
0 + 1 = 1
1 + 1 = 2
1 + 2 = 3
2 + 3 = 5
3 + 5 = 8
5 + 8 = 13
8 + 13= 21

# the z comes from nowhere else but the result of what we are about to do
# but we now know what we need to use in the second run, third run, and so on.
# We should make x now become y
x=$y

# and then y become z! $y needs to be give its value to x right
# before we give $y a new value from $z
y=$z

Now, how do we loop it? We can use a while loop. This while loop simply checks if $x is true. Whenever $x has a value, it will run. Hence, it will run forever.

1
2
3
4
5
6
7
y=1
while true; do
  let z=x+y
  echo $z
  x=$y
  y=$z
done

Here’s the result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
[[email protected] ~]$ y=1
[[email protected] ~]$ while true; do
>   let z=x+y
>   echo $z
>   x=$y
>   y=$z
> done
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
832040
1346269
2178309
3524578
5702887
9227465
14930352
24157817
39088169
63245986
102334155
165580141
267914296
433494437
701408733
1134903170
1836311903
2971215073
4807526976
7778742049
12586269025
20365011074
32951280099
53316291173
86267571272
139583862445
225851433717
365435296162
591286729879
956722026041
1548008755920
2504730781961
4052739537881
6557470319842
10610209857723
17167680177565
27777890035288
44945570212853
72723460248141
117669030460994
190392490709135
308061521170129
498454011879264
806515533049393
1304969544928657
2111485077978050
3416454622906707
5527939700884757
8944394323791464
14472334024676221
23416728348467685
37889062373143906
61305790721611591
99194853094755497
160500643816367088
259695496911122585
420196140727489673
679891637638612258
1100087778366101931
1779979416004714189
2880067194370816120
4660046610375530309
7540113804746346429
-6246583658587674878
1293530146158671551
-4953053512429003327
-3659523366270331776
-8612576878699335103
6174643828739884737
-2437933049959450366
3736710778780434371
1298777728820984005
5035488507601418376
6334266236422402381
-7076989329685730859
-742723093263328478
-7819712422949059337
-8562435516212387815
2064596134548104464
-6497839381664283351
-4433243247116178887
7515661444929089378
3082418197812910491
-7848664430967551747
-4766246233154641256
5831833409587358613
1065587176432717357
6897420586020075970
7963007762452793327
-3586315725236682319
4376692037216111008
790376311979428689
5167068349195539697
5957444661174968386
-7322231063339043533
-1364786402164075147
-8687017465503118680
8394940206042357789
-292077259460760891
8102862946581596898
7810785687120836007
-2533095440007118711
5277690247113717296
2744594807106598585
8022285054220315881
-7679864212382637150
342420841837678731
-7337443370544958419
-6995022528707279688
4114278174457313509
-2880744354249966179
1233533820207347330
-1647210534042618849
-413676713835271519
-2060887247877890368
-2474563961713161887
-4535451209591052255
-7010015171304214142
6901277692814285219
-108737478489928923

bulk Delete Comment Spam From Existing Blacklist

To bulk delete comments, we are going to use phpmyadmin. Most hosting panels have /phpmyadmin active on your account.

Log into phpmyadmin and click on your database on the LEFT, then wp_comments or whatever database prefix you are using.

Then head to Search

Bulk Delete Comment Spam From WordPress
Bulk Delete Comment Spam From WordPress

Scroll down to comment_content and set the Operator column to %LIKE%, which matched wildcard anything before or after your term.

For this example, we are going to use the word sex:

Bulk Search and Delete from WordPress Comment Database
Bulk Search and Delete from WordPress Comment Database

You will receive a valid SQL query that we are going to reuse.

Bulk Search Comments WordPress Then Delete
Bulk Search Comments WordPress Then Delete

All you need to do is replace SELECT * with DELETE FROM

WARNING: If you have any of the terms elsewhere in your comments database, they will be deleted.

Don’t do this if you don’t know what you are doing.

Now, get your Comment Blacklist ready.

Open Text Mechanic here so we can prefix and suffix our list: https://textmechanic.com/text-tools/basic-text-tools/add-prefixsuffix-into-line/

Paste your comment spam blacklist at the top.

Add the Prefix as DELETE FROM…..%

And the Suffix as %’;

Don’t forget the ; at the end as we are using multiple lines

Delete Comment Spam Bulk From WordPress Blacklist SQL
Delete Comment Spam Bulk From WordPress Blacklist SQL

Then in phpmyadmin paste your list of SQL deletions into the SQL section and press SIMULATE QUERY

Bulk Delete WordPress Comments Table WordPress
Bulk Delete WordPress Comments Table WordPress

Anti-warning: since this is our actual “comment blacklist” already from the WordPress comments section, these comments would not have passed the filter anyway.

Simulate Query will show you what will be deleted when you press Go.

MYSQL Bulk Delete WordPress Comment Query
MYSQL Bulk Delete WordPress Comment Query

If all looks good, close the simulated query window and hit GO to permanently delete comments on your WordPress database that match your blacklist.

Wordpress Comment Spam Before
WordPress Comment Spam Before

My comment database went from 6000 to 1500!

Wordpress Comment Spam After
WordPress Comment Spam After

My comment blacklist can be downloaded here.




Screen Blurry After Updating Arch Linux – AMD Pixelated Artifacts and Graphics Issue

After updating to the rolling release of Arch from a few days before, my desktop began to pixelate.

The new AMD Ryzen with Radeon graphics laptops, particularly the Ideapad & Thinkpads, have a problem with the Xfce window manager compositor.

Does your screen look like this?

Arch Desktop Blurry After Update Pixelated Graphics Problem Screen Tearing Artifcats
Arch Desktop Blurry After Update Pixelated Graphics Problem Screen Tearing Artifcats

I tried to record the blur but it didn’t show the issue in the recording.

The problem is with the Xfce4 Window Manager.

Solution: Go to Window Manager Tweaks and disable Window Compositing.

xfce Window Manager Tweaks
xfce Window Manager Tweaks
Xfce Window Manager Compositor Settings Turn Off Bug
Xfce Window Manager Compositor Settings Turn Off Bug

Uncheck the display compositing box.

If you re-check the box, it may make your screen go blank. This happened to me. Simply reboot.

This problem is very common, and occurs on fresh installs.

See the following posts about it:

https://forum.manjaro.org/t/graphical-glitches-artifacts-after-update-to-xfce-4-14/99049/16

https://bbs.archlinux.org/viewtopic.php?id=248543

https://forum.xfce.org/viewtopic.php?id=13233

https://bbs.archlinux.org/viewtopic.php?pid=1859321#p1859321

https://bbs.archlinux.org/viewtopic.php?id=248840

Until the bug is fixed, simply disable the compositor.

I will update this post once the compositor for xfce4 window manager is fixed.

How To Install DigiDoc4 on Arch Linux – E-Estonia

Here are instructions to install the DigiDoc4 software for Estonian E-residents on Arch Linux.

ccid is required to use your card reader. If you have an ACS card reader, you need acsccid too

1
2
# ccid required, acsccid if you have an ACS card reader, and pcsc-tools just to check if its working
sudo pacman -S ccid acsccid pcsc-tools

Install opensc from git because opensc in the main Arch repo does not yet contain drivers for EstEID 2018+.

1
yay opensc-git

After installing opensc-git from git, start pcscd as a service

1
2
3
4
# start pcscd service
sudo pcscd
# insert card reader and run a scan from pcsc-tools
pcsc_scan

We are using opensc-git instead of opensc. Since opensc is a required dependency of DigiDoc4 in the AUR, you first need to edit the PKGBUILD and remove opensc entry and then run the yay install.

1
2
3
4
5
6
# this will download the PKGBUILD of qdigidoc4 so we can delete opensc from it
yay -G qdigidoc4

# remove the opensc dependency with vi/nano
cd qdigidoc4
vim PKGBUILD

Once you have removed opensc from the dependencies,

1
2
3
4
# make qdigidoc4 from the AUR without opensc as a dependency. We are using opensc-git instead.
makepkg -si
# wait until install is finished and you should be able to run qdigidoc4 now
qdigidoc4

Insert your card reader and you should see your card details in DigiDoc4!

1
2
3
# later install the token signing software
yay chrome-token-signing
modutil -dbdir sql:$HOME/.pki/nssdb -add opensc-pkcs11 -libfile onepin-opensc-pkcs11.so -mechanisms FRIENDLY

You can test if the card works at logging you into RIK.EE via the https://ariregister.rik.ee/login.py or https://ettevotjaportaal.rik.ee/

More information can be found here if this tutorial becomes out of date: https://wiki.archlinux.org/index.php/Electronic_identification#Estonia

Estonia RIK Signing Linux Arch
Estonia RIK Signing Linux Arch

Remmina CLI – Shortcut For Open Remmina Profile on Linux Arch, Debian, Ubuntu, Mint, SNAP

Do you often have to open Remmina? Create a shorcut to your Remmina profile and add it as a desktop launcher, or even a keyboard shortcut.

If you installed Remmina without Snap, simply go to your Remmina config folder and choose which profile you want to open.

Your profiles are in /home/$user/.remmina/

Right click, and copy the profile you want.

The prefix what you just copied with remmina -c option.

The c means, “Connect to desktop described by file (.remmina or type supported by plugin)”

remmina -c /home/$user/.remmina/PROFILE.remmina

If you installed Remmina with Snap or Snapcraft, then your Remmina config files are located elsewhere.

First, search for your application with an application finder to get the Snap environment full path.

Right click on your entry and copy the application launcher command.

Remmina Snapcraft Command Open Profile With Terminal
Remmina Snapcraft Command Open Profile With Terminal

Add -c and to the end of this and get ready to add the config file that you want to open:

Open Remmina and highlight the profile you want to use.

In the bottom status bar of the window, you should see a path to .remmina file. It should be:

/home/$user/snap/remmina/current/.local/share/remmina/

Navigate to that folder and copy the profile that you want.

Environment-Path, -c, Config-File

env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/desktop/applications/remmina_remmina.desktop /var/lib/snapd/snap/bin/remmina -c /home/$user/snap/remmina/current/.local/share/remmina/$CONFIG.remmina

The -c isn’t actually required.

When doing this, you may be asked to enter the profile password again.

Remote Desktop Copy Paste Remmina Clipboard Not Syncing Properly – Parcellite Arch Linux

This post fixes problems with Remmina Clipboard not syncing correctly between host and remote desktops and fixes copy and paste on remote desktop not working on linux.

When you highlight text and hit Ctrl+C, and then press Ctrl+P elsewhere, this is called a Clipboard Copy & Paste.

When you highlight text, and then middle click (scroll mouse 3 button) elsewhere, this is called Primary Clipboard Copy & Paste.

These two clipboards can become out of sync when using a remote desktop, especially when you alternate between pressing Ctrl+C and Right Click > Copy on the remote desktop.

There is a software package on Arch, Ubuntu, Debian, CentOS, Manjaro, OpenSUSE, etc. called parcellite and xdotool

# debian and ubuntu users
sudo apt-get install parcellite xdotool

# arch and manjaro users
sudo pacman -S parcellite xdotool

# centos redhat or rpm users
yum install parcellite xdotool

Parcellite adds clipboard functionality.

xdotool allows you to use commands to press keys on the keyboard.

Remmina remote desktop copy paste not working

If you want to press Ctrl+C or right click copy on something on your remote desktop, then you should have Parcellite running to capture the clipboard copy event.

parcellite settings remmina clipboard sync

Above is a screenshot of the Parcellite settings.

If you tick the Use Copy box, this means Parcellite will hook into your Ctrl C Clipboard, so whenever you press Ctrl C, it will be stored in Parcellite.

When you Right Click copy on linux, this goes onto BOTH clipboards, even if they are not Syncronized because you have just copied the text by highlighting it (Primary) and also Copy by right click copying.

However, on the remote desktop, if you highlight text, nothing will happen. And when you right click copy on remote desktop it goes onto your Clipboard Selection clipboard.

Then press Ctrl + V to paste that anywhere.

Therefore, when using Remmina, tick both boxes but not the synchronize button.

When using remmina or remote desktop you need to decide to use Ctrl C all the time and uncheck synchronize clipboard, or…

When using both Right Click Copy OR Ctrl C on remmina check the synchronize keyboard button but don’t highlight stuff on your localhost. This is pretty hard to stop yourself from doing.

If you press Ctrl C on remote desktop without synchronizing the clipboards, you will be able to paste with both Ctrl V but not middle click.

If you press Ctrl C on remote desktop and have clipboards synced, you will be able to Ctrl V paste on localhost AND middle click paste. BUT if you highlight anything on your localhost it will overwrite your clipboard because you primary clipboard copied something.

If you right click copy on remote desktop without synchronizing the clipboard, you will sometimes be able to paste using Ctrl V but not using middle click. Sometimes it does Ctrl V paste, but it is delayed and laggy as it fetches the remote clipboard.

If you right click copy on remote desktop and have clipboards synced, you will be able to middle click paste but not Ctrl V paste.

This is what I have found when trying to copy and paste using Remmina and Arch Linux. Here are my settings:

Parcellite Settings for Remmina Remote Desktop Copy Paste Not Working Sometimes
Parcellite Settings for Remmina Remote Desktop Copy Paste Not Working Sometimes