This Week I Learned - 2017 Week 49

Last week post or something from the archive.

A few weeks ahead and we will reach the end of the year 2017 and embrace 2018. Slow week, lots of travelling and nothing much done. Interesting conversation with quite a few breeders.

Da Hu Fa is another good animation coming from China this year since the release of Big Fish & Begonia in 2016, preceded by Monkey King Hero Is Back in 2015. The Chinese animation industry comes a long way since the early days of Havoc in Heaven. It's still growing but still heavily influenced by Japanese anime in some ways and lack of the maturity and unique styles.



Interesting discussion on JavaScript itself with other developers. For RESTful API, use Koa.js (the development guide have some documentation), the next generation web framework for Node.js and the successor for Express.js.

Someone introduced me to Flow-based programming (FDP) and if you're using JavaScript, there is NoFlo. If you're from UNIX background, think FDP as pipeline or pipe and filter. Worth exploring and use it in your project? Well it depends, pretty much on the context or the type of system.



Looping and concatenating multiple arrays in Perl

Saw this code while searching through something and it caught my attention. Interesting way to concatenate arrays.
use strict;
use warnings;
use Data::Dumper;

my $a = [1,2];
my $b = [3,4];

my $c = [];
push @$c, @$_ for $a, $b;

print Dumper($c);

$perl main.pl
$VAR1 = [
          1,
          2,
          3,
          4
       ];

Alternatively, you can write it as this way where we concatenate both arrays.
use strict;
use warnings;
use Data::Dumper;

my $a = [1,2];
my $b = [3,4];

my $c = [];
push @$c, $_ for (@$a, @$b);

print Dumper($c);

$perl test1.pl
$VAR1 = [
          1,
          2,
          3,
          4
       ];

However, if we have any duplicated item in both $a or $b, it will be merged as well.
use strict;
use warnings;
use Data::Dumper;

my $a = [1,2];
my $b = [1,2,3,4];

my $c = [];
push @$c, $_ for (@$a, @$b);

print Dumper($c);

$perl test2.pl
$VAR1 = [
          1,
          2,
          1,
          2, 
          3,
          4
       ];

To resolve this, we need to remove the duplicate items in the combined array by using
List::MoreUtils.
use strict;
use warnings;
use Data::Dumper;
use List::MoreUtils qw(uniq);

my $a = [1,2];
my $b = [1,2,3,4];

my $c = [];
push @$c, $_ for uniq(@$a, @$b);

print Dumper($c);

$ perl test3.pl
$VAR1 = [
          1,
          2,
          3,
          4
        ];