Skip to content

Instantly share code, notes, and snippets.

package MySQL::Partition::Definition;
use strict;
use warnings;
use parent qw(Class::Accessor::Fast);
use Data::Util qw(is_array_ref is_scalar_ref is_integer is_number is_value);
use DBI qw(:sql_types);
our $VERSION = '0.01';
use strict;
use warnings;
use Test::More;
use Test::SharedFork;
use Parallel::Prefork;
use IO::Pipe;
my $pm = Parallel::Prefork->new(+{
max_workers => 3,
@zigorou
zigorou / Maker.pm
Created April 18, 2011 11:59
from and join
sub select_query {
my ($self, $table, $fields, $where, $opt) = @_;
unless (ref $fields eq 'ARRAY') {
Carp::croak("SQL::Maker::select_query: \$fields should be ArrayRef[Str]");
}
my $stmt = $self->new_select(
select => $fields,
);
@zigorou
zigorou / poll.pl
Created October 25, 2011 13:40
perl echo servers
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Getopt::Long;
use IO::Socket::INET;
use IO::Poll;
use Log::Minimal;
@zigorou
zigorou / ae_handle.pl
Created October 31, 2011 14:57
echo servers by AnyEvent
#!/usr/bin/env perl
use strict;
use warnings;
use AnyEvent;
use AnyEvent::Handle;
use AnyEvent::Socket;
use Data::Dump qw(dump);
@zigorou
zigorou / redis_connect.c
Created November 8, 2011 16:23
connect to redis by hiredis
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <hiredis/hiredis.h>
/**
* gcc -I/usr/local/include -L/usr/local/lib -lhiredis -Wall -o connect connect.c
*/
void redisDisconnect(redisContext *ctx) {
@zigorou
zigorou / ae_timer_and_idle_watcher.pl
Created November 8, 2011 17:11
AnyEvent Timer and Idle Watcher
#!/usr/bin/env perl
use strict;
use warnings;
use AnyEvent;
my $cv = AnyEvent->condvar;
for my $i (1..10) {
$cv->begin;
@zigorou
zigorou / Makefile
Created December 18, 2011 15:22
Building MySQL UDF on MacOSX
MYSQL_BUILD_DIR =
MYSQL_PLUGIN_DIR =
CC := gcc
CPPFLAGS := -Iinclude -I$(MYSQL_BUILD_DIR)/include -dynamiclib
LIB_FILE := lib_mysqludf_calc_distance.dylib
VPATH := src include
all: lib_mysqludf_calc_distance.dylib
lib_mysqludf_calc_distance.dylib: src/lib_mysqludf_calc_distance.c include/lib_mysqludf_calc_distance.h
$(CC) $(CPPFLAGS) -o $@ src/lib_mysqludf_calc_distance.c
@zigorou
zigorou / pf_with_data_structure.pl
Created December 19, 2011 18:03
Parallel::ForkManager and aggregate results
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dump qw(dump);
use Parallel::ForkManager 0.7.6;
my @servers = map { sprintf("svr%03d", $_) } (1 .. 1000);
my %results;
@zigorou
zigorou / pp_with_pipe.pl
Created December 20, 2011 10:53
For mandy
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dump qw(dump);
use IO::Pipe;
use Parallel::Prefork;
use Time::HiRes;