Skip to content

Instantly share code, notes, and snippets.

View nikita-d's full-sized avatar

Nikita Dubrovin nikita-d

  • Budva, Montenegro
View GitHub Profile
BEGIN {
$ENV{BAIL_ON_FAIL} ||= 1;
}
use Modern::Perl qw|2013|;
use Data::Printer (use_prototypes => 0);
use Test::Most;
use Mojo::DOM;
my $rss = "<channel>
@nikita-d
nikita-d / plugin_redis.pm
Last active August 29, 2015 14:02
Mojo::Redis Plugin
package RT::Plugin::Redis;
use Mojo::Base qw|Mojolicious::Plugin|;
use Modern::Perl qw|2013|;
use Data::Printer (use_prototypes => 0);
use Mojo::Redis;
sub register {
my ($self, $app) = @_;
my $config = $app->config;
use Data::Printer (use_prototypes => 0);
use Modern::Perl qw|2013|;
use Mojolicious::Lite;
use Mojo::Redis;
app->attr('salt' => 'passw0rd');
app->helper(
'redis_db' => sub {
my $c = shift;
$app->helper(
'check_authentication' => sub {
my $c = shift;
my $cb = pop;
my $session_id = shift;
die 'no session id' unless defined $session_id && $session_id;
my $redis = $c->redis_session;
my $log = $c->app->log;
package RTRu::Admin::Auth;
use Modern::Perl qw|2013|;
use Mojo::Base qw|Mojolicious::Controller|;
use Data::Printer (use_prototypes => 0);
use Hash::Merge::Simple qw|merge|;
sub login {
my $c = shift;
# return $c->redirect_to($c->url_for('page_index'))
sub load {
my ($self, $sid) = @_;
my $redis = $self->redis();
my $prefix = $self->redis_prefix;
my $session;
my $delay = Mojo::IOLoop->delay(
sub {
my ($d, $res) = @_;
$res->{'data'} = $res->{'data'} ? decode_json($res->{'data'}) : undef ;
@nikita-d
nikita-d / gist:9390784
Last active August 29, 2015 13:57
Memory cycle output
#!/usr/bin/env perl
use utf8::all;
use Modern::Perl qw|2013|;
use Data::Printer (use_prototypes => 0);
use Mojolicious::Lite;
use Test::Most;
use Test::More;
use Test::Mojo;
use RT::Admin;
@nikita-d
nikita-d / mojolicious_ymd_routes.t
Created January 13, 2014 15:19
A minimal use case for '/:year/:month/:day' routes.
use Test::Most;
use Mojolicious::Lite;
use Data::Printer (use_prototypes => 0);
use Test::Mojo;
use InoTV::DatePaginator;
my $now = DateTime->now;
under '/:year/:month/:day' => { year => $now->year, month => $now->month, day => undef } => sub {
my $c = shift;
@nikita-d
nikita-d / zmq_proxy.pl
Created June 19, 2013 11:55
ZeroMQ XSUB/XPUB proxy
#!/usr/bin/env perl
use Modern::Perl qw|2013|;
use Data::Printer (use_prototypes => 0, colored => 1);
use ZMQ::Constants qw|:all|;
use ZMQ;
my $ctx = ZMQ::Context->new(1);
my $frontend = $ctx->socket(ZMQ_XSUB);
@nikita-d
nikita-d / Example.pm
Created June 19, 2013 11:50
Example controller for websocket app.
package WebSocket::Simple::Example;
use Mojo::Base 'Mojolicious::Controller';
use ZMQ;
use ZMQ::Constants qw|ZMQ_NOBLOCK|;
use Mojo::JSON qw|j|;
use Mojo::ByteStream qw|b|;
use Data::Printer (
use_prototypes => 0,
colored => 1
);