並列処理 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

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};

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

'X-Frame-Options' to 'sameorigin'でpdfをiframeできない時の対処法

クリックジャッキング対策の対策

Refused to display '[pdfのURL]' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

と出てiframe内で外部サイトのPDFを表示できない場合の対処法

解決法

googleのPDFビュアーを通してembedのパラメータonにして表示させればok

iframeで表示されない。

iframeできるようになる

※パラメーターにembedded=trueを入れる

裁判が開始する10分前になるとツイート『傍聴bot』リリース

裁判の開始をツイートしてくれる『傍聴bot @bocho_bot』リリースしました。

事件番号、法廷、罪名、審議を法廷開始の10分前になると自動ツイートするよー



裁判傍聴のお供にどうぞ