Skip to content

Instantly share code, notes, and snippets.

@Logioniz
Logioniz / client-ev.pl
Created September 12, 2015 09:57
Non-blocking client
#!/use/bin/perl
use Mojo::Base -strict;
use Socket qw/:DEFAULT SOCK_NONBLOCK/;
use Data::Dumper;
use EV;
my $host="localhost";
my $port="3000";
socket(my $sock, PF_INET, SOCK_STREAM | SOCK_NONBLOCK, getprotobyname('tcp'));
@Logioniz
Logioniz / server-epoll.c
Last active May 8, 2022 15:30
Non-blocking servers
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <errno.h>
@Logioniz
Logioniz / 1.pl
Created May 21, 2015 07:21
Mojo test inactivity_timeout long operation.
use Mojo::Base -strict;
use Mojo::IOLoop;
use Mojolicious::Lite;
use Test::More;
use Test::Mojo;
get '/' => sub {
my $c = shift->render_later;
$c->inactivity_timeout(40);
@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
@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 / 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 / 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 / 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 / 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 / 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) = @_;