Skip to content

Instantly share code, notes, and snippets.

@sugar84
sugar84 / gist:1099157
Created July 22, 2011 09:28
check 256 colors in console
curl -L http://www.frexx.de/xterm-256-notes/data/256colors2.pl | perl
@sugar84
sugar84 / perl
Created August 11, 2011 11:08
strange
#!/usr/bin/env perl
use strict;
use warnings;
my $struct = {
bb => [qw(gg hh jj)],
};
if (@{$struct->{bb1}}) {print "works"}
for (@{$struct->{bb1}}) {print}
@sugar84
sugar84 / gist:1149473
Created August 16, 2011 16:24
mojo cookie bug or not?
use Mojolicious::Lite;
any '/' => sub {
my $self = shift;
my $name = $self->param("name");
#cookie with value
$self->cookie(baz => 'bar');
@sugar84
sugar84 / gist:1151648
Created August 17, 2011 14:42
params to hash vs params to hash_ref
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw/cmpthese/;
sub hash {
my $self = shift;
my %params = @_;
return;
@sugar84
sugar84 / gist:1198879
Created September 6, 2011 20:38
AnyEvent tail
#!/usr/bin/env perl
use AnyEvent;
if (open my $fh, "|-", "tailf -n 10 ./file") {
1;
} else {
my $cv = AnyEvent->condvar;
my $body;
my $handle; $handle = AnyEvent::Handle->new(
@sugar84
sugar84 / gist:1230440
Created September 20, 2011 21:30
mojox_run hangs
#!/usr/bin/env perl
use common::sense;
use Data::Dumper;
use MojoX::Run;
use Mojolicious;
say $Mojolicious::VERSION;
my $sub = sub {
return "hello", "world";
@sugar84
sugar84 / gist:1234591
Created September 22, 2011 11:41
mojox_run error?
my $count = scalar keys %$all;
my (@shas, $i);
for my $disk (keys %$all) {
my $part = $all->{$disk}->{partition};
my $pid = $run->spawn(
cmd => sub {
# my @shas =
# map {/^([0-9a-f]+)/}
# qx(find $dest/$part -type f | grep -Fv "lost+found" | sort | xargs shasum)
# ;
@sugar84
sugar84 / gist:1234627
Created September 22, 2011 12:06
separate script
#!/usr/bin/env perl
use common::sense;
use lib qw(./lib);
use MojoX::Run;
use Data::Dumper;
my $run = MojoX::Run->new;
my $all = { sda => 11, sdb => 22, sdc => 11, sdd => 22, sde => 11, sdf => 22, sdg => 33 };
[sugar@comp mojoxrun]$ PERL5LIB="lib" prove
t/00-load.t ................. 1/1 # Testing MojoX::Run 0.15, Perl 5.012004, /usr/bin/perl5.12.4
t/00-load.t ................. ok
t/boilerplate.t ............. ok
t/manifest.t ................ skipped: Author tests not required for installation
t/mojox-run-complexsub.t .... [Wed Oct 5 00:17:45 2011] [debug] Not installig any signal handler, because IOWatcher implementation Mojo::IOWatcher::EV implements better CHLD signal handling.
t/mojox-run-complexsub.t .... 1/5 Write failed: Can't call method "_connecting" on an undefined value at /usr/local/share/perl/5.12/Mojo/IOLoop/Client.pm line 129.
t/mojox-run-complexsub.t .... 2/5 Write failed: Can't call method "_connecting" on an undefined value at /usr/local/share/perl/5.12/Mojo/IOLoop/Client.pm line 129.
t/mojox-run-complexsub.t .... ok
t/mojox-run-long-running.t .. [Wed Oct 5 00:17:46 2011] [debug] Not installig any signal handler, because IOWatcher implementation Mojo::IOWatcher::EV implements better CHLD
@sugar84
sugar84 / gist:1264816
Created October 5, 2011 16:00
upload bug?
#!/usr/bin/env perl
use Mojolicious::Lite;
# create file for testing
my $file = "yet_another_file";
qx(touch $file; echo "hello" > $file);
any '/' => sub {
my $self = shift;