Skip to content

Instantly share code, notes, and snippets.

View SpringMT's full-sized avatar

Spring_MT SpringMT

View GitHub Profile
@SpringMT
SpringMT / gist:861721
Created March 9, 2011 05:05
時間のしゅとく
perl -MTime::Piece -e 'my $t = localtime;my($y, $m, $d) = $t->year, $t->mon, $t->mday'
@SpringMT
SpringMT / gist:864460
Created March 10, 2011 17:00
ハッシュを与えると文字列
perl -MString::ShellQuote -E 'my $i = say shell_quote map { ++$i % 2 ? "--$_" : $_ } (foo => 42, bar => "a b c")'
@SpringMT
SpringMT / gist:872523
Created March 16, 2011 13:53
Mac OS XでDNSキャッシュをFlushする方法
sudo dscacheutil -flushcache
http://d.hatena.ne.jp/solitary_shell/20090102/1230887064
@SpringMT
SpringMT / gist:874248
Created March 17, 2011 12:31
Capture::Tiny sample
#!/usr/bin/perl
fork+exec { $cmd } @args;
use strict;
use Capture::Tiny qw(capture);
my ($stdout, $stderr) = capture {
open my $fh, "| cat";
print $fh "foo bar baz\n";
};
@SpringMT
SpringMT / gist:962062
Created May 9, 2011 04:40
userdel -r 削除するユーザー名
ユーザーを削除するには、userdelコマンドを使用する。削除するユーザーのホームディレクトリをあわせて削除する場合は、-rオプションを付ける。
@SpringMT
SpringMT / gist:1062161
Created July 3, 2011 11:15
インストールされているモジュールの.pmファイルのパスを調べる
find `perl -e 'print "@INC";'` -name "Amon2.pm"|less
http://d.hatena.ne.jp/wizard_blue/20091029/1256743552
@SpringMT
SpringMT / gist:1148489
Created August 16, 2011 05:32
ex time in bashrc
# perl
function ex_time() {
perl -le '
use Time::Local;
use DateTime;
my $zone = 'UTC';
my $time = $ARGV[0] || time();
if ($time =~ m{^(\d{4})/(\d{2})/(\d{2})-(\d{2}):(\d{2}):(\d{2})$}) {
print("localtime2unixtime");
print("$time");
@SpringMT
SpringMT / gist:1186098
Created September 1, 2011 12:50
hashから
perl -MData::Dumper -le 'my $hash = +{a => 1, b=>2, c=>3}; my @list=qw/a b/; my $hash_new =+{}; @$hash_new{@list} = delete@$hash{@list}; print Dumper($hash_new); print Dumper($hash);'
@SpringMT
SpringMT / gist:1246797
Created September 28, 2011 01:55
シェル(bash)でOS判定分岐
if [ `uname` = "Darwin" ]; then
#mac用のコード
elif [ `uname` = "Linux" ]; then
#Linux用のコード
fi
@SpringMT
SpringMT / gist:1247745
Created September 28, 2011 11:44
乱数調査 途中
perl -le 'my %a; my $i = 1; for ($i=1; $i < 100000; $i++) { $a{ int(rand(1000000)) }++ ; }; for my $key ( keys %a ) { if ($a{$key} > 3) {print $key} } '
perl -le 'my %a; my $i = 1; for ($i=1; $i < 1000000; $i++) { $a{ int(rand(1000000)+1) }++ ; }; for my $key ( keys %a ) { if ( ($key % 1000000) == 0) {print "$key" . "\t" . $a{$key} } } '