Catégories
Uncategorized

The next iteration of Perl is now a different language called Raku (previously known as Perl6)

Image result for history of raku programming language

It became raku in 2019. I recently became interested in the language after seeing too many short solutions on stackoverflow to ordinary scripting problems I face everyday in my daily work.I usually resolve to bash, awk and sed, but sometimes the solution in those tools is rather cumbersome and awkward, even for simple problems like printing the last line of a file. Sure, you can do that with tail, but why add another process in the pipeline when you can solve all your problems in one process and be efficient?

About the Raku Name

RAKU WARE | History-Roots of Raku ware

The name Raku probably comes from the special kind of vessel used in Japanese tea ceremony.

Why the interest in Raku ?

The starting point was the short perl scripting solutions as mentioned earlier, but what piqued my interest is this particular quote from Lary Walll in a /. interview I found while searching for perl content on lobste.rs. (There’s a summary of it in next paragraph if you don’t want to read it completely). When asked :

It seems that most back-ends are now being written in any number of next-gen scripting languages like Python, JavaScript (NodeJS), and Swift. I don’t see the advantages of these, but it’s often hard to explain to colleagues, CTOs, managers, etc. the value of Perl over the newest trends. And Perl « 6 » is meaningless because to everyone else it’s still Perl. Why should we choose Perl 6 over the new establishment?

He simply responded

Because it’s the next generation after all those languages you mentioned.

He answered similarly to another question asked by user drakaa :

Perl used to be central to so many things (the ‘glue’ language for the internet), but seems to be slowly falling out of use in deference to JavaScript, Java, Python, VBScript/PowerShell, etc. It’s the language I used in my first job as a system administrator (back around the time you gave your first interview), and I loved it.

With so many years between the announcement of Perl 6 and it’s completion, many people moved on to other solutions or technologies. Perl 6 is here now, but why should I use it?

with :

Because it’s the next generation after all those languages you mentioned. Or maybe it’s several generations beyond that, but showed up early. 🙂

Elements of interest

While reading the interview and a couple other links, I took notes of what would possibly encourage me to learn more about this new language :

  • Supports multiple paradigms like OO, FP and CP. This means that you don’t have to switch language if you want to switch paradigms.
  • It allows you to solve your problem in more than one way, it doesn’t enforce you to use a certain way, there’s no cultural acceptance about what’s the proper way to do it. For example, python’s culture enforces you to use list comprehensions as the right way to process your lists. Perl offers you more than one way to process a list.
  • python has a global interpreter lock, perl 6 has a concurrency model that can scale up to multicore which avoids bottlenecks. It borrows from languages such as haskell, c#, go and erlang.
  • python’s object model just gives you hooks to its internal representation of classes and objects, raku gives a coherent meta-object model. For example, there is no simple way to create a singleton in python (see borgs).
  • python doesn’t provide the benefits of lexical scoping, closures, laziness nor does it encourage you to think that way.
  • Raku is concise
  • very good and early unicode support compared to competitors (I’m looking at you python2 !)
  • event loop aware scheduler
  • continuations

Elements of confusion

It is true that Raku has some elements of seduction, but it also has its own quirks, like any other language I guess. While skimming through documentation and various links, there are a few things that looked a little odd and that needed clarification / proper learning. For example, consider this line of code :

f() = 42;

It seems like you are calling a function f, which returns something, then assign 42 to that, but you don’t store that value anywhere so it’s immediately thrown away… « Normal » code would look like this :

x = f();

x = 42;

But even then, what’s the point of assigning x the result of f() if you are immediately overriding it with 42?

So I went to IRC, joined #raku and asked

[16:17] <ychaouche> can't understand this yet : f() = 42;
[16:18] <lizmat> that function f() returns a container
[...]
[16:19] <lizmat> m: my $bar; sub foo() is raw { $bar }; foo() = 42; say $bar
[16:19] <camelia> rakudo-moar ec4522404: OUTPUT: «42␤»
[16:19] <lizmat> the "is raw" on the sub makes sure it doesn't de-containerize (which is the default)

So what happens in lizmat code is that the variable $bar is created outside function foo(), and also modified outside of foo() (there is no code modifying $bar inside of foo).

The next line of code f()=42; will modify $bar as shown in camelia's output (it’s the bot that executes code you give to it when you start your sentence with m: as lizmat did) . Isn’t that interesting ?

is raw and is rw, same or different ?

Searching for the concept of raku containers, I saw the docs use is rw instead of is raw used in lizmat’s example. Consider this code :

my $x = 23;

sub f() is rw { $x };

f() = 42;

say $x;         # OUTPUT: «42␤»

Are those two the same thing with different spellings or are they two different things ? according to lizmat, they’re different, and so it is something I need to add to my to-learn list.

To-learn list

In addition to the is rw and is raw keywords(?) that I need to learn, the intro page warns the newcomer of 3 concepts that raku seem to do differently than the competition, these are :

  1. signatures
  2. containers
  3. classes and roles

It also enumerate a few traps to avoid in a dedicated page. All of which I need to add to my to-learn list.

End of part 1

I hope I’ll write more blog posts about my journey in learning this language, I do not expect to write more than this page to be honest, I’ll soon have to swtich tasks and switching tasks often leads to switching interests. What inspired me to write this blog post is two things :

  1. Raku’s community page encourages new language learners to share their experience
  2. the hope to get feedback that would accelerate my learning, put me on the right tracks and avoiding wrong routes.

Coincidentally, a tweet appeared on my timeline in about the same time, from @Ehabcoder, who is about to work in his new blog

Let’s see where this leads.

Catégories
Uncategorized

How to insert counters in your e-mail ?

Ceci est un compteur

et pourtant, il est sur un blog wordpress, où le javascript n’est pas autorisé, tout comme les e-mails. Alors, comment ils ont fait ?

Si comme moi vous avez consulté la source, vous pouvez vous appercevoir qu’il s’agit en fait d’une image GIF. L’idée est géniale : il suffit que la GIF soit générée au moment où la requête HTTP est faite. Vous avec donc un décompte réel, d’environ 1 minute, à partir du moment où vous visualisez le truc. Vous oubtenez donc une GIF différente à chaque rechargement de page, ou consultation d’e-mail !

Catégories
Uncategorized

cool-retro-term is cool

fteqvox

And easily buildable too (needs QT5. You might not find a package for your own distro.

For Mint, you need these dependencies :

apt-get install build-essential qmlscene qt5-qmake qt5-default qtdeclarative5-dev qtdeclarative5-controls-plugin qtdeclarative5-qtquick2-plugin libqt5qml-graphicaleffects qtdeclarative5-localstorage-plugin qtdeclarative5-window-plugin qtdeclarative5-dialogs-plugin

Then you simply qmake, make and make install from the source : https://github.com/Swordfish90/cool-retro-term

 

Catégories
Uncategorized

zipgrep greps inside zip files

That’s all.

Just keep in mind it might consume a little bit of cpu if you’re searching your firefox extensions for eg.

bsmn3jb

Catégories
Uncategorized

02/12

Ça va bientôt être le 2 décembre, et comme chaque année, en Algérie, pays musulman, de tradition musulmane, de moeurs musulmanes, on nous demande de mettre des capotes.

C’est comme si vous disiez que « celui qui trompe sa femme sans mettre de préservatif c’est un gros batard. »

 

 

Non, celui qui trompe sa femme est un batard. Point.

Catégories
Uncategorized

Mise à jour d’un fichier d’alias

Dans cet article, je montre comment tester le resultat d’une commande sous bash, à utiliser à l’interieur d’un if par exemple.

Context : je m’en sert ici pour mettre à jour un fichier d’alias (addresses e-mail). Si l’addresse ne figure pas déjà dans le fichier, l’ajouter.

1/ On cherche toutes les boites qui sont dans la base de données (searchmailbox.sql est un simple script bash qui cherche des e-mails dans la base de données)

root@messagerie-secours[CHROOT]10.10.10.19 ~/SCRIPTS/MAIL # ./searchmailbox.sql @mydomain.tld | awk ‘{print $2}’

sdg.eprs@mydomain.tld
chabane.lounakel@mydomain.tld
n.chabi@mydomain.tld
saad.taraf@mydomain.tld
mustafa.benaoumeur@mydomain.tld
djilali.merad@mydomain.tld
abdelmadjid.aissa@mydomain.tld
root@messagerie-secours[CHROOT]10.10.10.19 ~/SCRIPTS/MAIL #

On peut rediriger vers un fichier temporaire pour enlever les lignes vides et les titres des colonnes (e-mail / name).

2/ Ensuite, il faut chercher chaque boite dans le fichier alias et ne lister que celles qui ne sont pas trouvées.

root@messagerie-secours[CHROOT]10.10.10.19 ~/SCRIPTS/MAIL # while read -r box; do if ! grep -q $box /etc/postfix/maps/global; then echo $box; fi; done < /tmp/allboxes
postmaster@mydomain.tld
ms.saidi@mydomain.tld
chadly-disabled@mydomain.tld
pf-admin@mydomain.tld
arch-admin@mydomain.tld
it-m.a.m@mydomain.tld
z.timtaoucine@mydomain.tld
m.stefan-disabled@mydomain.tld
ntp@mydomain.tld
it-helpdesk@mydomain.tld
owncloud@mydomain.tld
meteo@mydomain.tld
it_support@mydomain.tld
application@mydomain.tld
it-sys@mydomain.tld
panarab@mydomain.tld
saad.taraf@mydomain.tld
mustafa.benaoumeur@mydomain.tld
djilali.merad@mydomain.tld
abdelmadjid.aissa@mydomain.tld
root@messagerie-secours[CHROOT]10.10.10.19 ~/SCRIPTS/MAIL #

Il y a donc, depuis la dernière fois que j’ai mis à jour l’alias, quelques nouvelles boites, judicieusement mises à la fin, sans doute à cause de leur ordre d’insertion dans la base de données. Je n’ai plus qu’à les ajouter à mon fichier global.

 

Catégories
Uncategorized

Sur les bienfaits de la colonisation

Avant la colonisation :

ychaouche@ychaouche-PC 11:24:18 ~ $ apt-cache search libqt5 --names-only | head
libqt53d5 - Qt 3D module
libqt5clucene5 - Qt 5 CLucene module
libqt5concurrent5 - Qt 5 concurrent module
libqt5contacts5 - Qt PIM module, Contacts library
libqt5core5a - Qt 5 core module
libqt5dbus5 - Qt 5 D-Bus module
libqt5designer5 - Qt 5 designer module
libqt5designercomponents5 - Qt 5 Designer components module
libqt5feedback5 - Qt Feedback module
libqt5gui5 - Qt 5 GUI module
ychaouche@ychaouche-PC 11:29:07 ~ $

Après la colonisation :

ychaouche@ychaouche-PC 11:29:07 ~ $ apt-cache search libqt5 --names-only | head | sed 's/ - /%/' | column -t -s %
libqt53d5                  Qt 3D module
libqt5clucene5             Qt 5 CLucene module
libqt5concurrent5          Qt 5 concurrent module
libqt5contacts5            Qt PIM module, Contacts library
libqt5core5a               Qt 5 core module
libqt5dbus5                Qt 5 D-Bus module
libqt5designer5            Qt 5 designer module
libqt5designercomponents5  Qt 5 Designer components module
libqt5feedback5            Qt Feedback module
libqt5gui5                 Qt 5 GUI module
ychaouche@ychaouche-PC 11:29:46 ~ $

Comment ça marche ce truc :

Je remarque que les noms de paquets et les descriptions sont séparées par ‘ – ‘. Malheureusement, la commande column ne prend qu’un seul character de séparation, ce qui fait que si ‘-‘ est présent ailleurs, il va me mettre la pagaille dans l’affichage :

ychaouche@ychaouche-PC 11:32:37 ~ $ apt-cache search libqt5 --names-only | head | column -t -s -
libqt53d5                    Qt 3D module
libqt5clucene5               Qt 5 CLucene module
libqt5concurrent5            Qt 5 concurrent module
libqt5contacts5              Qt PIM module, Contacts library
libqt5core5a                 Qt 5 core module
libqt5dbus5                  Qt 5 D                           Bus module
libqt5designer5              Qt 5 designer module
libqt5designercomponents5    Qt 5 Designer components module
libqt5feedback5              Qt Feedback module
libqt5gui5                   Qt 5 GUI module
ychaouche@ychaouche-PC 11:32:40 ~ $

On remarque que D-Bus a été décortiqué en D                 Bus, ce qu’on ne veut pas.

Ce qu’il faudrait s’est prendre tout ‘ – ‘ (espace tiret espace) comme séparateur mais impossible de faire ça va column.

Solution : remplacer ‘ – ‘ par un seul caractère qui n’est pas du tout utilisé ni dans les noms ni dans les descriptions. Sans trop me casser la tête j’ai pris ‘%’ mais ça pourrait être tout autre chose encore plus rare.

J’utilise sed pour m’aider à réaliser cette substitution (la commande s pour substitute)

ychaouche@ychaouche-PC 11:32:40 ~ $ apt-cache search libqt5 --names-only | head | sed 's/ - /%/'
libqt53d5%Qt 3D module
libqt5clucene5%Qt 5 CLucene module
libqt5concurrent5%Qt 5 concurrent module
libqt5contacts5%Qt PIM module, Contacts library
libqt5core5a%Qt 5 core module
libqt5dbus5%Qt 5 D-Bus module
libqt5designer5%Qt 5 designer module
libqt5designercomponents5%Qt 5 Designer components module
libqt5feedback5%Qt Feedback module
libqt5gui5%Qt 5 GUI module
ychaouche@ychaouche-PC 11:34:50 ~ $

On remarque que par exemple le – de D-BUS a bien été sauvegardé.

On essaye de nouveau :

ychaouche@ychaouche-PC 11:34:50 ~ $ apt-cache search libqt5 --names-only | head | sed 's/ - /%/' | column -t -s %
libqt53d5                  Qt 3D module
libqt5clucene5             Qt 5 CLucene module
libqt5concurrent5          Qt 5 concurrent module
libqt5contacts5            Qt PIM module, Contacts library
libqt5core5a               Qt 5 core module
libqt5dbus5                Qt 5 D-Bus module
libqt5designer5            Qt 5 designer module
libqt5designercomponents5  Qt 5 Designer components module
libqt5feedback5            Qt Feedback module
libqt5gui5                 Qt 5 GUI module
ychaouche@ychaouche-PC 11:35:44 ~ $

àlà.

Catégories
Uncategorized

Jun 28 15:14:25 messagerie postfix/postqueue[7275]: fatal: write error: Input/output error

Des milliers de lignes de ce type ont soudainement commencé à apparaître sur mon fichier de log

Jun 28 15:14:14 messagerie postfix/postqueue[7222]: fatal: write error: Input/output error
Jun 28 15:14:15 messagerie postfix/postqueue[7227]: fatal: write error: Input/output error
Jun 28 15:14:16 messagerie postfix/postqueue[7234]: fatal: write error: Input/output error
Jun 28 15:14:17 messagerie postfix/postqueue[7238]: fatal: write error: Input/output error
Jun 28 15:14:18 messagerie postfix/postqueue[7243]: fatal: write error: Input/output error
Jun 28 15:14:19 messagerie postfix/postqueue[7248]: fatal: write error: Input/output error
Jun 28 15:14:20 messagerie postfix/postqueue[7253]: fatal: write error: Input/output error
Jun 28 15:14:21 messagerie postfix/postqueue[7259]: fatal: write error: Input/output error
Jun 28 15:14:22 messagerie postfix/postqueue[7263]: fatal: write error: Input/output error
Jun 28 15:14:23 messagerie postfix/postqueue[7267]: fatal: write error: Input/output error
Jun 28 15:14:24 messagerie postfix/postqueue[7271]: fatal: write error: Input/output error
Jun 28 15:14:25 messagerie postfix/postqueue[7275]: fatal: write error: Input/output error

postfix stop/start n’y a rien fait !

Sur #postfix

https://i0.wp.com/i.imgur.com/Or5B8N6.png

Sur le serveur

root@messagerie[CHROOT][10.10.10.19] ~ # ps ax | grep bash
 3882 pts/5    Ss     0:00 -bash
 9155 pts/5    S+     0:00 grep --color=always bash
14591 pts/7    Ss     0:00 -bash
14614 pts/9    Ss     0:00 -bash
14657 pts/12   Ss     0:00 -bash
14775 pts/7    S      0:00 bash
 7558 ?        S      0:00 bash
14786 pts/9    S      0:00 bash
14814 pts/12   S+     0:01 bash
22057 pts/0    Ss     0:00 -bash
22149 pts/0    S+     0:00 bash
30553 pts/1    Ss     0:00 -bash
30584 pts/1    S      0:00 bash
30763 pts/2    Ss     0:00 -bash
30797 pts/2    S      0:00 bash
30898 pts/3    Ss     0:00 -bash
30932 pts/3    S      0:00 bash
root@messagerie[CHROOT][10.10.10.19] ~ #

Je détecte la ligne avec un « ? », c’est un processus qui n’est associé à aucun tty, donc potentiellement celui qui pose problème. Un petit strace pour voir un peu ce qu’il fait ?

root@messagerie[CHROOT][10.10.10.19] ~ # strace -p 7558
Process 7558 attached - interrupt to quit
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 69}], WSTOPPED|WCONTINUED, NULL) = 7238
rt_sigprocmask(SIG_BLOCK, [CHLD TSTP TTIN TTOU], [CHLD], 8) = 0
ioctl(255, TIOCSPGRP, [7558])           = -1 ENOTTY (Inappropriate ioctl for device)
rt_sigprocmask(SIG_SETMASK, [CHLD], NULL, 8) = 0
ioctl(255, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff0718ff00) = -1 EIO (Input/output error)
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
--- SIGCHLD (Child exited) @ 0 (0) ---
wait4(-1, 0x7fff0718fa9c, WNOHANG|WSTOPPED|WCONTINUED, NULL) = -1 ECHILD (No child processes)
rt_sigreturn(0xffffffffffffffff)        = 0
rt_sigprocmask(SIG_BLOCK, [INT CHLD], [], 8) = 0
pipe([3, 4])                            = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f86b6a7d9d0) = 7240
setpgid(7240, 7240)                     = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
close(3)                                = 0
close(4)                                = 0
ioctl(255, TIOCGPGRP, [0])              = -1 EIO (Input/output error)
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], WSTOPPED|WCONTINUED, NULL) = 7240
rt_sigprocmask(SIG_BLOCK, [CHLD TSTP TTIN TTOU], [CHLD], 8) = 0
ioctl(255, TIOCSPGRP, [7558])           = -1 ENOTTY (Inappropriate ioctl for device)
rt_sigprocmask(SIG_SETMASK, [CHLD], NULL, 8) = 0
ioctl(255, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff0718ffb0) = -1 EIO (Input/output error)
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0

Voilà, le Input/output error semblent venir de là. La prochaine étape a été de killer tous les process bashs que j’avais créé le matin.

Catégories
Uncategorized

Batch thumbnail creation from the command line

for file in 100_029* 100_03*; do convert $file -resize 25% resized/$file; done;
Catégories
Uncategorized

Server down

https://i0.wp.com/i.imgur.com/UHFjdpi.jpg