Skip to content

Instantly share code, notes, and snippets.

View tobyink's full-sized avatar
🦈
hi

Toby Inkster tobyink

🦈
hi
View GitHub Profile
@tobyink
tobyink / pw-84-matrix.pl
Last active October 31, 2020 19:44
Finding squares in a matrix
use strict;
use warnings;
package Weekly84 {
use Zydeco;
class Matrix {
# public required attribute
has cells! ( type => ArrayRef[ArrayRef[Bool, 1], 1] );
@tobyink
tobyink / frequency-sort.pl
Last active October 14, 2020 17:17
frequency sort
use strict;
use warnings;
use List::MoreUtils qw( frequency part uniq );
my @words = map /([\w']+)/g, <DATA>;
my %freq = frequency @words;
my @parts = part { $freq{$_} } uniq @words;
for my $i ( 0 .. $#parts ) {
next unless $parts[$i];
@tobyink
tobyink / subop.pl
Created October 2, 2020 16:51
Sub::Operable Example
use strict;
use warnings;
use feature 'say';
use List::Util 'shuffle';
use Sub::Operable 'subop';
*greetings = subop {
my @greetings = shuffle(
'Greetings',
'Hello',
@tobyink
tobyink / wp-t-d-auto-eg1.html
Last active September 29, 2020 20:22
WP Tempus Dominus Auto Example 1
<div class="form-group">
<label>Start Date (required)</label>
<input
type="date"
required
class="form-control"
id="startdate"
name="startdate"
data-tempus-dominus-overlay="ddd D MMM YYYY"
data-tempus-dominus-onclick="true"
@tobyink
tobyink / github-visitor.pl
Last active September 29, 2020 12:02
Script to switch off the "issues" feature for all my Perl repos. (Issues for my Perl repos should be reported to rt.cpan.org.)
#!/usr/bin/env perl
use Z;
my $app = app sub {
class 'Visitor' => sub {
constant 'USER' => 'tobyink'; # Your username!
constant 'TOKEN' => 'XXXXXXX'; # https://github.com/settings/tokens
has 'code' => ( type => CodeRef, required => true );
has 'repos' => ( is => 'lazy', init_arg => undef );
@tobyink
tobyink / linked-lists.pl
Last active September 25, 2020 21:22
Linked lists, Zydeco example
package SLL {
use Zydeco;
class Node {
has value ( type => Int );
has nextnode ( type => Maybe[Object] );
method printvalue () {
print $self->value, " ";
}
@tobyink
tobyink / moon-sizes.pl
Created September 20, 2020 13:23
Angular sizes of moons and planets seen from other bodies
use utf8::all;
use Moo ();
use Z qw( Dumper );
use Math::Trig qw( asin pi );
my $app = app sub {
role 'Body' => sub {
my $CleanNumber = Num->plus_coercions( Str, sub {
@tobyink
tobyink / example-moo.pl
Last active September 14, 2020 22:01
Example from the Zydeco pod, rewritten for Moo plus Type::Tiny
use 5.008008;
use strict;
use warnings;
{
package MyApp;
use parent 'Exporter::Tiny';
our @EXPORT_OK;
@tobyink
tobyink / example-mxp.pl
Last active September 14, 2020 21:12
Example from the Zydeco pod, rewritten for MooX::Press
use 5.008008;
use strict;
use warnings;
use Types::Standard qw( Str );
use MooX::Press (
prefix => 'MyApp',
class => [
'Person' => {
@tobyink
tobyink / example-zylite.pl
Last active September 14, 2020 22:38
Example from the Zydeco pod, rewritten for Zydeco::Lite
use 5.008008;
use strict;
use warnings;
use Zydeco::Lite;
use Types::Standard qw( Str );
app 'MyApp' => sub {
class 'Person' => sub {