Skip to content

Instantly share code, notes, and snippets.

Richard Simões rsimoes

  • Center for Technology and Civic Life
  • Austin, Texas
Block or report user

Report or block rsimoes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View types-type_math-bigfloat.pl
package My::Types;
use strict;
use warnings;
use Type::Utils;
use Type::Library -base,
-declare => 'Percentage';
use Types::Standard qw(Num);
use Math::BigFloat;
View moox-classattribute-inheritance.pl
package Foo;
use Moo::Role;
use MooX::ClassAttribute;
class_has 'foo' => (
is => 'ro',
isa => sub { $_[0] == 1 or die 'not 1' }
);
View set-builder_synopsis.pl
use Set::Builder qw(Set Var for_all);
# set constructor, roster style:
my $set = Set { 0..9 };
# element variable constructor:
my ($x, $y) = (Var) x 2;
# subset consisting of the numbers 0 and 1
my $subset1 = Set { $x ~~ $set | $x ~~ Set { 0..1 } };
@rsimoes
rsimoes / lazy_io_var.pl
Created Mar 10, 2012
Proof of concept: Lazy IO variable with AnyEvent, Variable::Magic, Data::Alias, and PadWalker
View lazy_io_var.pl
#!/usr/bin/env perl
use v5.14;
use warnings;
use AnyEvent::HTTP "http_get";
use Variable::Magic qw(wizard cast dispell);
use Data::Alias "alias";
use PadWalker "peek_my";
sub get_page {
@rsimoes
rsimoes / linearly-typed.pl
Created Feb 22, 2012
Long-winded linearly typed variables
View linearly-typed.pl
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dump;
use Data::Alias "alias";
use Scalar::Util qw(weaken isweak);
my $foo = ["a".."z"];
alias my @bar = @$foo;
@rsimoes
rsimoes / net-gnutls-high-level.pl
Created Feb 20, 2012
Net::GnuTLS high-level bindings
View net-gnutls-high-level.pl
use IO::Socket::IP;
use Socket qw(SOCK_STREAM)
use Net::GnuTLS::Client;
use Net::GnuTLS::Credentials;
# Connect to server:
my $socket = IO::Socket::IP->new(
PeerHost => "metacpan.org",
PeerPort => "https",
@rsimoes
rsimoes / net-gnutls-low-level.pl
Created Feb 20, 2012
Net::GnuTLS low-level bindings
View net-gnutls-low-level.pl
use Socket qw(getaddrinfo SHUT_RDWR SOCK_STREAM);
use Net::GnuTLS qw(GNUTLS_CLIENT GNUTLS_CRD_CERTIFICATE GNUTLS_SHUT_RDWR
GNUTLS_X509_FMT_PEM);
my %hints = ( socktype => SOCK_STREAM );
my ( $err, $addr_info ) = getaddrinfo( "metaperl.org", "echo", \%hints );
socket( my $SKT, @{$addr_info}{qw(family type protocol)} ) || die "socket: $!";
connect( $SKT, $addr_info->{addr} ) || die "connect: $!";
my $creds = Net::GnuTLS::Certificate::allocate_credentials();
@rsimoes
rsimoes / xml_parse_bench.pl
Created Feb 18, 2012
XML parsing benchmarks
View xml_parse_bench.pl
use v5.14;
use strict;
use warnings;
use utf8::all;
use Data::Dump;
use LWP::Simple qw(get);
use Benchmark qw(cmpthese timethese);
use XML::LibXML;
use XML::Parser;
use XML::SAX::PurePerl;
@rsimoes
rsimoes / moose_defaults.pod
Created Jan 2, 2012
Moose defaults vs builders
View moose_defaults.pod

Defaults allow subclassing

If we subclass our Person class, we can override the size attribute's default:

package Lilliputian;
 
use Moose;
extends 'Person';
 
has +size => ( default => "small" );
@rsimoes
rsimoes / concapl.pl
Created Dec 30, 2011
Concatenative, stack-oriented Perl DSL
View concapl.pl
"What is 2 + 3?" . say . readline
. { 2 . 3 . add . eqn }
. { "Correct!" . say } . { "Incorrect" . say }
. ifte
You can’t perform that action at this time.