Skip to content

Instantly share code, notes, and snippets.

View rsimoes's full-sized avatar

Richard Simões rsimoes

  • Center for Technology and Civic Life
  • Austin, Texas
View GitHub Profile
@rsimoes
rsimoes / net-gnutls-high-level.pl
Created February 20, 2012 17:31
Net::GnuTLS high-level bindings
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 / linearly-typed.pl
Created February 22, 2012 14:48
Long-winded linearly typed variables
#!/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 / lazy_io_var.pl
Created March 10, 2012 05:49
Proof of concept: Lazy IO variable with AnyEvent, Variable::Magic, Data::Alias, and PadWalker
#!/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 / set-builder_synopsis.pl
Created July 14, 2012 01:52
Set::Builder synopsis
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 } };
package Foo;
use Moo::Role;
use MooX::ClassAttribute;
class_has 'foo' => (
is => 'ro',
isa => sub { $_[0] == 1 or die 'not 1' }
);
package My::Types;
use strict;
use warnings;
use Type::Utils;
use Type::Library -base,
-declare => 'Percentage';
use Types::Standard qw(Num);
use Math::BigFloat;