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
@riywo
riywo / gist:868772
Created March 14, 2011 04:19
innobackupexでログにパスワードを生で吐かない様に
# diff -u /usr/bin/innobackupex-1.5.1 innobackupex-1.5.1
--- /usr/bin/innobackupex-1.5.1 2010-11-12 16:13:38.000000000 +0900
+++ innobackupex-1.5.1 2011-03-14 13:17:24.000000000 +0900
@@ -1134,7 +1134,8 @@
my $options = get_mysql_options();
# run mysql as a child process with a pipe connection
$now = current_time();
- print STDERR "$now $prefix Starting mysql with options: $options\n";
+ (my $prt_options = $options) =~ s/--password=[^ ]+ /--password=xxxxxxxx /g;
+ print STDERR "$now $prefix Starting mysql with options: $prt_options\n";
@riywo
riywo / gist:870404
Created March 15, 2011 06:56
引数に与えた単語をGoogle翻訳で多言語に投げてみるスクリプト
use strict;
use warnings;
use Furl;
use JSON;
use Encode;
use Web::Scraper;
my $furl = Furl->new;
my $scraped = scraper {
@riywo
riywo / gist:870515
Created March 15, 2011 09:46
GNU parallel使って並列でrsyncする&ちゃんとmkdirする
find /path/to/dir/ -type f | time parallel --eta 'rsync -aRz --compress-level=1 {} remote:/'
@riywo
riywo / gist:872848
Created March 16, 2011 17:06
ファイルハンドルを途中で読み込み止めるにはどうするのがいいのかな。。。
use strict;
use warnings;
use IO::Handle;
my ($parent_in, $parent_out);
my ($child_in, $child_out);
pipe $parent_out, $child_in;
pipe $child_out, $parent_in;
@riywo
riywo / gist:872908
Created March 16, 2011 17:41
オレオレperlipcまとめ
@riywo
riywo / microsec.pl
Created March 17, 2011 04:54
DBD::mysqlでのinsertの処理時間(localhost接続)
mysql> select * from microsec limit 10;
+------------+--------+
| epoch | us |
+------------+--------+
| 1300337288 | 938208 |
| 1300337288 | 965069 |
| 1300337288 | 976498 |
| 1300337288 | 987483 |
| 1300337288 | 998476 |
| 1300337289 | 9421 |
@riywo
riywo / gist:874011
Created March 17, 2011 08:37
bashでパイプとかでつないでバッファされちゃう時

tail -fみたいに流しながら見たいんだけど、色んなコマンドが出力をバッファしちゃうので、困ったときはそのコマンドにバッファしないオプションが無いか探すのがオヌヌメ。 man command -> bufferとかで検索

grep

   --line-buffered
          Use line buffering, it can be a performance penality.

$ iostat -x 1 | grep --line-buffered 'sda'

awk

my $ret = $mysql->mysql("select count(*) from $TABLE", 'db' => $DB, 'opt' => "--skip-column-name"),
note($ret);
note explain $ret;
is($ret, "200\n", "count");
note($ret);
#---------------------------------------------------------------------------------------------------
# undef
# 100
@riywo
riywo / gist:879355
Created March 21, 2011 11:57
perlのfork&execで `echo "show databases" | mysql -uroot` を再現してみた
use strict;
use warnings;
use Data::Dumper;
use IO::Handle;
my ($parent_in, $parent_out);
my ($child_in, $child_out);
pipe $parent_out, $child_in;
pipe $child_out, $parent_in;
$parent_in->autoflush(1);
@riywo
riywo / gist:879661
Created March 21, 2011 15:49
fork & exec with Perl
use strict;
use warnings;
use IO::Handle;
sub fork_exec {
my @args = @_;
my $handles = [];
if (ref($args[$#args]) eq 'GLOB') {
my $stdin = pop @args;