Skip to content

Instantly share code, notes, and snippets.

View sharifulin's full-sized avatar

Anatoly Sharifulin sharifulin

View GitHub Profile
@sharifulin
sharifulin / gist:611589
Created October 5, 2010 14:01
LWP::UserAgent vs. Mojo::Client
use Mojo::Client;
use LWP::UserAgent;
use Test::More tests => 6;
my $r;
$r = LWP::UserAgent->new->post(
'http://post.audioscrobbler.com/2.0/',
'Content-Type' => 'application/x-www-form-urlencoded',
@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 / example.pl
Last active October 24, 2016 09:43
Usage intercom (api_key)
# Пример модуля
use Mojo::JSON;
use Mojo::UserAgent;
has json => sub { Mojo::JSON->new };
has ua => sub { Mojo::UserAgent->new };
use constant DEBUG => $ENV{APPFOLLOW_ANALYTICS_DEBUG} || 1;
has is_debug => DEBUG;
@sharifulin
sharifulin / gp_parse_developer.sh
Last active December 20, 2015 16:59
Google Play and Mojo, powered by Perl
# all apps in html
$ mojo get "https://play.google.com/store/apps/developer?id=Яндекс&hl=ru" "a[class=title]"
# all apps title
$ mojo get "https://play.google.com/store/apps/developer?id=Яндекс&hl=ru" "a[class=title]" text
# all apps link
$ mojo get "https://play.google.com/store/apps/developer?id=Яндекс&hl=ru" "a[class=title]" attr href
use v5.12;
use List::Util 'sum';
my $data = [
map {
chomp;
my $res; @$res{qw(impr clicks ctr cost)} = grep { s/\s+//sg; s/,/./sg; s/%//sg; 1 } split /\t/; $res;
}
<DATA>
];
@sharifulin
sharifulin / gist:5921524
Created July 3, 2013 18:42
Норм код, да? :-)
# ids
my @ids = $self->req->param('id');
if (!@ids and my $ids = $self->req->param('ids')) {
@ids = $ids =~ /(\d+)/g;
}
#!/usr/bin/perl
use common::sense;
use lib qw(/tk/lib /tk/mojo/lib);
$ENV{MOJO_APP} ||= 'Proxy';
use Mojo::Commands; Mojo::Commands->start;
package Proxy;
use common::sense;
#!/usr/bin/env perl
use v5.12;
my $limit = 500;
my $re = qr{ dt=(\d{3,}) }x;
my $re2 = qr{\? p=([^&]+) & h=([^&]+) }x;
for (1..3_000_000) {
my $line = q(127.0.0.1 - - [15/May/2013:21:35:24 +0000] "GET /hc/cdn-bench.gif?p=http&h=host.example.org&dt=235 HTTP/1.1" 200 43 "http://example.org/blah/?q=Kiev&sort=price.asc&utm_source=yandex&utm_medium=cpc&utm_campaign=s_gen_city_cis_ua_kiev_1565_alldevices_georus&from=earch.no&_openstat=zzz" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1106.241 YaBrowser/1.5.1106.241 Safari/537.4" "0.002" "ostrovok.ru" "1368653724.588" "lucky:92" us:1.1.1.1:80 us_t:0.001);
#!/usr/bin/env perl
use v5.12;
my $line = q(127.0.0.1 - - [15/May/2013:21:35:24 +0000] "GET /hc/cdn-bench.gif?p=http&h=host.example.org&dt=235 HTTP/1.1" 200 43 "http://example.org/blah/?q=Kiev&sort=price.asc&utm_source=yandex&utm_medium=cpc&utm_campaign=s_gen_city_cis_ua_kiev_1565_alldevices_georus&from=earch.no&_openstat=zzz" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1106.241 YaBrowser/1.5.1106.241 Safari/537.4" "0.002" "ostrovok.ru" "1368653724.588" "lucky:92" us:1.1.1.1:80 us_t:0.001);
my $re = qr{\? p=([^&]+) & h=([^&]+) & dt=(\d+) }x;
for (1..3_000_000) {
my @r = $line =~ /$re/;
@sharifulin
sharifulin / stat_fb_ads.pl
Last active December 16, 2015 08:19
Working with Facebook Ads stats (iOS, Android campaigns). I like Perl! :-)
#!/usr/bin/env perl
use v5.12;
use Encode;
use Text::CSV;
use Data::Dumper;
my $dir = '/Users/sharifulin/Downloads/refb814';
while (<$dir/*.csv>) {