Skip to content

Instantly share code, notes, and snippets.

View riywo's full-sized avatar
🏈
Go 49ers!

Ryosuke Iwanaga riywo

🏈
Go 49ers!
View GitHub Profile
use strict;
use warnings;
use IPC::Open2 qw(open2);
## warning = Name "main::OUT1" used only once: possible typo
open2(\*OUT1, undef, 'iostat', '1', '3');
open2(\*OUT2, "<&OUT1", 'cat', '-nu');
print while(<OUT2>);
## error = open2: close(main::GLOB(0x827988)) failed: Bad file descriptor
@riywo
riywo / gist:885109
Created March 24, 2011 14:05
Parallel::ForkManager使って普通のforkっぽいことをやる
use strict;
use warnings;
use IO::Handle;
use Parallel::ForkManager;
my $pm = Parallel::ForkManager->new(2);
my ($pread, $pwrite);
pipe $pread, $pwrite;
use strict;
use warnings;
use Plack::Builder;
use Plack::Session;
use Plack::Session::State::Cookie;
use Plack::Session::Store::Cache;
use Authen::Simple::DBI;
use Data::Section::Simple;
use Text::Xslate;
use Cache::Memcached::Fast;
--- /usr/local/Library/Homebrew/cmd/install.rb.bak 2011-04-01 04:18:15.000000000 +0900
+++ /usr/local/Library/Homebrew/cmd/install.rb 2011-04-01 05:05:30.000000000 +0900
@@ -23,7 +23,7 @@
def check_writable_install_location
raise "Cannot write to #{HOMEBREW_CELLAR}" if HOMEBREW_CELLAR.exist? and not HOMEBREW_CELLAR.writable?
- raise "Cannot write to #{HOMEBREW_PREFIX}" unless HOMEBREW_PREFIX.writable?
+ raise "Cannot write to #{HOMEBREW_PREFIX}" unless HOMEBREW_PREFIX.writable_real?
end
[~/.cpanm/latest-build/AnyEvent-Impl-NSRunLoop-0.04]$ perl -Mlib=blib/lib t/03_child.t
1..50
ok 1
ok 2
ok 3 # 26944 == 26944
ok 4 # 3 == 768 >> 8 (768)
ok 5 # 26945 == 26945
ok 6 # 7 == 1792 >> 8 (1792)
ok 7
ok 8
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::RealBin/lib";
use lib "$FindBin::RealBin/extlib/lib/perl5";
use Cache::LRU;
use Config::Simple;
use Cybozu::Garoon::Notify;
@riywo
riywo / gist:919309
Created April 14, 2011 11:39
設定ファイルをperlで書き換える
use strict;
use warnings;
use File::Copy;
open my $conf, '<', '/etc/my.cnf' or die;
open my $conf_new, '>', '/tmp/my.cnf' or die;
while (<$conf>) {
chomp;
my $line =
@riywo
riywo / gist:923775
Created April 17, 2011 05:26
extlib的なところにcpanmが入ってるかチェックして入ってなければ入れるテストスクリプトライクなセットアップスクリプト
use strict;
use warnings;
use Test::More qw(no_plan);
use FindBin;
my $extlib = "/home/riywo/extlib";
isnt(`which gcc`, '', 'check gcc') or &{
diag(`sudo yum install gcc -y`);
};
use strict;
use warnings;
use Test::More;
open my $fh, '>', \(my $output_buffer = '');
Test::More->builder->output($fh);
Test::More->builder->failure_output($fh);
Test::More->builder->todo_output($fh);
note "hoge";
@riywo
riywo / gist:1251364
Created September 29, 2011 17:37
形態素解析した結果を数えるとか

りすこがこんなの書いてて、聞いてみたら名詞だけ抜き出してcountとかやりたいとか。 そういう時はawk使うと便利ですよ(perlでもいいですが)

$ cat filename | awk '$4 ~ /^名詞/{print $1}' | sort | uniq -c | sort -n

4個目のカラムが「品詞」で始まる性質を使ってます。