Ravas coding goodies
-
- Full of knowledge
- Posts: 2106
- Joined: 17 Jun 2013, 13:17
- Distribution: Porteus 3.2.2 XFCE 32bit
- Location: Germany
Ravas coding goodies
Post#136 by donald » 01 Oct 2022, 14:58
ffmpeg -i input.mp3 output.wav
lame --decode input.mp3 output.wav
btw - mpg123 does not work at all in 3.2.2-32bit because the *.la files are missing
in /usr/lib/mpg123/
extracting the slackware mpg123 package and copying the .la files made mpg123 working.
donald
- Rava
- Contributor
- Posts: 5424
- Joined: 11 Jan 2011, 02:46
- Distribution: XFCE 5.01 x86_64 + 4.0 i586
- Location: Forests of Germany
Ravas coding goodies
Post#137 by Rava » 01 Oct 2022, 15:04
Thanks for the heads up on that, donald!
And thanks for the alternatives. Especially important since ffmpeg can also handle other input formats than just mp3, when lame and mpg123 only can handle mp3. (and mp2, but that one is quite rare in the wild)
Is there a way to determine if any of the three choices - lame, ffmpeg or mpg123 produces the best result?
All wav files are of course similar bad since they are based on a lossy mp3 file.
Yours Rava
Rava
- Rava
- Contributor
- Posts: 5424
- Joined: 11 Jan 2011, 02:46
- Distribution: XFCE 5.01 x86_64 + 4.0 i586
- Location: Forests of Germany
Ravas coding goodies
Post#138 by Rava » 04 Oct 2022, 20:03
Not something of a coding goodie, when you want one look here: [FIX] fastest-mirror & wonky network
Instead I found a Pleasant surprise in mousepad
By chance I stumbled upon the 2nd special word that gets treated by mousepad different than other words in a comment-area of code. In my case, the code is sh (bash) script code.
The first time I realized that was years ago when I realized that a
Code: Select all
# TODO Lorem Ipsum
My system XFCE 4.12 / Port 5.0 x86-64 / System Colour Scheme ("Appearance / Style") Adwaita-dark
In my pleasant for the eyes and fitting my dark theme colours scheme in mousepad is set to "Cobalt". I realized for many moons now that having TODO in a comment gets it brightly yellow highlighted.
Usually in Cobalt scheme it is a middle blue on dark blue background - not that readable per se.
But the yellow highlighted TODO stands out.
Cave! When you open a script that not ends in *.sh you have to set the file type manually via
Document > Filetype > Scripts > sh - by default mousepad would display such a script as any normal text file.
By adding some dummy entries to one of my wget.sh scripts I used XXX as placeholder … and realized XXX gets treated the same special way that TODO gets treated.
Probably a picture says more than 1000 words: therefore see the screenshot:

Sadly I have no idea if these special words that get treated in that outstanding way are somewhere listed in the mousepad documentary or not…
Yours Rava
Rava
- Rava
- Contributor
- Posts: 5424
- Joined: 11 Jan 2011, 02:46
- Distribution: XFCE 5.01 x86_64 + 4.0 i586
- Location: Forests of Germany
Ravas coding goodies
Post#139 by Rava » 05 Oct 2022, 03:22
E.g.
Code: Select all
guest@porteus:~$ date +"%Y-%m-%d %H:%M"
2022-10-05 05:22
But you need padding at the front and extra info at the back? Say, for logging purposes. No problemo:
Code: Select all
guest@porteus:~$ date +" %Y-%m-%d %H:%M - script XXX.sh started"
2022-10-05 05:22 - script XXX.sh started
Cave!
While date +%Y-%m-%d works without quotation marks
Code: Select all
guest@porteus:~$ date +%Y-%m-%d
2022-10-05
Code: Select all
guest@porteus:~$ date +%Y-%m-%d %H:%M
date: extra operand ‘%H:%M’
Try 'date --help' for more information.
Code: Select all
date +"%Y-%m-%d"
Yours Rava
Rava
Ravas coding goodies
Post#140 by M. Eerie » 05 Oct 2022, 09:07
Also valid for "FIXME" keyword.
Seems to be a syntax highlightning convention (probably included in gtksourceview)

https://forum.porteus.org/viewtopic.php?p=94310#p94310
https://forum.porteus.org/viewtopic.php?p=102066#p102066
https://forum.porteus.org/viewtopic.php?p=102306#p102306
https://forum.porteus.org/viewtopic.php?p=72741#p72741
M. Eerie
- Rava
- Contributor
- Posts: 5424
- Joined: 11 Jan 2011, 02:46
- Distribution: XFCE 5.01 x86_64 + 4.0 i586
- Location: Forests of Germany
Ravas coding goodies
Post#141 by Rava » 05 Oct 2022, 23:23
Code: Select all
# TODO XXX FIXME
Sadly, it is not that easy to track down as I hoped.
Code: Select all
root@porteus:/usr/share/gtksourceview-2.0# grep -E "TODO|XXX|FIXME" language-specs/sh.lang
<style id="variable" _name="Variable" map-to="def:type"/> <!-- FIXME: need to sort out proper styles for variables -->
root@porteus:/usr/share/gtksourceview-2.0# grep -E "TODO|XXX|FIXME" styles/cobalt.xml
<!-- Bookmarks FIXME -->
Code: Select all
<!-- testing TODO XXX FIXME -->
Yours Rava
Rava
Ravas coding goodies
Post#142 by M. Eerie » 06 Oct 2022, 07:42
All of them seems to intersect @ /usr/share/gtksourceview-3.0/language-specs/def.lang (in my machine).


https://forum.porteus.org/viewtopic.php?p=94310#p94310
https://forum.porteus.org/viewtopic.php?p=102066#p102066
https://forum.porteus.org/viewtopic.php?p=102306#p102306
https://forum.porteus.org/viewtopic.php?p=72741#p72741
M. Eerie
- Rava
- Contributor
- Posts: 5424
- Joined: 11 Jan 2011, 02:46
- Distribution: XFCE 5.01 x86_64 + 4.0 i586
- Location: Forests of Germany
Ravas coding goodies
Post#143 by Rava » 06 Oct 2022, 11:04
I looked for XXX only since I thought that this would hardly appear in a comment itself (like FIXME or TODO could)
Code: Select all
guest@porteus:/$ grep -A 2 XXX /usr/share/gtksourceview-2.0/language-specs/def.lang
<!-- Anything that needs extra attention; mostly the keywords TODO, FIXME and XXX -->
<style id="note" _name="Note (FIXME, TODO, XXX, etc.)"/>
<!-- Text that stands out, HTML links, e-mail addresses, etc. -->
--
<match>\b(FIXME|TODO|XXX)\b</match>
</context>
</include>

Added in 23 hours 25 minutes 44 seconds:
Since I am currently either too busy with RL or too lazy to fully translate partially German commented scripts fully into English, I elaborate a bit on a code by a fellow Porteusian - babam and his getmod.
For those wondering, $$ is the PID (Process ID) of the current process, in this case, the one of the script.Rava wrote: ↑07 Oct 2022, 10:21Thanks for that.
For those curious, this is line 17and this is line 58Code: Select all
ROOTDIR=/tmp/$PKG.$$
Code: Select all
WORKDIR=/tmp/getmod
Very handy since there is always only one program or script that uses that one PID.
Example 1:PID of shell:
Code: Select all
guest@porteus:~$ echo $$
2646
guest@porteus:~$ echo $$
2646
Example 2: we create a test.sh script - by using echo in the terminal:
Code: Select all
guest@porteus:~$ echo '#!/bin/sh
echo my PID is $$' >/tmp/test.sh
guest@porteus:~$ chmod a+x /tmp/test.sh
guest@porteus:~$ /tmp/test.sh
my PID is 2659
guest@porteus:~$ file /tmp/test.sh
/tmp/test.sh: POSIX shell script, ASCII text executable
guest@porteus:~$ cat /tmp/test.sh
#!/bin/sh
echo my PID is $$
guest@porteus:~$
Yours Rava
Rava
Ed_P
- Rava
- Contributor
- Posts: 5424
- Joined: 11 Jan 2011, 02:46
- Distribution: XFCE 5.01 x86_64 + 4.0 i586
- Location: Forests of Germany
Ravas coding goodies
Post#145 by Rava » 07 Oct 2022, 15:13
Thanks. By doing it like this, to me it is the best and easiest way for getting people into script coding - you not even need an editor, just echo and a CLI. (Command Line Interpreter, ours is by standard bash)
Yours Rava
Rava
- Rava
- Contributor
- Posts: 5424
- Joined: 11 Jan 2011, 02:46
- Distribution: XFCE 5.01 x86_64 + 4.0 i586
- Location: Forests of Germany
Ravas coding goodies
Post#146 by Rava » 14 Oct 2022, 02:18
When you only have files by root
|cut -c 19-
Code: Select all
root@porteus:~# ls -oa .bash* .xauth*|cut -c 19-
4314 2022-10-13 11:59 .bash_history
79 2019-12-07 06:40 .bash_profile
1212 2021-01-05 14:39 .bashrc
64 2022-10-13 07:40 .xauthBqqdsN
64 2022-10-13 07:40 .xautho9GpXA
|cut -c 20-
Code: Select all
root@porteus:~# touch .xauthdummy
root@porteus:~# chown guest.users .xauthdummy
root@porteus:~# ls -oa .bash* .xauth*|cut -c 19-
4314 2022-10-13 11:59 .bash_history
79 2019-12-07 06:40 .bash_profile
1212 2021-01-05 14:39 .bashrc
64 2022-10-13 07:40 .xauthBqqdsN
0 2022-10-14 03:48 .xauthdummy
64 2022-10-13 07:40 .xautho9GpXA
root@porteus:~# ls -oa .bash* .xauth*|cut -c 20-
4314 2022-10-13 11:59 .bash_history
79 2019-12-07 06:40 .bash_profile
1212 2021-01-05 14:39 .bashrc
64 2022-10-13 07:40 .xauthBqqdsN
0 2022-10-14 03:48 .xauthdummy
64 2022-10-13 07:40 .xautho9GpXA
Preparations and see the full paths of the symlinks:
Code: Select all
root@porteus:~# mkdir -p /this/should/demonstrate/reallyreallylongpath/
root@porteus:~# touch /this/should/demonstrate/reallyreallylongpath/035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm
root@porteus:~# touch /this/should/demonstrate/reallyreallylongpath/001-core.xzm
root@porteus:~# mkdir base
root@porteus:~# cd base/
root@porteus:~/base# ln -s /this/should/demonstrate/reallyreallylongpath/001-core.xzm /this/should/demonstrate/reallyreallylongpath/035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm .
root@porteus:~/base# ls -o
total 0
lrwxrwxrwx 1 root 59 2022-10-14 03:52 001-core.xzm -> /this/should/demonstrate/reallyreallylongpath/001-core.xzm
lrwxrwxrwx 1 root 121 2022-10-14 03:52 035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm -> /this/should/demonstrate/reallyreallylongpath/035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm
Our demo symlinks need this: ls -o --color=always|cut -c 40-
Code: Select all
root@porteus:~/base# ls -o --color=always|cut -c 40-
001-core.xzm -> /this/should/demonstrate/reallyreallylongpath/001-core.xzm
035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm -> /this/should/demonstrate/reallyreallylongpath/035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm
Let's create a non-symlink dummy file for comparison and I use [ quote ] instead of [ code ] to show the colours:
Now you hopefully see why a "ls -o" can at times be a good idea even when you cut off all permissions, user info and size info, because just a "ls" would not print the symlink targets, and you would also see when there is a broken symlink because ls would display it in red. So let's create a broken symlink to demonstrate:root@porteus:~/base# touch 000-kernel5.4.30.xzm
root@porteus:~/base# ls -o --color=always|cut -c 40-
000-kernel5.4.30.xzm
001-core.xzm -> /this/should/demonstrate/reallyreallylongpath/001-core.xzm
035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm -> /this/should/demonstrate/reallyreallylongpath/035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm
HTH…root@porteus:~/base# rm /this/should/demonstrate/reallyreallylongpath/001-core.xzm
root@porteus:~/base# ls -o --color=always|cut -c 40-
000-kernel5.4.30.xzm
001-core.xzm -> /this/should/demonstrate/reallyreallylongpath/001-core.xzm
035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm -> /this/should/demonstrate/reallyreallylongpath/035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm
Added in 15 minutes 31 seconds:
As comparison, a simply ls would show that there is something wrong with 001-core.xzm - but there are file types that get displayed in red. So let's simulate that as well.

by ls alone - is dummy.xz a broken symlink or is it a valid file (symlink or not) and just a compressed file?root@porteus:~/base# touch dummy.xz
root@porteus:~/base# ls
000-kernel5.4.30.xzm
001-core.xzm
035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm
dummy.xz
ls -o will show us the difference between the red for 001-core.xzm and the red for dummy.xz:
root@porteus:~/base# ls -o --color=always|cut -c 40-
000-kernel5.4.30.xzm
001-core.xzm -> /this/should/demonstrate/reallyreallylongpath/001-core.xzm
035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm -> /this/should/demonstrate/reallyreallylongpath/035-fbreader-0.99.2_deps_qt-4.8.4STRIPPED+liblinebreak-2.1--x86_64.rava.xzm
dummy.xz
Yours Rava
Rava
Ed_P
Rava
- Rava
- Contributor
- Posts: 5424
- Joined: 11 Jan 2011, 02:46
- Distribution: XFCE 5.01 x86_64 + 4.0 i586
- Location: Forests of Germany
Ravas coding goodies
Post#149 by Rava » 14 Oct 2022, 18:01
Look at the lines with either
Code: Select all
MYCOL=$(tput cols)
Code: Select all
| fold -sw $MYCOL
"sleep-timer" was first done via a one liner, until I got sick of that one-liner - because of how I needed editing that one-liner to alter the sleep pause accordingly to the momentarily needs (e.g. 25 minutes for rice cooking, 10 minutes for pasta and such); now in "sleep-timer" that's simply the 1st parameter.
The one liners have been e.g.
Code: Select all
tz;sleep 10m;tz;daueralarm.sh 25
sleep-timer's sole dependency is another script of mine, daueralarm.sh - I already posted that here (using a more English only name since Dauer is German for "permanent" or "certain time that passes") as "sleepalarm.sh" but in my systems the script is called "daueralarm.sh"
If you want to use sleep-timer either tweak the code into it reading "sleepalarm.sh" instead of "daueralarm.sh" or create a symlink named "daueralarm.sh" that points to "sleepalarm.sh".
You first have to make "sleepalarm.sh", look above for its code, and you also need an appropriate sound file that gets your attention as a kind of alarm clock sound while not being overt annoying.
Code: Select all
#!/bin/sh
MYNAME=sleep-timer
MYVERSION=0.1 # blame Rava
#dependencies: daueralarm.sh
#function(s): tz
tz ()
{
echo $(date +%d.%m.%Y\ %H:%M:%S) ____________________________________________________________
}
MYCOL=$(tput cols)
if [ $# -ne 2 ];then
echo $MYNAME v$MYVERSION - I need exactly two parameters:
echo "● Parameter One: The time you want me to sleep. It could be '90' - that is 90 seconds, or '4m' - that is 4 minutes etcetera. When the called command 'sleep' prints an error correct that error and try again."| fold -sw $MYCOL
echo "● Parameter Two: The pause for daueralarm.sh in seconds - e.g. 5 or 30. When daueralarm.sh prints an error correct that and try again. In that case you would not get reminded of the sleep time being over."| fold -sw $MYCOL
exit 1
else
echo $MYNAME v$MYVERSION
echo sleep time: $1
echo pause time for daueralarm.sh: $2
tz;sleep $1;tz;daueralarm.sh $2
fi

This is what it looks like in action:
Code: Select all
guest@porteus:/$ sleep-timer 5m 25
sleep-timer v0.1
sleep time: 5m
pause time for daueralarm.sh: 25
14.10.2022 17:44:16 ____________________________________________________________
14.10.2022 17:49:16 ____________________________________________________________
daueralarm.sh V1.2 - Sounddatei ist /sound/notification_-15dB.mp3
Pausenlaenge: 25 Sekunden - Abbruch mit Strg+C
^C
guest@porteus:/$

Of course sleep-timer could be coded a bit differently:
When only one parameter is given assume that's the sleep time. And presume the user is okay with a longer pause for daueralarm.sh - 25 seconds.
When 2 parameters are given - same as above.
When none or more than 2 are given: error, only explaining that the 2nd parameter is optional, and the 1st is obligatory.
Yours Rava
Rava
- Rava
- Contributor
- Posts: 5424
- Joined: 11 Jan 2011, 02:46
- Distribution: XFCE 5.01 x86_64 + 4.0 i586
- Location: Forests of Germany
Ravas coding goodies
Post#150 by Rava » 15 Oct 2022, 03:56
Source: https://stackoverflow.com/questions/152 ... e-on-linux - thanks niXar & Peter Mortensen ( the later edited it )Most of the answers above are dangerous because they do not deal with names containing odd characters. Your safest bet for this kind of thing is to use find's -print0 option, which will terminate filenames with ascii NUL instead of \n. Here I submit this script, which only alter files and not directory names so as not to confuse find.
find . -type f -print0 | xargs -0n 1 bash -c \
's=$(dirname "$0")/$(basename "$0");
d=$(dirname "$0")_$(basename "$0"); echo mv -f "$s" "$d"'
I tested it and it works with filenames containing spaces, all kinds of quotes, etc.
I added this by myself:
You always find good stuff on the Stack Exchange network - https://stackexchange.com/ - , especially on Stack Overflow - https://stackoverflow.com/ -.Cave! Only ONE directory hierarchy will be transformed from / to _ - aka the "last", rightmost one.
#d=$(dirname "$0")/$(basename "$0"|tr "[A-Z]" "[a-z]"); mv -f "$s" "$d"

Added in 8 minutes 88 seconds:
I altered the above to rename some files. It would have been quicker in doing all three manually, but I wanted to work on the code and tweak it to my needs, and that is an exercise for my brain, while renaming one file at a time is hardly a mental exercise.
Here you go: First we look at the files I wanted renamed:
Code: Select all
root@porteus:/Porteus_modules# find -name 'midori-9.0*'
./midori-9.0-webkit2gtk-2.35.1-x86_64-1.xzm
./midori-9.0-x86_64-1.txt
./midori-9.0-x86_64-1.xzm
Code: Select all
root@porteus:/Porteus_modules# find -name 'midori-9.0*' -print0 | xargs -0n 1 bash -c 's=$(dirname "$0")/$(basename "$0");
d=$(dirname "$0")/005-$(basename "$0"); echo mv -fv "$s" "$d"'
mv -fv ./midori-9.0-webkit2gtk-2.35.1-x86_64-1.xzm ./005-midori-9.0-webkit2gtk-2.35.1-x86_64-1.xzm
mv -fv ./midori-9.0-x86_64-1.txt ./005-midori-9.0-x86_64-1.txt
mv -fv ./midori-9.0-x86_64-1.xzm ./005-midori-9.0-x86_64-1.xzm
Code: Select all
root@porteus:/Porteus_modules# find -name 'midori-9.0*' -print0 | xargs -0n 1 bash -c 's=$(dirname "$0")/$(basename "$0");
d=$(dirname "$0")/005-$(basename "$0"); mv -fv "$s" "$d"'
renamed './midori-9.0-webkit2gtk-2.35.1-x86_64-1.xzm' -> './005-midori-9.0-webkit2gtk-2.35.1-x86_64-1.xzm'
renamed './midori-9.0-x86_64-1.txt' -> './005-midori-9.0-x86_64-1.txt'
renamed './midori-9.0-x86_64-1.xzm' -> './005-midori-9.0-x86_64-1.xzm'
Code: Select all
root@porteus:/Porteus_modules# find -name 'midori-9.0*'
root@porteus:/Porteus_modules# find -name '*midori-9.0*'
./005-midori-9.0-x86_64-1.txt
./005-midori-9.0-x86_64-1.xzm
./005-midori-9.0-webkit2gtk-2.35.1-x86_64-1.xzm
root@porteus:/Porteus_modules#

Yours Rava
Rava