Skip to content

Instantly share code, notes, and snippets.

View xtetsuji's full-sized avatar

OGATA Tetsuji xtetsuji

View GitHub Profile
@xtetsuji
xtetsuji / maillog-hashnize.pl
Last active October 11, 2022 08:08
enhancement of "pflog" for parsing maillog of postfix 2.3 or higher version.
#!/usr/bin/perl
# "pflog" enhancement for parsing maillog of postfix 2.3 or higher version.
# "pflog" see: http://www.tmtm.org/ruby/pflog/pflog-0.3
use strict;
use warnings;
use Time::Local;
use Getopt::Long;
#use Data::Dumper;
@xtetsuji
xtetsuji / end-of-month.sh
Created February 29, 2012 13:58
return success code on "end of month" and "leap year"
#!/bin/bash
# Usage:
# # crontab: need to run some-command at end-of-month.
# 0 15 28-31 * * end-of-month.sh && some-command
set -o errexit
arg=$1
if [ $(date +%m -d "$arg tomorrow" ) != $(date +%m -d "$arg" ) ] ; then
exit 0;
@xtetsuji
xtetsuji / twitter-stream-search.pl
Created March 20, 2012 18:58
Search Twitter by Twitter Stream API using AnyEvent::Twitter::Stream
#!/usr/bin/env perl
# written by @xtetsuji at 2012/02/04
use v5.10;
use strict;
use warnings;
use utf8;
use IO::Handle;
use Encode;
@xtetsuji
xtetsuji / dumper-utf8.pl
Created July 27, 2012 08:34
Recursive {en,de}code version's Data::Dumper::Dumper() for having perl internal string.
# -*- cperl -*-
# ogata 2012/07/22
# ogata 2012/07/27
use strict;
use warnings;
use Data::Dumper;
use Scalar::Util qw(reftype readonly);
@xtetsuji
xtetsuji / Hello2.pm
Created July 30, 2012 14:49
MyApache2::Sinatratic - Sinatratic WAF emulator for mod_perl2 (joke and concept version)
package MyApache2::Hello2;
use strict;
use warnings;
use Apache2::RequestRec;
use Apache2::RequestIO;
use Apache2::Const -compile => qw(OK);
use MyApache2::Sinatratic;
@xtetsuji
xtetsuji / map2.pl
Created August 7, 2012 01:39
perl map syntax implement by perl itself without using CORE::map.
#!/usr/bin/perl
# ogata 2012/08/07
# perl map syntax implement by perl itself without using CORE::map.
sub map2 (&@) {
my $code = shift;
my @args = @_;
require Scalar::Util;
my $type = Scalar::Util::reftype($code);
unless($type and $type eq 'CODE') {
@xtetsuji
xtetsuji / prime-jojo.sh
Created August 12, 2012 14:33
Echo "JOJO!" if counting number is prime.
#!/bin/bash
# require: factor
# note: Debian coreutils includes factor command and using it first setup.
for((i=1;;i++)) ; do factor $i | grep -E '^[0-9]+: [0-9]+$' >/dev/null 2>&1 && echo 'JOJO!' || echo $i ; sleep 1 ; done
@xtetsuji
xtetsuji / apache2-const.pl
Created August 28, 2012 10:20
Show almost every Apache2::Const having constants.
#!/usr/bin/env perl
# ogata 2012/08/28
# Show almost every Apache2::Const having constants.
use strict;
use warnings;
use Apache2::Const -compile => qw(
:cmd_how
:common
@xtetsuji
xtetsuji / aterm-wm3600r-battery.pl
Created August 28, 2012 14:38
Display Aterm WM3600R remaining battery charge.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Encode;
use LWP::UserAgent;
use Web::Scraper;
binmode STDOUT, ':utf8';
@xtetsuji
xtetsuji / data-section-emulate.pl
Created October 3, 2012 09:16
Emulate __DATA__ section for mod_perl Registry/PerlRun script, and so on.
#!/usr/bin/perl
# Emulate __DATA__ section for mod_perl Registry/PerlRun script, and so on.
use strict;
use warnings;
### In tail of this file, its "data" exists and defines inside BEGIN { ... } block.
my $DATA;
open \*DATA, '<', \$DATA;