Skip to content

Instantly share code, notes, and snippets.

@xsawyerx
xsawyerx / recur_def_promise.pl
Last active December 14, 2015 21:39
Recursive deferred promises: sometimes you need to run a set of actions consecutively without knowing how many actions exist. An example would be running an arbitrary number of commands one after the other. You want to be able to add more commands to the array without having to add another explicit deferred promise. This code shows how to recurs…
use strict;
use warnings;
use AnyEvent;
use AnyEvent::HTTP;
use Promises 'deferred';
my @urls = ( 'https://ddg.gg', 'http://dyndns.org', 'http://metacpan.org' );
my $cv = AE::cv;
my $cb; $cb = sub {
@xsawyerx
xsawyerx / async_response.pl
Created October 31, 2012 14:31
using send_file for full non-blocking async fork w/ condvars
# this function lets you run code in a fork
# and use a condvar on it to get the data
# and return it to the client in JSON form, all non-blocking and async
# based heavily on a trick by Assaf Gordon
sub async_response (&) {
my $cb = shift;
send_file(
\'noop',
@xsawyerx
xsawyerx / datetime.pl
Created July 13, 2012 20:38
Finding Friday the 13th
use strict;
use warnings;
use DateTime;
my $dt = DateTime->new(
day => 13,
year => 2012,
);
my $count = 0;
@xsawyerx
xsawyerx / dancer1-design.txt
Created June 28, 2012 22:51
Dancer design graphs
.---------.
.----------.----------| Handler |--------.--------.
| | | '---------' | |
| | | | | |
| | | | | |
v v v '-> v v
.-----. .-----. .-----. .------------. .------. .-------.
| App | | App | | App | | Serializer | | Hook | | Route |
'-----' '-----' '-----' '------------' '------' '-------'
@xsawyerx
xsawyerx / author-pauseid.pl
Created August 2, 2011 05:42
MetaCPAN::API example
use MetaCPAN::API;
my $mcpan = MetaCPAN::API->new();
my $author = $mcpan->author( pauseid => 'XSAWYERX' );
package MusicPref;
use Moose;
use namespace::autoclean;
has 'name' => ( is => 'ro', isa => 'Str' );
package Character;
use Moose;
use namespace::autoclean;
has 'name' => ( is => 'ro', isa => 'Str' );
has 'music_prefs' => ( is => 'rw', does => 'KiokuDB::Set' );