Hatena::ブログ(Diary)

satoru.netの自由帳 このページをアンテナに追加 RSSフィード

180921Friday

[]perlからphpのsession read

いまさらperlつかってるひとなんて化石なんだろうなあとおもいつつーperlだいすき


https://www.h-fj.com/blog/archives/2013/02/27-152952.php

use Data::Dumper

use CGI::Cookie;

use PHP::Serialization qw( unserialize );

my %ck = fetch CGI::Cookie;;

my $data = $memd->get($ck{PHPSESSID}->value);

$data =~ s/^[^\|]+\|//;

my $ref = PHP::Serialization::unserialize($data);

print Dumper($ref);

180626Tueday

when https disabled memo

yum -y install perl-Net-SSLeay perl-Crypt-SSLeay perl-IO-Socket-SSL
cpanm LWP::Protocol::https

mecab memo

yum -y install mecab mecab-ipadic mecab-devel
cpanm Text::MeCab

180114Sunday

並列処理 Parallel::ForkManager @ perl

  • 時間のかかる処理を{}で括って$pm->start and next;と$pm->finish;で待機させる
  • count1は10秒で終わる、count2は5秒で終わる処理を並列処理するサンプル
#!/usr/bin/perl

use Parallel::ForkManager;

my $pm = Parallel::ForkManager->new(2);

## 処理1
{
	$pm->start and next;
	my $count1 = 0;
	while(1){
		if($count1++ == 10){
			print "count1 finish!\n";
			last;
		}
		print "count1 $count1\n";
		sleep 1;
	}
	$pm->finish;
}

## 処理2
{
	$pm->start and next;
	my $count2 = 0;
	while(1){
		if($count2++ == 5){
			print "count2 finish!\n";
			last;
		}

		print "count2 $count2\n";
		sleep 1;
	}
	$pm->finish;
}

$pm->wait_all_children;

print "ALL FINISH $count1 $count2\n";

結果

count1 1
count2 1
count1 2
count2 2
count1 3
count2 3
count1 4
count2 4
count1 5
count2 5
count1 6
count2 finish!
count1 7
count1 8
count1 9
count1 10
count1 finish!
ALL FINISH

180112Friday

coincheck-API perl

#!/usr/bin/perl

use HTTP::Tiny;
use Digest::SHA qw/hmac_sha256_hex/;
use strict;

my $ACCESS_KEY = ACCESS_KEY;
my $SECRET_KEY = SECRET_KEY;

my $dt = time*10000;
my $url = "https://coincheck.com/api/ticker";
my $signature = hmac_sha256_hex($dt . $url ,$SECRET_KEY);
my $tiny = new HTTP::Tiny(
	default_headers => {
		"ACCESS-KEY" => $ACCESS_KEY,
		"ACCESS-NONCE"=> $dt,
		"ACCESS-SIGNATURE"=> $signature,
	}
);

my $res = $tiny->get("$url");
print $res->{content};

171113Monday

node-js memo (for self)

memo

que

NodeJS Socket.io : Many connections in state CLOSE_WAIT and FIN_WAIT2 without release

https://stackoverflow.com/questions/20777827/nodejs-socket-io-many-connections-in-state-close-wait-and-fin-wait2-without-re

ans

Also, it appears that calling socket.destroy() from worker processes on Node.js v4.9.5 also leads to sockets stuck in CLOSE_WAIT state. Updating to Node.js v6.9.5 LTS fixed this for me.

memo

links

©satoru.net
Mail Twitter