Hatena::ブログ(Diary)

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

181220Thuday

順番が変になったカラムを特定のキー順に振りなおしてやりなおせるSQL

ALTER TABLE `subject` CHANGE num num int(11) NOT NULL;

alter table subject drop primary key;

SET @i := 0; UPDATE subject SET num = (@i := @i +1) ORDER BY created;

ALTER TABLE subject CHANGE num num int auto_increment, ADD PRIMARY KEY(num);

ALTER TABLE subject AUTO_INCREMENT = @i;

実行は一瞬

181110Satday

[] nes resources ..

https://www.spriters-resource.com/nes/

ファミコン系ゲームつくりたいとき用の素材サイト

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

©satoru.net
Mail Twitter