Skip to content

Instantly share code, notes, and snippets.

View sharifulin's full-sized avatar

Anatoly Sharifulin sharifulin

View GitHub Profile
@sharifulin
sharifulin / gist:829553
Created February 16, 2011 15:26
Format Bytes
sub _format_byte {
my $self = shift;
my $byte = shift;
my $str;
for (reverse [ 1 => 'B' ], [ 1024 => 'KB' ], [ 1024 ** 2 => 'MB' ], [ 1024 ** 3 => 'GB' ], [ 1024 ** 4 => 'TB' ]) {
my $temp = $byte / $_->[0];
$str = sprintf "%0.2f $_->[1]", $temp;
$str =~ s/\.?0+ / /;
use common::sense;
my $n = 1.229;
my $n = 4;
say 1 + $1 if $n =~ /(\d+)\./; # simple and good!
say $n =~ /(\d+)\./ && $1 + 1; # not pretty :)
@sharifulin
sharifulin / gist:754417
Created December 24, 2010 17:39
Upload bug
#!/usr/bin/env perl
use common::sense;
use lib 'lib';
use Mojolicious::Lite;
use Test::Mojo;
use Test::More tests => 8;
use Data::Dumper;
@sharifulin
sharifulin / gist:736180
Created December 10, 2010 13:04
Mojo::DOM and bug with tag case
#!/usr/bin/env perl
use strict;
use lib 'lib';
use ojo;
use Test::More tests => 4;
my $xml = do { local $/; <DATA> };
my $x = x($xml);
@sharifulin
sharifulin / tochkak.pl
Created November 24, 2010 17:01
Code of tochkak.ru
#!/usr/bin/env perl
use common::sense;
use Mojolicious::Lite;
get '/' => 'about/what' ;
get '/who' => 'about/who' ;
get '/what' => 'about/what' ;
get '/where' => 'about/where';
get '/code' => 'about/code' ;
@sharifulin
sharifulin / artist.pl
Created November 24, 2010 16:47
Get images from Last.fm API
my $imgs = eval { $net->request(
method => 'artist.getImages',
artist => $artist,
)->{images} };
unless ($@) {
if (my @imgs =
map {
my $h = {
map { $_->{name} => $_->{'#text'} }
@sharifulin
sharifulin / gist:666140
Created November 7, 2010 14:07
Small bug: inflate + utf8
#!/usr/bin/env perl
use Mojolicious::Lite;
use utf8;
get '/' => 'index';
get '/:groovy' => sub {
my $self = shift;
$self->render(text => $self->param('groovy'), layout => 'funky');
@sharifulin
sharifulin / gist:658382
Created November 1, 2010 15:41
Uploadify and Mojolicious app
#!/usr/bin/env perl
BEGIN { $ENV{MOJO_MAX_MESSAGE_SIZE} = 50 * 1024 * 1024; }
use Mojolicious::Lite;
my $conf = { path => 'data/uploads/', ext => qr/\.(?i:mp3|wav|wma|ogg)$/ };
post '/uploadify/check' => sub {
my $self = shift;
my $param = $self->req->params->to_hash;
@sharifulin
sharifulin / gist:626753
Created October 14, 2010 18:39
Mojolicious app + dw
# controller
sub list {
my $self = shift;
my $DB = $self->app->db;
my $where = $self->stash('act') ? 'status=' . $DB->quote( $self->stash('act') ) : 1;
$self->stash(
page => $_,