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 / example-zydeco.pl
Last active September 14, 2020 22:40
Example from the Zydeco pod
use v5.14;
use strict;
use warnings;
package MyApp {
use Zydeco;
class Person {
has name ( type => Str, required => true );
has gender ( type => Str );
@tobyink
tobyink / blog-get.pl
Created September 11, 2020 10:46
Web scraper using Zydeco
#!/usr/bin/env perl
use v5.14;
package Local::App {
use Zydeco;
# Utility function.
#
require HTML::Entities;
@tobyink
tobyink / simple-to-json-method.pl
Created August 25, 2020 19:45
A simple TO_JSON method
sub TO_JSON {
my $self = shift;
return { %$self };
}
@tobyink
tobyink / marshalling-3.pl
Created August 25, 2020 19:30
More complex example of marshalling and unmarshalling using Zydeco
use v5.16;
use strict;
use warnings;
use JSON::MaybeXS;
use Data::Dumper;
package MyApp {
use Zydeco;
use Carp 'confess';
@tobyink
tobyink / marshalling-2.pl
Last active August 25, 2020 19:29
Example of marshalling with Zydeco using coercion to unmarshall the data
use v5.16;
use strict;
use warnings;
use JSON::MaybeXS;
use Data::Dumper;
package MyApp {
use Zydeco;
use Carp 'confess';
@tobyink
tobyink / marshalling-1.pl
Last active August 25, 2020 19:29
Example of marshalling with Zydeco where unmarshalling fails
use v5.16;
use strict;
use warnings;
use JSON::MaybeXS;
use Data::Dumper;
package MyApp {
use Zydeco;
use Carp 'confess';
@tobyink
tobyink / mom-eg2.pl
Created August 11, 2020 18:06
Mom.pm usage, example 2
use strict;
use warnings;
package Widget {
use Mom q{
name :ro :type(Str) :required
stock_level :rwp :type(Int) :default(0)
sku :ro :type(Str) :required
};
@tobyink
tobyink / mom-eg1.pl
Created August 11, 2020 18:05
Mom.pm usage, example 1
use strict;
use warnings;
package Widget {
use Mom q{ name stock_level sku };
}
my $thingy = Widget->new(
name => 'Whatsit',
sku => 'X0000001',
@tobyink
tobyink / puzzle1.pl
Last active June 16, 2020 12:49
Solution to a number puzzle in Perl
#!/usr/bin/env perl
use v5.12;
use strict;
use warnings;
use Algorithm::Permute;
sub main {
my $check = build_checker( \*DATA );
@tobyink
tobyink / functions.php
Last active June 9, 2020 13:11
Wordpress edit hotkey
<?php
# These snippets can be added to your existing functions.php.
#
# 1. This outputs <link rel="edit-form"> in your page <head> elements.
#
add_action( 'wp_head', function () {
global $post;
if ( $post && current_user_can( 'edit_post', $post->ID ) ) {