Skip to content

Instantly share code, notes, and snippets.

View SpringMT's full-sized avatar

Spring_MT SpringMT

View GitHub Profile
@SpringMT
SpringMT / gist:1252584
Created September 30, 2011 03:43
CPANモジュールのバージョンを簡単に確認する関数
$ perl -MEncode -le "print $Encode::VERSION"
function cpanv (){
perl -M$1 -le "print \$$1::VERSION"
}
@SpringMT
SpringMT / gist:1252619
Created September 30, 2011 04:12
perlでOSを調べる
perl -e 'print $^O'
#!/usr/bin/env perl
=head1 NAME
idezawaman.pl -
=head1 WHY THIS NAME?
16:24 < Yappo> ちょっとしたツールかきたいのに良い名前が思い浮かばなくてかけてない
16:28 < teranishi> まかせなさい
@SpringMT
SpringMT / gist:1303286
Created October 21, 2011 07:20
SEGV調べる
% gdb --args perl `which plackup` app.psgi
というわけで、テンプレートエンジンがSEGVする場合のうち、90% はテンプレートエンジン自体の問題ではありません。そこでまずは SEGV する原因をしらべるわけですが、SEGV する原因をしらべるには、gdb をつかうのが簡単です。
% gdb --args perl `which plackup` app.psgi
などとして起動してから実際に SEGV をおとし、gdb がとまったところですかさず 'bt' コマンドをうちます(bt=backtrace)。この時、C レベルのスタックトレースがとれますが、このときに表示されているスタックトレースのログの一番上の方にのこっている部分に注目します。
@SpringMT
SpringMT / gist:1526749
Created December 28, 2011 06:32
サーバー間のファイルの差分調べる
for h in \
hoge.pm \
foo.pm \
; do echo $h; ssh {} cat /path/to/$h | diff - /path/to/$h ; done
@SpringMT
SpringMT / gist:1526773
Created December 28, 2011 06:47
tcpdump packet capture
sudo /usr/sbin/tcpdump -i bond0 -p -n 'udp and host hegheg'
@SpringMT
SpringMT / gist:1526929
Created December 28, 2011 07:19
perl goto sample
perl -le 'sub test { print join ",", @_; } sub main { my $a = "test"; goto &$a; } main("Hello", "World");'
@SpringMT
SpringMT / gist:1527022
Created December 28, 2011 07:51
Class::Accessor::Lite sample
perl -le 'package L; use Class::Accessor::Lite (new =>1,rw => [qw/id name separator/]);package main; my $ret = L->new(id => 1); print $ret->id;'
@SpringMT
SpringMT / gist:1586850
Created January 10, 2012 04:03
git stashした数
#!/bin/sh
echo `__git_ps1`
if [ -r "/etc/bash_completion.d/git" ]; then
git stash list 2>/dev/null | grep `__git_ps1 %s` | wc -l
fi
@SpringMT
SpringMT / gist:1586878
Created January 10, 2012 04:10
クロージャ
外のスコープのmy変数を参照しているのがクロージャ。そうでないのが非クロージャ ->
perl -MDevel::Peek -e 'my $x; our $y; Dump sub { $x }; Dump sub { $y }'