Perl Weekly Challenge 70: Character Swapping and Gray Code Sequence

These are some answers to the Week 70 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Task 1: Character Swapping

You are given a string $S of size $N.

You are also given swap count $C and offset $O such that $C >= 1, $O >= 1, $C <= $O and $C + $O <= $N.

Write a script to perform character swapping like below:

$S[ 1 % $N ] <=> $S[ (1 + $O) % $N ]
$S[ 2 % $N ] <=> $S[ (2 + $O) % $N ]
$S[ 3 % $N ] <=> $S[ (3 + $O) % $N ]
...
...
$S[ $C % $N ] <=> $S[ ($C + $O) % $N ]

Example 1:

Speeding Up Perl Test Suites & Test2::Aggregate

I gave a talk at TPC 2019 based on my experiences speeding up the Perl test suite at room/roommate finding service SpareRoom, also serving as an introduction to the - just released at the time - Test2::Aggregate. The talk was a bit too dense, as I had prepared a pretty packed 20 minute presentation, only to realize a couple of days before (newbie speaker) that I had just 15 minutes real time excluding the Q&A. So, some attendees asked me to put up a blog post with the notes etc, and especially more about Test2::Aggregate, which is why I am writing this. I will try to give a longer and more detailed talk about the subject in one of the Perl conferences this summer.

In any case, the talk is up on youtube and gives an overview of the various lessons learned and techniques used while making our frustratingly slow 20 min test suite almost 10x faster, making a huge difference in our dev process:

The slide deck is available here.

Test2::Aggregate

Monthly Report - January

The start of year 2020 didn't go well as planned. First my Dad was hospitalised and I had to make emergency travel plan to visit India. Luckily he is out of danger and back home. During this whole drama, the Perl Weekly Challenge got less of my attention. Thankfully I had loads of support messages throughout. Some offered to chip in so that I can focus on my Dad's health. I even missed my turn of editing Perl Weekly newsletter. It never happened ever since I joined the team of editors. Thanks to the chief edit, Gabor Szabo, I survived.

Another casualty of the January 2020, I missed submitting one Pull Request on everage in the month. I only submitted 22 Pull Requests. I have done this non-stop since October 2017. Sufferings didn't stop there, I couldn't get the monthly report published on the 1st Feb as per the tradition. It got delayed by 2 days.

Perl Weekly Challenge 045: Square Secret Code & Source Dumper

Square Secret Code

The square secret code mechanism first removes any space from the original message. Then it lays down the message in a row of 8 columns. The coded message is then obtained by reading down the columns going left to right.

For example, the message is “The quick brown fox jumps over the lazy dog”. The code message would be as below:

tbjrd hruto eomhg qwpe unsl ifoa covz kxey

Let’s start with the test:

#!/usr/bin/perl
use warnings;
use strict;

use Test::More tests => 1;
is square_secret_code('The quick brown fox jumps over the lazy dog'),
    'tbjrd hruto eomhg qwpe unsl ifoa covz kxey',
    'encode';
        

Perl Weekly Challenge 69: Strobogrammatic Numbers and 0/1 Strings

These are some answers to the Week 69 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a couple of days (July 19, 2020). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

Task 1: Strobogrammatic Numbers

A strobogrammatic number is a number that looks the same when looked at upside down.

You are given two positive numbers $A and $B such that 1 <= $A <= $B <= 10^15.

Write a script to print all strobogrammatic numbers between the given two numbers.

Example

Input: $A = 50, $B = 100
Output: 69, 88, 96

LANraragi v.0.6.8 - Cool Cat

cD0tV_9g.jpeg

LANraragi is a web application for archival and reading of manga/doujinshi. It's lightweight and Docker-ready for NAS/servers. There is even a standing offer from the author to send out a free sticker pack for the first person to run the linux/s390x docker image on a real IBM System 390.

Check out the release details and try out the demo

Making YAML.pm, YAML::Syck and YAML::XS safer by default

Several YAML modules allow loading and dumping objects. When loading untrusted data, this can be a security vulnerability, if this feature is enabled.

You can create any kind of object with YAML. The creation itself is not the critical part, but if the class has a DESTROY method, it will be called once the object is deleted. An example with File::Temp removing files can be found here: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=862373

YAML::Syck had the option to disable this feature via $YAML::Syck::LoadBlessed for a long time. Since 2018, also YAML.pm and YAML::XS have this variable.

See also my blog post from 2018: Safely load untrusted YAML in Perl

In the past, this feature was enabled by default in all three modules.

This will now be disabled by default, to make sure that Perl's YAML libraries are, by default, more secure.

If you are using one of the modules to serialize/load objects, you have to set this variable now:

Perl Weekly Challenge 044: One Hundred, Two Hundred

Only 100, please

You are given a string “123456789”. Write a script that would insert ”+” or ”-” in between digits so that when you evaluate, the result should be 100.

We can populate each place “between digits” with one of three possible values: a plus sign, minus sign, or nothing. To check all the possible permutations, we’ll use an indicator function similarly to The Knapsack Problem. In this case, though, there are three possible values, so we need to loop over numbers in the ternary numeral system.

The only operation we’ll need will be the increment, so we don’t need the full support for arithmetic in base 3. We can implement the increment ourselves: we start from the right of the number, change any 2 into 0 and move left. Once we find 0 or 1, we increment it and we’re done.

To create the expression, we just need to intersperse the digits with the operators. See the apply subroutine below.

# Perl Weekly Challenge 68: Zero Matrix

These are some answers to the Week 68 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Task 1: Zero Matrix

You are given a matrix of size M x N having only 0s and 1s.

Write a script to set the entire row and column to 0 if an element is 0.

Example 1:

Input: [1, 0, 1]
       [1, 1, 1]
       [1, 1, 1]

Output: [0, 0, 0]
        [1, 0, 1]
        [1, 0, 1]

Example 2:

Announcing MooX::Pression

Kind of like Moops but with less hacky parsing.

GPW2020 - Keynote, accepted talks and extension of the submission deadline

We are really happy to announce that Curtis “Ovid” Poe will present a keynote at the 22nd Perl/Raku workshop in March in Erlangen!

Curtis runs Tau Station and is a long time contributor to the workshop.

The list of accepted talks has grown, with varied topics from “Progressing from Humans to Developers”, “A new Lisp, in Perl” and “Querying the Etherum Blockchain Nodes with Raku”. All accepted talks are listed here .

Since we still have some slots free for talks, we have extended the deadline for talk submission to the 3rd February 2020. If you have a topic you want to present, please submit your talk .

We’d also like to thank our sponsors for supporting the Perl and Raku community

Friedrich-Alexander-Universität - https://www.fau.de

United Domains - https://united-domains.de

Perl-Services.de - Renée Bäcker - https://perl-services.de

genua GmbH - https://genua.de

dpunkt.verlag - https://www.dpunkt.de

Paws L (A little party planned)

Well it looks like a wrap for PAWS XML as the last thing I am working on is getting the test suite to pass

Looking at S3 I have only 1 error with the 09_requestst.t test suite;
ok 829 - Call S3->SelectObjectContent from t/09_requests/s3-select-object-content.request
not ok 830 - Got content eq from request
#   Failed test 'Got content eq from request'
#   at t/09_requests.t line 123.
#          got: '<SelectObjectContentRequest xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><InputSerialization><CompressionType>NONE</CompressionType></InputSerialization><OutputSerialization><CSV><FieldDelimiter>\,</FieldDelimiter><QuoteCharacter>\'</QuoteCharacter><QuoteEscapeCharacter>\"</QuoteEscapeCharacter><QuoteFields>ASNEEDED</QuoteFields><RecordDelimiter>\\n</RecordDelimiter></CSV></OutputSerialization><Expression>MyExpression</Expression><ExpressionType>SQL</ExpressionType></SelectObjectContentRequest>'
#     expected: '<InputSerialization><CompressionType>NONE</CompressionType></InputSerialization><OutputSerialization><CSV><FieldDelimiter>\,</FieldDelimiter><QuoteCharacter>\'</QuoteCharacter><QuoteEscapeCharacter>\"</QuoteEscapeCharacter><QuoteFields>ASNEEDED</QuoteFields><RecordDelimiter>\\n</RecordDelimiter></CSV></OutputSerialization>' 

I rechecked the API and my real world test and found the action 'SelectObjectContent
' it is a one off case in S3 that requires the root tag and the 'xmlns' to be present;

So a simple fix to the test got that.

Perl Weekly Challenge 67: Number Combinations and Letter Phone

These are some answers to the Week 67 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a couple of days (July 5, 2020). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

Task 1: Number Combinations

You are given two integers $m and $n. Write a script print all possible combinations of $n numbers from the list 1 2 3 … $m.

Every combination should be sorted i.e. [2,3] is valid combination but [3,2] is not.

Example:

Input: $m = 5, $n = 2

Output: [ [1,2], [1,3], [1,4], [1,5], [2,3], [2,4], [2,5], [3,4], [3,5], [4,5] ]

Note that I don’t consider the formatting of the displayed output above to be part of the task.

Number Combinations in Raku

k-means: a brief interlude into Data Wrangling

When last we saw our heroes, what they thought was the brink of success turned out to be the precipice of hasty interpretation and now they are dangling for dear life on the branch of normalization! how's that for tortured metaphor!

If you use raw values for your k-means clustering, dimensions with large values or large ranges can swamp smaller dimensions and skew your clusters. The process of normalization tries to bring everything into the same range, usually [0,1], although your choices on how to transform the ranges are also significant. There is not always one best way to do it and, as usual, get familiar with your dataset and use your judgement.

Springtime in Switzerland

For over a decade now, I've been running public training classes in both presentation skills
and software development in conjunction with the Swiss Institute of Bioinformatics,
the University of Lausanne, and the École Polytechnique Fédérale de Lausanne.

This year, in the week of March 9-13, we're offering my full set of Presentation Skills classes as a three-day sequence (though, of course, you can also sign up for just one or two of the classes, if you prefer):

We’re also offering two general software development classes:

These two classes are based on my popular Perl courses on these topics, but I've now
redesigned and adapted them to be entirely language-neutral, so they're equally useful
to developers working in any other mainstream language(s).

Docker, Perl and GitHub

Why using Docker images?

There are many reasons to use Docker Images, from setting up a development environment to pushing your code to production. The primary/first reason which pushes me to start using some Docker Images is "Continuous Integration".

When maintaining a Perl package used by multiple users/companies (or not), you absolutely want to know how your code behaves on different versions of Perl. Even if you could have multiple versions of Perl installed on your development environment, most of the time, the development is only performed using a single version of Perl.

Continuous Integration system like Travis CI or GitHub Workflows allows you to run your test suite on every push, pull request... without the need of testing manually on all Perl Versions.

When testing your code on a container (or Virtual Machine) you do not want to install or compile a fresh version of Perl each time... This is a slow operation, that ideally, should be done once.

Perl Weekly Challenge 65: Digit Sum

These are some answers to the Week 65 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

You are given two positive numbers $N and $S.

Write a script to list all positive numbers having exactly $N digits where sum of all digits equals to $S.

Example:

Input:
    $N = 2
    $S = 4

Output:
    13, 22, 31, 40

Digit Sum in Raku

My first attempt to solve the problem would be a pure brute force approach as follows:

Paws XXXXIX (Very Close)

Finally things were looking my way. I plowed thought the remaining CloudFront actions and got them all to work without any more changes to Paws.

In the end I checked in 30+ new tests cases and over 2k of tests the other day. So I can safely say that 'CloudFront' is fully operational.

That leaves only 'Route53' to look and for me this is somewhat problematic. The Route53 api deals with 'Domains', 'Checks', 'Hosts', 'Traffic' and such. To test 90% of the actions in this API you will need

  1. Have at least one registered DNS domains to start
  2. Know how to create a Hosts for a Domain
  3. Know how to config a Host for a Domain and most importantly
  4. Have some spare cash to pay for all the actions you are mucking with

As I fail on all 4 of the above I am not comfortable with creating working scrips for this API.

Shorewall 5.2.3.5 Released!

Shorewall 5.2.3.5 is now available for download. Shorewall is a gateway/firewall configuration tool for GNU/Linux, written in Perl.

Problems Corrected:

1) A typo in the FTP documentation has been corrected.

2) The recommended mss setting when using IPSec with ipcomp
has been corrected.

3) A number of incorrect links in the manpages have been
corrected.

4) The 'bypass' option is now allowed when specifying an
NFQUEUE policy. Previously, specifying that option resulted
in an error.

5) Corrected IPv6 Address Range parsing.

Previously, such ranges were required to be of the form
[-] rather than the more standard form
[]-[]. In the snat file (and in nat actions),
the latter form was actually flagged as an error while in
other contexts, it resulted in a less obvious error being
raised.

6) The manpages have been updated to refer to https://shorewall.org rather than http://www.shorewall.org.

Call for FOSDEM 2020 Booth volunteers

This year we've got one of the high-traffic locations, on the ground floor where Free Software Foundation Europe set up last year, right next to the stairway to *all* the dev rooms. So we're looking for volunteers to come and talk about both Perl and Raku at FOSDEM 2020 in Brussels. If I haven't already talked to you, please email me at drforr [at] pobox (dot) com and give me an idea of your availability and what you'd want to do. We've made arrangements for the usual booth swag, and will have pamphlets to hand out and books to sell on both Raku and Perl.

Again, if you're able to give us a hand or know someone that can, send me email at drforr [at] pobox (dot) com and give me an idea of when you're available and how much you can help out.

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.