CY's Recent Submission for PWC(061-063)

This is a part of Perl Weekly Challenge(PWC) and the followings are related to my solution. If you want to challenge yourself on Perl, go to https://perlweeklychallenge.org, code the latest challenges, submit codes on-time (by GitHub or email)(before Monday GMT+0 00:00) if possible, before reading my blog post.

Miss out blogging for a while. Here just write some lines on the recent PWC coding experience.

Challenge 061

ch-1 :

Enumeration

ch-2 :

Before coding, I had thought it was a complicated task for regular expression. It turned out smoother.

I use a subroutine possible_octet to check whether a number can be a part of IPv4 octet.

Its content:

sub possible_octet {
    my $item = $_[0];
    if ($item =~ /^[0-9]$/ or $item =~ /^[1-9][0-9]$/ ) {
        return 1; }
    elsif ($item =~ /^[1-9][0-9][0-9]$/) {
        return  ( $item <= 255) ;
    }
    else {
        return 0;
    }
}

BLOG: The Weekly Challenge #063

https://perlweeklychallenge.org/blog/weekly-challenge-063

Perl Weekly Challenge 63: Last Word and Rotate String

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (June 7, 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: Last Word Matching a Regex

Define sub last_word($string, $regexp) that returns the last word matching $regexp found in the given string, or undef if the string does not contain a word matching $regexp.

For this challenge, a “word” is defined as any character sequence consisting of non-whitespace characters (\S) only. That means punctuation and other symbols are part of the word.

The $regexp is a regular expression. Take care that the regexp can only match individual words! See the Examples for one way this can break if you are not careful.

Examples:

Stack Overfow Developer Survey 2020

There's a lot in it and we could question some of the methodology, but here's some thoughts.

EZFPPD-WoAAv2Dq.jpeg

Perl developers are older (and there aren't that many of them) but salaries are excellent.

I would note that TIOBE didn't match up too closely with common usage but there's no silver lining.

Ruby is now in consistent decline, I have read people linking this to Twitter moving away from Ruby on Rails but can't cite that claim. My observation is that RoR seems to have gone out of fashion in favor of lightweight server frameworks and I would suggest that Kubernetes has sidelined Puppet, so organizations aren't bringing in Ruby via apps/frameworks they want to use.

New Arel like SQL Manager

Some months ago I started working in a system similar to ActiveRecord. But then it became pretty big so then I centered my attention in a SQL AST manager instead.

So I made a library that is basically an Arel port. You can see the README with most of the basic info. After looking at implementations in CPAN I realized there are many of them already but all of them based on hash structures.

This impl can instead represent a full SQL AST mainly using builder chainable methods.

I need some feedback on wether you think it will be something that is useful.

Thanks in advance.

Repo link: https://bitbucket.org/juankpro/perl-sql/src/master/

PD: Here is another question. If you try to download and use the lib right now it will not work because it depends on another library made by me as well: https://bitbucket.org/juankpro/model-support/admin

This library is a group of packages with somewhat unrelated utility functions that allows me to support my own perl OOP engine implementation shared through other libraries I'm working on. I don't know what's the best approach to handle this. Is it ok to upload this library separately? if I need to reuse this code again, how do I prevent collisions if my other libs will use it as well?

Monthly Report - May

I have been doing Monthly Report since June 2018 non-stop. It has become a ritual for me now. It gives me an opportunity to look upon my activities. Since the beginning of the year 2020, I have made conscious decision to slow down as far as submitting Pull Request. I have also stopped playing CPAN game of daily upload after breaking the chain three times. I am happy that Perlancar is keeping the game alive. It has given me space to try something new. Although COVID-19 keeping us indoor all the time, still looking for interesting project to keep the mind busy.

Perl Weekly Challenge 62: Sort Email Addresses

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

Task 1: Sort Email Addresses

Write a script that takes a list of email addresses (one per line) and sorts them first by the domain part of the email address, and then by the part to the left of the @ (known as the mailbox).

Note that the domain is case-insensitive, while the mailbox part is case sensitive. (Some email providers choose to ignore case, but that’s another matter entirely.)

If your script is invoked with arguments, it should treat them as file names and read them in order, otherwise your script should read email addresses from standard input.

Bonus

Add a -u option which only includes unique email addresses in the output, just like sort -u.

Example:

If given the following list:

Prima: release v1.59 adds major text rendering functionality

  1. Previously it was only possible to output text with strings using text_out() method. Now, a more versatile and modern way is added with text_shape() method that converts text string in a series of glyphs, that allows the following:

    • Full unicode bidi processing
    • Support for font ligatures
    • Native support for right-to-left text
    • Transparent font substituion where a single font does not contain necessary glyphs

    In addition to that, infrastructure was added to support RTL and shaping in all standard Prima widgets. Run podview Prima::Drawable::Glyphs and check out the examples in the end of the document.

  2. PostScript backend rewritten to generate embedded Type1 fonts. This allows to generate unicode text in PostScript documents.

  3. In X11 backend, standard key combination (Ctrl+Shift+U) accepts unicode hex number as a character input. Try typing "a" then Ctrl+Shift+U 300 ENTER.

  4. Prima::*Dialog packages are moved to Prima::Dialog::* namespace

glyphs.png

Dancer2 0.300004 Released

The Dancer Core Team would like to announce the availability of Dancer2 0.300004. This release brings several important fixes and enhancements:

  • Session cookies can be restricted to a first-party or same-site context

  • There were a number of spots where Dancer2 would return a 500 error upon receiving an invalid request, rather than (correctly) returning 400 - Bad Request. Many, if not all, of these have been fixed.

For more information about same-site context, please refer to [RFC-6265bis]( https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site).

To use this, add the cookie_same_site key to your session engine configuration in the appropriate YAML file. Valid settings include Strict, Lax, and None.

The complete changelog is as follows: 0.300004 2020-05-26 20:52:34-04:00 America/New_York

Late May Software Releases

There have been several! LANraragi, ZEVENET CE, LedgerSMB, and Sympa. All great perl software!

LANraragi v.0.7.0 -- Cat People (Putting Out Fire)

Web application for archival and reading of manga/doujinshi. Lightweight and Docker-ready for NAS/servers.

This release includes an API revamp, categories have finally been added, PDF files are now first class citizens, Docker image is much smaller, and many other fixes and small features.

Check it out here: https://github.com/Difegue/LANraragi/releases/tag/v.0.7.0


ZEVENET Community Edition v5.11.1

The community edition of this load balancer appliance is bugfixes.

Check it out at: https://github.com/zevenet/zlb/releases/tag/v5.11.1


LedgerSMB 1.7.14

This accounting software's release is composed primarily of bugfixes.

Check it out at: https://github.com/ledgersmb/LedgerSMB/releases/tag/1.7.14

Sympa 6.2.56

This release is a all bugfixes for this mailing list management software

Check it out at: https://github.com/sympa-community/sympa/blob/6.2.56/NEWS.md

Perl Weekly Challenge 061: Product SubArray And IPv4 Partition

Product SubArray

Given a list of 4 or more numbers, write a script to find the contiguous sublist that has the maximum product. The length of the sublist is irrelevant; your job is to maximize the product.

Example

Input: [ 2, 5, -1, 3 ]

Output: [ 2, 5 ] which gives maximum product 10.

The easiest (but probably not the fastest) method would be to start from each position and compute the products of all the possible sublists starting at the position, remembering the positions where the product is maximal.

I automatically reached for List::Util’s product to get the products easily, but alas! Running

product(-1, 3)

caused a Floating point exception (bug reported). So, I had to implement product myself:

Vikna: pre-release of a text console UI framework for Raku

After almost half a year of work I finally publish my new project Vikna which is also the subject of my talk at the upcoming Conference in the Cloud.

As the subject says, it is a clear pre-release and a proof of concept for the preview of those who might be interested. In the project I tried to get hold of all the best what Raku can offer in the field of asynchronous/threaded processing and OO. Whish you can as much fun trying it as I have in developing!

PWC 060: Task #1, Excel Column & Task #2, Find Numbers

PWC Task #1, Excel Column

jaredor submission for Task #1

Convert back and forth between base 10 and base 26, no problem.

"Column A" equals 1? Problem.

Okay, as problems go, that is a small one. Let I, an old Fortran programmer who loves perl, be your guide between offset indexing and ordinal indexing. First of all, we should complete our assessment of the lay of the land:

"Column 1" equals 1? Problem.

Yes, both column numbering systems start at "one", not "zero", but the mechanical conversion between number bases requires modular arithmetic, which is very much related to offset (0-based) indexing.

Note the quotes? They are meant to emphasize the concept of "one-ness" and "zero-ness" so that I don't have to deal with lexicographic tautologists telling me that "A is A, 1 is 1." Work with me here: The core of difficulty in this task is that we are translating between two number systems that don't have a zero and zero is a big thing.

CY's Post on PWC#060: Numbers with Headache

This is a part of Perl Weekly Challenge(PWC) #060 and the followings are related to my solution. If you want to challenge yourself on Perl, go to https://perlweeklychallenge.org, code the latest challenges, submit codes on-time (by GitHub or email) if possible, before reading my blog post

Do tell me if I am wrong or you strongly oppose my statements!

Task #1: Excel Column

Firstly we observe that 16384 < 263 = 17576 . Therefore there are at most 3 alphabets for the spreedsheet nomenclature. Knowing the cases to handle are not massive, I handle the cases with some subroutines named AtoOne, AtoZero and OnetoA.

The in-production testing line is for (1..3000) {print (numtoExcelCol($_),"\n"} and the finalized testing line is     for (1..$MAX) {print($_,"\n") unless $_ == excelcoltoNum(numtoExcelCol($_));} .


Task #2 Find Numbers

The original task makes me feel it is an exercise for using the module Math::Combinatorics .

Afterall, hence I modify the following more mathematically interesting task for myself:

Paging for Fun and Profit

Paging PAWS for fun an profit


Egad have been away for a while, it is not due to laziness on my part, I really have been stuck on a Paws problem over the past month+, add to that dozens of inside and out sided projects that I need to get done around the house time has just not been there. At least I have finally cracked it.

I really went down a rabbit hole for this one and spend way too many hours trying to figure out how to test 'Paws Pagination' end to end.

In my last post I started out with a new test suite '30_pagination.t' and a few test YAMLs. Just getting the YAML just right to God only knows how many iterations. I also had to create a completely new caller 'TestPaginationCaller.pm' to get the tests to work.

Perl Weekly Challenge 060: Excel Column And Find Numbers

Excel Column

Write a script that accepts a number and returns the Excel Column Name it represents and vice-versa.

Excel columns start at A and increase lexicographically using the 26 letters of the English alphabet, A..Z. After Z, the columns pick up an extra “digit”, going from AA, AB, etc., which could (in theory) continue to an arbitrary number of digits. In practice, Excel sheets are limited to 16,384 columns.

Example

Input Number: 28
Output: AB

Input Column Name: AD
Output: 30

This seemed like a simple base 10 to base 26 conversion and back. I started by installing Math::Base::Convert, Math::BaseConvert, Math::BaseCnv, and Convert::AnyBase to quickly discover they wouldn’t help me much. What Excel uses for column names is a weird 26 digit system that lacks a symbol for zero, but has a symbol for 26 (or for 1026). It’s called the bijective base-26 numeration system. The interesting fact about such systems is that digit addition, subtraction, and multiplication work the same way as in our common system (division is a bit problematic).

PWC 059: Task #1, Linked List & Task #2, Bit Sum

PWC Task #1, Linked List

jaredor submission for Task #1

Partitioning an input array into a @lower and @upper array based on a pivot element, $k, and then recombining into an output array (@lower, @upper) is pretty easy, e.g.,

say join(' ', (grep { $_ < $k } @ARGV), (grep { $k <= $_ } @ARGV));

A linked list can be collapsed into an array easily enough, so the challenge here (for me) is to add a little extra in the handling that could be useful in the future (because I always steal from myself ;-)

So maybe the little extra is this: Once a link is made it won't be copied.

I started explaining everything and it started feeling like I was writing a very boring novel. Below I'll just stick to the link logic.

Details

Input

There is one command line option:

--k
Specify the pivot point, k, per the problem instructions. [REQUIRED]

The arguments are the elements of the chain, in order, from HEAD to TAIL, since I like to make things as easy for myself as possible.

Link Logic

Coders In Cars Getting Chatty

The last time I spoke at Craft Conference, I also took part in what is probably the most fun and unusual interview of my career: Ivette Ördög’s Morning Commute.

Bear in mind, however, that this discussion took place back in 2018, so you’ll need to mentally s/Perl 6/Raku/ in a couple of places.

Even if you’re not interested in my random thoughts on the importance of linguistic diversity, Ivette’s other interviews are well worth watching.

Perlmongers Conferences in the Time of Corona

I’m collecting different setups here. Other efforts are underway to organize a virtual conference. The setups listed below aim for smaller audiences with hopefully lower effort in setting things up.

I don’t discuss the other stuff needed for organizing a conference, like the social aspects (”hallway track”, “moderation”, “timekeeping”) or how people can forward questions from the chat to the speaker. The logistic aspects are mostly that outside of the “producer”, ideally nobody needs to install software beyond Chromium or another browser compatible enough with Jitsi to do video streaming.

Docker::Names::Random

If you are using Docker, you may have noticed that it creates random names for containers when you haven't provided any specific name. These names are a combination of an adjective and a proper name of an individual. The individuals are famous men and women picked from the history of scientific exploration and engineering.

This package allows you to use the same system in your own programs. You would get combinations like interesting_mendeleev, epic_engelbart, lucid_dhawan, recursing_cori, ecstatic_liskov and busy_ardinghelli.

The combination boring_wozniak is not allowed because Steve Wozniak is not boring. This same limitation exists in the original code.

SYNOPSIS

About blogs.perl.org

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