Skip to content

Instantly share code, notes, and snippets.

@Logioniz
Logioniz / 1.pl
Created April 18, 2016 11:10
Eample with blocking task.
# to run simple execute: morbo 1.pl
# go to link htpp://127.0.0.1:3000/
use Mojolicious::Lite;
use Mojo::IOLoop;
use Mojo::IOLoop::ReadWriteFork;
get '/' => 'index';
websocket '/find' => sub {
@Logioniz
Logioniz / Readme
Created June 22, 2016 14:01
Mojo client verification and get certificate info
Generate 2 certficate:
openssl req -nodes -new -x509 -keyout client.key -out client.cert
openssl req -nodes -new -x509 -keyout server.key -out server.cert
run server:
morbo server.pl -l 'https://*:3000?cert=./server.cert&key=./server.key&ca=client.cert'
run client:
openssl s_client -connect 127.0.0.1:3000 -cert client.cert -key client.key
GET / HTTP/1.0
@Logioniz
Logioniz / Mojolicious::Plugin::Coro.pm
Last active July 22, 2018 12:34
Coro and Mojolicious
package Mojolicious::Plugin::Coro;
use Mojo::Base 'Mojolicious::Plugin';
use Coro;
use Mojo::IOLoop;
# Wrap application in coroutine and reschedule main coroutine in event loop
sub register {
my ($self, $app) = @_;
my $subscribers = $app->plugins->subscribers('around_dispatch');
@Logioniz
Logioniz / 1.sql
Created December 16, 2016 12:42
Postgresql upsert with many constraints
create table test (id int primary key, a int, b int, unique (a, b));
\d+ test
begin;
insert into test values (1, 1, 1);
do $$
declare
_cn text;
begin
insert into test values (1, 2, 2);
@Logioniz
Logioniz / my_ioloop.pl
Created January 28, 2017 01:51
Example of ioloop (based on Mojo::IOLoop)
#!/usr/bin/perl
package Reactor::Select;
use Mojo::Base -base;
use IO::Select;
sub new {
my $self = shift->SUPER::new;
$self->{select}{read} = IO::Select->new;
@Logioniz
Logioniz / mystem.pl
Last active February 18, 2017 08:05
Web server wrapper for mystem
#!/usr/bin/perl
use Mojo::Base -strict;
use Mojo::JSON::MaybeXS;
use Mojo::JSON 'decode_json';
use Mojolicious::Lite;
use IPC::Open3;
use Mojo::IOLoop;
my $mystem_path = '/usr/local/bin/mystem';
@Logioniz
Logioniz / socks.pl
Last active March 11, 2017 07:51
Simple non-blocking socks server
#!/usr/bin/perl
use Mojo::Base -strict;
use Socket;
use Mojo::IOLoop;
use IO::Socket::Socks qw/:constants $SOCKS_ERROR/;
my @configs = ({
proxy_addr => '127.0.0.1',
proxy_port => 12345,
@Logioniz
Logioniz / client.pl
Created April 11, 2017 17:35
Example tls server and client
#!/usr/bin/perl
use Mojo::Base;
use Mojo::IOLoop;
use Mojo::IOLoop::Client;
use Mojo::IOLoop::TLS;
use IO::Socket::IP;
my $s;
@Logioniz
Logioniz / callback.dynamic.sequential.pl
Last active May 12, 2017 08:04
Sequential dynamic requests
#!/usr/bin/perl
use Mojo::Base -strict;
use Mojo::IOLoop;
use Mojo::UserAgent;
use Mojo::URL;
my $ua = Mojo::UserAgent->new(max_redirects => 3);
sub find_new_url {
@Logioniz
Logioniz / dpd.pl
Created August 15, 2017 06:55
dpd soap::lite example
#!/usr/bin/perl
use Mojo::Base -strict;
use SOAP::Lite +trace => 'all';
use DDP;
my $soap = new SOAP::Lite->new;
$soap->autotype(0);
$soap->readable(1);
$soap->service('http://ws.dpd.ru/services/geography2?wsdl');