Skip to content

Instantly share code, notes, and snippets.

Avatar

Toshiaki_Yokoda adokoy001

View GitHub Profile
@adokoy001
adokoy001 / rarity.pl
Created Jun 21, 2017
Error function and Rarity calculation with Gauss distribution.
View rarity.pl
use strict;
use warnings;
use bignum (a => 200);
# error function
sub erf {
my $x = shift;
$x = $x * sqrt(2);
my $sqrt2pi = sqrt(2 * 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027);
my $t = 1.0/(1.0 + 0.2316419*abs($x));
@adokoy001
adokoy001 / mr_prime.pl
Created Jun 7, 2017
Summation of Prime numbers by MapReduce::Framework::Simple
View mr_prime.pl
use strict;
use warnings;
use MapReduce::Framework::Simple;
my $mfs = MapReduce::Framework::Simple->new(
skip_undef_result => 1,
warn_discarded_data => 1
);
my $data_map_reduce = [
@adokoy001
adokoy001 / quine.pl
Last active Apr 2, 2017
Quine like self-rewriting program in perl
View quine.pl
eval($code=q{
# Quine like self-rewriting program
# 1st : $ perl quine.pl > a1.pl
# repeat : $ perl a1.pl > a2.pl ; cat a2.pl ; cp a2.pl a1.pl
$str="
XXXXXXXXXX
A
XXXXXXXXXX
";
@adokoy001
adokoy001 / db_example.pl
Created Jan 21, 2017
MapReduce::Framework::Simple
View db_example.pl
use strict;
use warnings;
use MapReduce::Framework::Simple;
use Data::Dumper;
use DBI;
my $mfs = MapReduce::Framework::Simple->new();
my $data_bk =
@adokoy001
adokoy001 / list_compare.pl
Last active Sep 20, 2016
List comparison in Perl
View list_compare.pl
use strict;
use warnings;
sub list_unique{
my $left = shift;
my $right = shift;
my @list = (@$left,@$right);
my %tmp1;
my @unique = grep { !$tmp1{$_}++ } (@list);
return @unique;
@adokoy001
adokoy001 / bench_sum.pl
Created Jul 11, 2016
MapReduce::Framework::Simple Benchmark example.
View bench_sum.pl
use strict;
use warnings;
my $sum = 0;
for(1 .. 3_000_000_000){
$sum += $_;
}
print $sum,"\n";
View MapReduce by YCGL::Lite
# You can startup MR worker by one liner below.
# $ perl -MYCGL::Lite -e 'YCGL::Lite->new->plack->plackup_eval("/eval");'
# Example: Word count
use strict;
use warnings;
use YCGL::Lite;
use Data::Dumper;
my $ycgl = YCGL::Lite->new();
@adokoy001
adokoy001 / prefork_ssl_echo_client.pl
Last active Nov 11, 2015
prefork ssl echo server and client
View prefork_ssl_echo_client.pl
use strict;
use warnings;
use IO::Socket::SSL;
while(1){
my $c = IO::Socket::SSL->new(
PeerAddr => "localhost",
PeerPort => 5001,
Proto => "tcp",
SSL_verify_mode => 'SSL_VERIFY_NONE'
@adokoy001
adokoy001 / plack_psgi_example.pl
Created Oct 13, 2015
PSGI Plack example with Japanese comments.
View plack_psgi_example.pl
use strict;
use warnings;
use Plack::MIME; # mimeタイプ自動判別用
use Data::Dumper;
use File::Slurp; # 効率的な静的ファイル応答
# 静的ファイル置き場
my $public_dir = './public';
# ディレクトリインデックスの指定
@adokoy001
adokoy001 / partial_corr_demo.pl
Created Dec 25, 2014
Perl : PDLを使って偏相関係数行列を生成
View partial_corr_demo.pl
use strict;
use warnings;
use PDL;
use PDL::Stats::Basic;
# モジュール化するまでも無いのでgistに載せます。
# ランダム要素を無くすと出力がInfになったりするのでそこはご愛嬌ということで。
# また、対角要素は-1になってしまいます。
# 偏相関係数行列を求める関数
sub partial_corr{
You can’t perform that action at this time.