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


VPS Benchmarks – CPU & I/Ops + RAM Virtual Private Server & Dedicated Server Hosting Head-to-Head

The best VPS is a VPS with no downtime, solid uplink, no overcrowding and no disruption to your services.

Other general factors can play into VPS and offshore hosting when it comes to the law.

Does your web server hosting company respond to abuse reports or DMCA requests?

Do they notify you of new malware or in the wild exploits that affect your services?

I have operated servers with Digital Ocean, Vultr, AWS, OVH, 24shells, HostKey, Alexhost, Packet.net, yourserver.se,

For the purpose of this tutorial we will be looking at various servers and I will be providing the speed tests. The tests verify how fast the CPU’s are and how faste the read/write of the drives are. These are a good indicator of how good a VPS is without taking into consideration business decisions of the VPS company.

VPS Disc Read And Write Speed Test

wget freevps.us/downloads/bench.sh && bash bench.sh -io && rm -f bench.sh*

VPS CPU BenchMark test

wget https://vhwinfo.com/vhwinfo.sh & sh vhwinfo.sh

VPS 10GB File Creation Speed

date && xfs_mkfile 10240m 10Gigfile && date

Vultr VPS Review

Vultr takes a sweet spot in my heart. Why? Because they were how I learned how to linux… At the time when they started they were the cheapest little VPS provider for mission critical ops.

Recently VULTR added their new High Frequency servers with newer CPU’s and NVMe drives!

Here’s one of our tests on a 32GB RAM with 512 NVMe SSD and 8 core servers in Amsterdam:

SO:         CentOS Linux release 7.6.1810 (Core) N 64 bits
kernel: 3.10.0-957.21.3.el7.x86_64
virtual: It is not virtual, is dedicated
cpu: Virtual CPU 6db7dc0e7704
vcpu: 8 cores / 7584.00 bogomips
RAM: 32011 MB (0% used) / swap 0 MB (0% used)
HD: 570G (1% used) / inkling speed 2.1 GB/s
cachefly 10MB: 192 MB/s (probably Gigabit Port)

Disk Speed
I/O (1st run) : 769 MB/s
I/O (2nd run) : 743 MB/s
I/O (3rd run) : 763 MB/s
Average I/O : 758.333 MB/s

[[email protected] ~]# date && xfs_mkfile 10240m 10Gigfile && date
Fri Aug 9 03:34:34 UTC 2019
Fri Aug 9 03:34:44 UTC 2019
10 seconds to create a 10 GB file

Here’s one of our tests on a 2GB RAM with 64GB NVMe SSD and single core servers in Sydney, less consistent but around 50% faster..

SO:         CentOS Linux release 7.6.1810 (Core) N 64 bits
kernel: 3.10.0-957.21.3.el7.x86_64
virtual: It is not virtual, is dedicated
cpu: Virtual CPU 6db7dc0e7704
vcpu: 1 core / 7584.00 bogomips
RAM: 1838 MB (4% used) / swap 0 MB (0% used)
HD: 67G (2% used) / inkling speed 661 MB/s
cachefly 10MB: 215 MB/s (probably Gigabit Port)

Disk Speed
I/O (1st run) : 631 MB/s
I/O (2nd run) : 1.1 GB/s
I/O (3rd run) : 1.0 GB/s
Average I/O : 211.033 MB/s

Disk Speed
I/O (1st run) : 1.0 GB/s
I/O (2nd run) : 1.0 GB/s
I/O (3rd run) : 1.0 GB/s
Average I/O : 1 MB/s

Disk Speed
I/O (1st run) : 774 MB/s
I/O (2nd run) : 1.0 GB/s
I/O (3rd run) : 1.1 GB/s
Average I/O : 258.7 MB/s

[[email protected] ~]# date && xfs_mkfile 10240m 10Gigfile && date
Fri Aug 9 03:35:22 UTC 2019
Fri Aug 9 03:35:32 UTC 2019

10 Seconds to make a 10GB File

Arch WiFi-Menu Auto Connect: Cool ncurses WiFi-Menu Xfce4 Application Bar Launcher

This is a cool little widget to go alongside your xfce4 application toolbars.

This creates a single click WiFi-menu popup on your toolbar or can be used to run WiFi-menu on Arch startup or Xfce4 startup. Works on Debian, Mint, Ubuntu, OpenSUSE, Manjaro

If you have a single WiFi card, and will never plug in dongles, then you can simply add this to a xfce4 launcher or to application startup which can be found in

xfce4-session-settings

Then add this command to application auto-start:

xterm -e "sudo wifi-menu"

Done!

Arch WiFi-Menu Ricing

You can move the terminal to the top right of the screen. First check your screen resolution:

xrandr

Note down your screen resolution after “current: “

E.g. current 1920 x 1080

Decide how big you want your wifi-menu window to be, e.g 50×24

xterm -geometry 50x24+1980+0

I use 1980 as the wifi-menu won’t show up off the screen. If you have dual monitors, you will need to trial and error to get the numbers to your liking.

Then add that to the command

xterm -geometry 50x24+1980+0 -e "sudo wifi-menu" 

arch wifi menu connect on startup auto start debian wifi connect
arch wifi menu connect on startup auto start debian wifi connect

If you use more than one WiFi card or you use Ethernet and Wifi, you will need to specify which network connection to use in WiFi-Menu.

First, note your WiFi card using the command:

sudo ip link

This will list all your available network cards. Your laptop wifi card will be the one with wlp. Change it in the below command.

xterm -geometry 50x24+1980+0 -e "sudo wifi-menu wlpx0x0x0"

If that still doesn’t work or you have the same problem I do on new Lenovo Ideapad laptops with the Wifi driver then do the following:

Create a file somewhere on your computer and name it wifi or your wifi card .sh

touch ~/wlp2s0.sh
nano ~/wlp2s0.sh

I had a WiFi card driver problem with my laptop so my file contains this:

#!/bin/bash
ip link set wlp2s0 down
wifi-menu wlp2s

After you save the file, right click on it > properties > allow executable.

Or just:

chmod +x ~/wlp2s0.sh

Then create a xfce4 toolbar launcher with some cool wifi icon and

xterm -e "sudo ~/wlp2s0.sh

# Enjoy!

How to Record Calls on Twilio with TwiML Automatically

TwiML is Twilio’s amazing markup language for quickly & efficiently deploying new complex voice & SMS services.

Twilio are cloud based software providers of phone systems both landline and mobiles. They even have MMS services that I will cover in later tutorial.

Do you want to record incoming phone calls automatically on Twilio? Read ahead.

First, you need to take advantage of Twilio’s TwiML which is their own markup/scripting language. We use their markup to quickly roll out functions for Twilio’s platform to perform.

First, create a TwiML Bin by going to the menu on the left > Runtime > TwiML Bins.

Twilio Record Calls Using TwiML
Twilio Record Calls Using TwiML

A TwiML Bin is a little notepad that you can write and save your set of instructions to. Better yet, TwiML will host that file for you.

1
2
3
4
5
<Response>
  <Dial record="record-from-answer">
      <Number>+1555555555</Number>
  </Dial>
</Response>

When somebody calls your TwiML number, this markup will tell TwiML to dial +155555555 and if someone answers the call, it will record the call to 155555555. This may be illegal in your country if neither party has consent of the recorded call.

Dial with the record=”record-from-answer” can also be set to record-from-ringing-dual if you want it to record before 155555555 even answers, or even if they don’t answer.

Twilio Markup TwiML Record Calls Code
Twilio Markup TwiML Record Calls Code