Skip to content

Instantly share code, notes, and snippets.

View xtetsuji's full-sized avatar

OGATA Tetsuji xtetsuji

View GitHub Profile
@xtetsuji
xtetsuji / set_special_globals.pl
Created May 20, 2016 01:24
Perl truly global variable and tacit global variable.
#!/usr/bin/perl
# $_ is truly global variable
# $a is especially global varialble (for sort and some function). is not trully?
use strict;
use warnings;
use v5.10;
# initialize strictly
undef $_;
@xtetsuji
xtetsuji / shell.txt
Last active April 28, 2016 03:29
Time::HiRes::ualarm micro-second argument is signed 32 bit integer.
$ perl -MTime::HiRes=ualarm -E 'ualarm(3600 * 10**6);'
Time::HiRes::ualarm(-694967296, 0): negative time not invented yet at -e line 1.
$ perl -MTime::HiRes=ualarm -E 'ualarm(360 * 10**6);'
$ perl -MTime::HiRes=ualarm -E 'say(log(3600 * 10**6)/log(2));'
31.7453497605412
@xtetsuji
xtetsuji / DenyFakeBot.pm
Created April 22, 2016 04:18
ModPerl::DenyFakeBot - deny fake bot (currently, only deny fake-googlebot). It is my shorthand script in few minutes, as-is... (probably code has wrong things)
package ModPerl::DenyFakeBot;
# PerlPostReadRequestHadnler ModPerl::DenyFakeBot
use strict;
use warnings;
use APR::Table ();
use Apache2::Connection ();
use Apache2::RequestRec ();
use Apache2::RequestUtil ();
@xtetsuji
xtetsuji / syslog-split.pl
Created March 31, 2016 07:05
syslog handmade rotate for monthly.
#!/usr/bin/perl
# xtetsuji 2016/03/31
# Syslog format does not have year information.
# So this script detect related year as y<digit>.
use strict;
use warnings;
use IO::File;
@xtetsuji
xtetsuji / macgui.sh
Created March 19, 2016 05:12
JXA frontend
#!/bin/bash
ARG1="$1"
shift
JSRUN="osascript -l JavaScript"
COMMAND_LIST="gcal|chrome_tabs|round_tabs"
function dispatch_gcal {
@xtetsuji
xtetsuji / trap.pl
Created January 18, 2016 08:07
Show given signal.
#!/usr/bin/perl
use strict;
use warnings;
my @signals = map { uc } split /\s+/, qx{/bin/kill -l};
$SIG{$_} = sub {
my $signal = shift;
print "signal=$signal\n";
@xtetsuji
xtetsuji / colorsyslog.pl
Created November 5, 2015 09:41
Portable utility of coloring Syslog format and same kind class, e.g. Postfix.
#!/usr/bin/perl
# xtetsuji 2015/11/05
use v5.10;
use strict;
use warnings;
use Term::ANSIColor;
my $syslog_re = qr/^(?<date>\w\w\w [ \d]\d) (?<time>\d\d:\d\d:\d\d) (?<host>\S+) (?<process>\S+): (?<message>.*)/;
@xtetsuji
xtetsuji / marksy.pl
Created October 23, 2015 02:46
convert some text format using Marksy API
#!/usr/bin/env perl
# xtetsuji 2015/10/23
# Perl 5.14 or its higher version have no dependency.
use strict;
use warnings;
use HTTP::Tiny;
use JSON::PP;
use Getopt::Long;
@xtetsuji
xtetsuji / password-check.pl
Created September 5, 2015 14:27
Password checker for ntt-east at-billing.
#!/usr/bin/perl
# アットビリング用に設定できるパスワードのチェック
# OGATA Tetsuji at 2015/09/05
# MITライセンスなのでご自由にどうぞ
use strict;
use warnings;
my $string = shift;
@xtetsuji
xtetsuji / prime-sample.pl
Created August 10, 2015 02:36
is sum prime(n) power of prime(n) on n from 1 to 24 prime?
#!/usr/bin/perl
use strict;
use warnings;
# 超巨大な整数を扱う
use bigint;
use Math::BigInt;
# memoize すれば CPUコストは減らせるけれど、強烈な大きさの数の検査をするとメモリを食い潰しそうなのでなんとも