Skip to content

Instantly share code, notes, and snippets.

View olegwtf's full-sized avatar

Oleg olegwtf

  • reg.ru
  • Russia, Novosibirsk
View GitHub Profile
@olegwtf
olegwtf / split_number.pl
Created April 19, 2012 16:57
split number by thousands
my $str = '0123456789';
$str =~ s/(?<=.)(?=(?:\d{3})+$)/ /g;
@olegwtf
olegwtf / pgolf.pl
Created April 17, 2012 17:38
Perl Golf
$i++%50||++$j&mkdir($f="folder$j")&($i=1),rename$_,"$f/$i"for<*>
@olegwtf
olegwtf / coro-lwp-timeout.t
Created April 14, 2012 10:09
coro::lwp and timeout test
#!/usr/bin/env perl
use strict;
use Coro::LWP;
use Coro;
use LWP;
use Test::More tests => 1;
sub make_broken_http_server {
my $serv = IO::Socket::INET->new(Listen => 1);
@olegwtf
olegwtf / json_ordered.pl
Created March 26, 2012 04:39
Save JSON object keys ordering as is
use strict;
use Tie::IxHash;
use JSON::PP;
# magic start
my $obj_parser_sub = \&JSON::PP::object;
*JSON::PP::object = sub {
tie my %obj, 'Tie::IxHash';
$obj_parser_sub->(\%obj);
@olegwtf
olegwtf / mojolicious_fork.pl
Created March 19, 2012 06:05
Mojolicious fork
use Mojolicious::Lite;
use POSIX;
get '/' => sub {
my $child = fork();
unless (defined $child) {
die "fork(): $!";
}
elsif ($child == 0) {
@olegwtf
olegwtf / private-or-no.cpp
Created January 26, 2012 17:34
Encapsulation
#include <iostream>
class Ax {
public:
Ax(int a);
bool compare(const Ax &other);
private:
int m_a;
};
@olegwtf
olegwtf / won.pl
Created January 24, 2012 12:21
works or not
use Data::Dumper;
use strict;
$a = ['google.ru', on_prepare => sub {}, timeout => 10, sub{}];
print Dumper _extract_known_params($a);
print Dumper ($a), "-------\n";
$a = ['google.ru', timeout => 10, on_prepare => sub {}, sub{}];
print Dumper _extract_known_params($a);
print Dumper ($a), "-------\n";
@olegwtf
olegwtf / a-g-p-warns.pl
Created January 24, 2012 01:43
Any Warnings?
use strict;
use warnings;
use AnyEvent::Google::PageRank 'rank_get';
my $cv = AE::cv;
rank_get 'http://www.google.ru', sub {
print shift, "\n";
$cv->send;
};
$cv->recv;
@olegwtf
olegwtf / lambda-http.pl
Created January 12, 2012 17:37
IO::Lambda::HTTP
use strict;
use URI;
use HTTP::Request;
use IO::Lambda qw(:all);
use IO::Lambda::HTTP qw(http_request);
sub request($) {
my $url = URI->new($_[0]);
my $req = HTTP::Request->new(GET => $url, [Host => $url->host]);
$req->protocol('HTTP/1.1');
@olegwtf
olegwtf / pchange.pl
Created December 6, 2011 15:21
I:S:S:W runtime proxy changing test
BEGIN {
$ENV{SOCKS_DEBUG} = 1;
}
use IO::Socket::Socks::Wrapper (
Net::FTP => {
ProxyAddr => 'localhost',
ProxyPort => 1080,
SocksVersion => 5
},
Net::FTP::dataconn => {