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 / 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 / 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 / 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 / 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 / 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 / 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 / split_number.pl
Created April 19, 2012 16:57
split number by thousands
my $str = '0123456789';
$str =~ s/(?<=.)(?=(?:\d{3})+$)/ /g;
@olegwtf
olegwtf / 1с.pl
Created April 19, 2012 18:15
Perl like 1С
use utf8;
my $мама = 'рама';
sub мой($) {
print "я мою ", shift, "\n";
}
мой($мама);
@olegwtf
olegwtf / method_declare.pl
Created May 6, 2012 10:54
Combined example from Devel::Declare doc
package Syntax::method;
use Devel::Declare;
use B::Hooks::EndOfScope;
use strict;
sub import {
my $class = shift;
my $caller = caller;
CREATE TABLE `dbrepl`.`allok` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(256) NOT NULL,
`type` enum('TYPE_OK','TYPE_FAIL') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8