Skip to content

Instantly share code, notes, and snippets.

@kevincolyer
kevincolyer / gist:5452267
Created April 24, 2013 13:51
Template::Toolkit content for Perlanet RSS aggregator. Uses HTML::Scrubber plugin for TT to defang and normalise the typography of the feeds that it aggregates.
<div class="span-17 colborder" id="content" >
[% USE Filter.HTMLScrubber %]
[% FOREACH entry IN feed.entries %]
<h2 class="loud alt"><a href="[% entry.link | url | html %]">[% entry.title | html %]</h2></a>
<div class="alt">
[% entry.content.body
| html_scrubber(['-span','+p','+h3','+h4','+ol','+ul','+li','+strong','+em','-style','-script', '-iframe'])
| remove('style=".*?"' )
| remove('class=".*?"' )
@kevincolyer
kevincolyer / gist:7aad41a836beb1eb75cd
Last active May 6, 2019 15:51
Perl6 object cloning test
#!/usr/bin/env perl6
use v6;
class obj {
has $.attr is rw = 42;
has @.shallow = 1,2,3;
has @.deep = [1,2,3],[4,5,6];
}
@kevincolyer
kevincolyer / week9.pl
Created May 24, 2019 12:30
Perl Weekly challenge - week 9
#!/usr/bin/env perl6
use v6;
say "Part 1 (first square number with 5 distinct digits)";
for (100..10_000) -> $i { my $j=$i**2; "$i -> $j".say && last if $j.comb.unique.elems==5 };
say "\nPart 2 (Rankings)";
# Imagine a running race - times of the runners are:
my @times= 10, 5, 10, 15;
@kevincolyer
kevincolyer / week12.pl
Created June 10, 2019 19:29
Perl Weekly puzzle week 12
#!/usr/bin/perl6
use v6;
use Test;
# 12.1
my @primes = lazy (2,3,*+2 ... ∞).grep: *.is-prime;
# from wikipedia: https://en.wikipedia.org/wiki/Euclid_number
# Write a script that finds the smallest Euclid Number that is not prime
@kevincolyer
kevincolyer / Week13.pl
Created June 17, 2019 12:05
Perl Weekly challenge # 13
#!/usr/bin/perl6
use v6;
use Test;
# Challenge #13.1
# Write a script to print the date of last Friday of every month of a given year. Order y, m, d
my $year=2019;
for 1..12 -> $month {
my $d=Date.new($year,$month,1);
@kevincolyer
kevincolyer / Week14.pl
Created June 24, 2019 21:24
Perl weekly challenge
#!/usr/bin/perl6
use v6;
use Test;
# challenge 14.1
# Write a script to generate Van Eck’s sequence.
my @testEck=0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 5, 0, 2, 6, 5, 4, 0, 5;
is vanEck(17),@testEck,"First 18 items Van Eck's sequence correct";
#!/usr/bin/perl6
use v6;
use Test;
# 15.1 Write a script to generate first 10 strong and weak prime numbers.
#
# For example, the nth prime number is represented by p(n).
#
# p(1) = 1
#!/usr/bin/perl6
use v6;
use Test;
# 15.1 Write a script to generate first 10 strong and weak prime numbers.
#
# For example, the nth prime number is represented by p(n).
#
# p(1) = 1
#!/usr/bin/perl6
use v6;
use Test;
# 15.2
# Write a script to implement Vigenère cipher. The script should be able encode and decode. https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher
#| Encodes or Decodes a text using Vigenère cipher.
multi sub MAIN(Str $text , Str $key, Bool :$encode=True, Bool :$decode=False) {
#!/usr/bin/perl6
use v6;
use Test;
# 16.1
# Pythagoras Pie Puzzle, proposed by Jo Christian Oterhals.
#
# At a party a pie is to be shared by 100 guest. The first guest gets 1% of the pie, the second guest gets 2% of the remaining pie, the third gets 3% of the remaining pie, the fourth gets 4% and so on.
#