Skip to content

Instantly share code, notes, and snippets.

@Logioniz
Logioniz / next_tick_a.pl
Last active August 29, 2015 14:08
Nice example. Why die?)
#!/usr/bin/perl -wl
# code for answer on question
use Mojo::IOLoop;
sub inc {
my ($num, $cb) = @_;
return Mojo::IOLoop->next_tick(sub {$cb->('error')}) unless $num =~ /^\d+$/;
@Logioniz
Logioniz / ioloop.pl
Last active August 29, 2015 14:08
Nice example to understand ioloop.
my $t = Test::Mojo->new;
sub f2 {
my $cb = shift;
my $d = Mojo::IOLoop->delay(
sub {
warn 'f2_1', $/;
shift->pass;
},
sub {
@Logioniz
Logioniz / ua.bad.pl
Created November 2, 2014 13:39
UserAgent in controller
my $ua = Mojo::UserAgent->new();
my $result;
$self->render_later;
$ua->head( $location => sub {
my ($ua, $tx) = @_;
if ( $tx->res->code eq '200' ) {
$result = 'good';
}
@Logioniz
Logioniz / model.pl
Last active August 29, 2015 14:18
Model class with weaken App.
#!/usr/bin/perl
# Run with command perl 1.pl get /
package AAA;
use Scalar::Util 'weaken';
sub new {
my ($class, $app) = @_;
@Logioniz
Logioniz / ws_es.pl
Last active August 29, 2015 14:18
Websocket vs EventSource. Need open in many tabs of browsers to see "Waiting for available socket" for EventSource.
#!/usr/bin/perl
use strict;
use warnings;
use v5.10;
use Mojolicious::Lite;
use Mojo::IOLoop;
@Logioniz
Logioniz / session.pl
Last active August 29, 2015 14:18
Minimal example login, session
#!/usr/bin/perl
use strict;
use warnings;
use v5.10;
use Mojolicious::Lite;
get '/login' => sub { shift->render } => 'login';
@Logioniz
Logioniz / autoload.pl
Created April 13, 2015 09:10
Example of AUTOLOAD
#!/usr/bin/perl
package A1;
use Data::Dumper;
our $AUTOLOAD;
sub new { my $class = shift; bless {@_}, ref $class || $class };
sub AUTOLOAD {
@Logioniz
Logioniz / client.pl
Created April 24, 2015 11:26
Upload big file to server. Server save it to temp directory.
#!/usr/bin/perl
use strict;
use warnings;
use v5.10;
use Mojo::UserAgent;
say Mojo::UserAgent->new->post('http://127.0.0.1:3000/' => form => {
@Logioniz
Logioniz / client.pl
Created April 24, 2015 19:58
UserAgent: send multipart/form-data.
#!/usr/bin/perl
use Mojo::Base -strict;
use Mojo::Util 'encode';
use Mojo::UserAgent;
say Mojo::UserAgent->new->post('http://127.0.0.1:3000/' => form => {
file_name_1 => [
{
# file => '/path/to/file',
@Logioniz
Logioniz / .bashrc
Last active May 1, 2016 08:23
Environoment
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\]\u\[\033[01;32m\]@\[\033[01;31m\]\h\[\033[00m\]:\[\033[01;35m\]\w\[\033[01;31m\]$(__git_ps1 " (%s) ")\[\033[01;32m\]\$ \[\033[00m\]'
function svndiff () { svn diff $@ | colordiff; }
PATH=$PATH:/home/logioniz/Scripts