Skip to content

Instantly share code, notes, and snippets.

View xtetsuji's full-sized avatar

OGATA Tetsuji xtetsuji

View GitHub Profile
@xtetsuji
xtetsuji / mystacktrace-test.pl
Created March 2, 2017 09:14
Getting stacktrace $SIG{__DIE__} hook from outsider code which ignores and trashes all exceptions.
#!/usr/bin/perl
use strict;
use warnings;
use Sys::Syslog;
#use Carp;
BEGIN {
( my $basename = $0 ) =~ s{.*/}{};
@xtetsuji
xtetsuji / 99seen.pl
Created January 18, 2017 16:20
How many kind numbers 9*9 multiplation table has.
#!/usr/bin/perl
use strict;
use warnings;
my %seen;
for my $i (1..9) {
for my $j (1..9) {
$seen{$i * $j}++;
@xtetsuji
xtetsuji / 99sum.pl
Created January 11, 2017 11:57
When sum of all multiplation table numbers is subtracted 9, its answer is 2016.
#!/usr/bin/perl
use strict;
use warnings;
my $sum = 0;
for my $i (1..9) {
for my $j (1..9) {
$sum += $i * $j;
@xtetsuji
xtetsuji / leapwatch.pl
Created December 31, 2016 23:59
leap second inspector.
#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes qw(usleep time);
while(1) {
printf "%s [%s]\n", time, scalar localtime;
# 0.1秒 = 10**5 microsecond
@xtetsuji
xtetsuji / qqns.pl
Last active October 26, 2016 16:12
Querying and logging qq.com MX to qq.com all NSes continuously.
#!/usr/bin/perl
# xtetsuji 2016/10/26
# qqns.pl - qq.com の MX を qq.com の NS 群全部に問い合わせをして、その記録を取る
#
# 何も考えず雑に書いたのでかなり適当です
# qq.com の NS のうち複数が返答しない場合があるらしく、その調査観察を行うためのスクリプトです
use v5.10;
use strict;
use warnings;
#!/bin/bash
set -eu
declare -a ar=()
echo length ${#ar[*]}
for i in {1..10} ; do
# set -u のときは array push のときに中身が無い ${ar[*]} を参照できない
@xtetsuji
xtetsuji / forward.pl
Created June 23, 2016 16:32
forward 1st execution answer to right callback.
#!/usr/bin/perl
use strict;
use warnings;
# こういう forward 関数(仮名)があれば
sub forward {
my $landing_cb = pop;
my @sub_returns = @_;
@xtetsuji
xtetsuji / syslog-manual-rotate.pl
Last active June 21, 2016 11:53
Syslog manual rotatation. It fills alphabet as temprary year information.
#!/usr/bin/perl
use strict;
use warnings;
use Term::ANSIColor qw(colored);
my %mon_digit_of = (
qw(Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6 Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12)
);
@xtetsuji
xtetsuji / mhls
Created June 8, 2016 08:56
MH format mail file simple parser.
#!/usr/bin/perl
# mhls MH_FILENAME ...
# MH 形式のファイルを引数に与えるとファイルサイズとDateヘッダから導き出される日付を表示します
use strict;
use warnings;
use Date::Format qw(time2str);
use Date::Parse qw(str2time);
use List::Util qw(first);
@xtetsuji
xtetsuji / prime-day-2016.txt
Created June 3, 2016 05:42
Prime days in 2016.
$ for i in {-1..364} ; do ymd=$(date +%Y%m%d -d "2016/01/01 $i days tomorrow") ; if factor $ymd | grep -E "^$ymd: $ymd$" >/dev/null ; then echo $ymd ; fi ; done | cat -n
1 20160319
2 20160401
3 20160403
4 20160529
5 20160601
6 20160607
7 20160611
8 20160709
9 20160727