Skip to content

Instantly share code, notes, and snippets.

@akanehara
akanehara / bunch.pl
Last active December 6, 2017 09:29
Bunchオブジェクト (Perl)
#!/usr/bin/perl
use strict;
use warnings;
package Bunch {
sub new {
my $class = shift;
my $self = {@_};
@akanehara
akanehara / chrome-search-settings
Created December 5, 2017 01:10
Chrome検索エンジン設定
Linux-JP
jman
http://linuxjm.osdn.jp/cgi-bin/man.cgi?Pagename=%s&submit=Search%21&Sec1=on&Sec2=on&Sec3=on&Sec4=on&Sec5=on&Sec6=on&Sec7=on&Sec8=on
@akanehara
akanehara / cli-template.pl
Last active December 21, 2021 01:09
CLIツール雛形 (Perl)
#!/usr/bin/perl
use strict;
use warnings;
# use lib "."; # Module search path
use File::Basename qw/basename dirname/;
use Pod::Usage;
use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat);
@akanehara
akanehara / snippet.pl
Last active November 6, 2017 02:50
Perlスニペット
# 標準出力・標準エラー出力のバッファリングをしない
{ $|=1; my $_old = select(STDERR); $|=1; select($_old); }
# 入力時の行区切り指定
local $/ = "\r\n";
@akanehara
akanehara / unuseful-onliners.sh
Last active August 2, 2019 01:40
非実用一行野郎
# スプレッドシートの37万8861列目は UNKO
echo UNKO | perl -aple 'my($d,$x);for(map ord(uc$_)-65,reverse split//,$F[0]){$x+=($_+1)*(26**$d++)};$_=$x'
# dcイディオム(map)
seq 10 | dc -e '[2*]sF' -e '?[lFxpc?z0<.]ds.x'
# dcイディオム(reduce)
seq 10 | dc -e '[+]sF?' -e '?[lFx?z1<.]s.z0<.p'
# 10進encode
printf akanehara | xxd -u -p | tr -d '\n' | dc -e '16i?p' | tr -d '\n\\'
@akanehara
akanehara / useful-oneliners.sh
Last active February 22, 2024 05:51
実用一行野郎
VBoxManage list runningvms | awk '$0=$1' | tr -d '"' | xargs -n1 -I@ VBoxManage controlvm @ acpipowerbutton
# 事前ソート不要の uniq
awk '!s[$0]{s[$0]=1;print}'
# nl 用例
# - ゼロ埋め2桁連番空白セパレータ
nl -nrz -w2 -s ' '
# 使われていないvmの削除コマンド (さらにshにパイプして実行)
@akanehara
akanehara / gist:97a7ee8627413eb5d3d5dece13ac4948
Last active August 1, 2020 02:02
斎藤衛氏の国会証人喚問での発言
curl -s "https://kokkai.ndl.go.jp/api/speech?$(echo 'speaker=斎藤衛' | perl -MURI::Escape -ple '$_=uri_escape $_;')" | xmllint --encode utf-8 --xpath "//session|//date|//speech|//speaker" - | nkf --numchar-input | tr -d '\n' | LANG=C LC_ALL=C sed -e 's/ *//g' | sed -e 's/<[\/0-9a-zA-Z]*>/ /g' | xargs -n4
@akanehara
akanehara / giwaku.sh
Last active August 1, 2020 02:06
疑惑の総合商社の初出は2002年3月11日
curl -s "https://kokkai.ndl.go.jp/api/speech?$(echo 'spaker=辻本清美&any=疑惑の総合商社' | perl -MURI::Escape -ple '$_=uri_escape $_;')" | xmllint --encode utf-8 --xpath "//speechRecord/session|//speechRecord/date|//speechRecord/speech|//speechRecord/speaker" - | nkf --numchar-input | gtr -d '\n' | gsed -e 's/[:space:]*//g' | gsed -e 's/<[\/0-9a-zA-Z]*>/ /g' | xargs -n4
@akanehara
akanehara / ArrayUtil.pm
Last active February 20, 2017 06:27
配列ユーティリティ
package ArrayUtil;
use strict;
use warnings;
use Exporter;
our @ISA = qw/Exporter/;
our @EXPORT_OK = qw/
uniq
any
BEGIN {
OFS = "\t";
E = L-1 ;A = 0; I = 1;
do {
B = A + W - 1;
if (E < B) B = E;
print A, B;
A = B + 1;
} while (A < L);
}