Skip to content

Instantly share code, notes, and snippets.

View bayashi's full-sized avatar
💎
OK

bayashi bayashi

💎
OK
View GitHub Profile
@bayashi
bayashi / build_placeholder.pl
Last active August 29, 2015 14:20
benchmark of building place holder
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmarks sub {
my @list = (1..10);
+{
map_join => sub {
join(',', map { '?' } @list);
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Benchmark qw(cmpthese);
my $h = '25';
my $pattern = '((?:(?:'.$h.'[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))';
my $regexp = qr/$pattern/;
my $regexp_o = qr/$pattern/o;
@bayashi
bayashi / awesome.pl
Created July 14, 2014 04:43
awesome-perl
use strict;
use warnings;
use Time::HiRes qw/sleep/;
use Furl;
my %awesome;
{
my $page = 1;
while ( my @index = get_index($page) ) {
$ ./dump-perl-stacktrace -p 17688 -d
perl_code: open my $fh, '>', qq{/tmp/dump_stacktrace.$$.}.time() or die $!; req
uire Carp; print {$fh} Carp::longmess(q{Dump stacktrace}); close $fh;
init
C
R Attaching to process 17688
Reading symbols from /usr/bin/perl...(no debugging symbols found)...done.
Reading symbols from /usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/libperl.s
o...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/libperl.so
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long qw/GetOptionsFromArray/;
use IO::Stty;
use Digest::HMAC_SHA1 qw//;
our $VERSION = 0.01;
main(\@ARGV);
@bayashi
bayashi / Benchmark.pm
Created March 10, 2013 09:20
patched Benchmark.pm: croak if return values are wrong.
package Benchmark;
use strict;
=head1 NAME
Benchmark - benchmark running times of Perl code
=head1 SYNOPSIS
@bayashi
bayashi / gist:4751969
Created February 11, 2013 02:03
Test: : Do NOT load modules
use strict;
use Test::AllModules;
use Test::More;
BEGIN {
note('compile all modules.');
all_ok(
search_path => 'MyApp',
check => sub {
my $class = shift;
package Test::AllModules;
use strict;
use warnings;
use Module::Pluggable::Object;
use List::MoreUtils qw(any);
use Test::More ();
our $VERSION = '0.01';
use Exporter;
@bayashi
bayashi / gist:4292477
Created December 15, 2012 10:12
とあるページの画像だけ抜き出す Web App

とあるページの画像だけ抜き出す Web App

plack ワンライナー

plackup -MLWP::Simple=get -e 'sub { my $env = shift; my ($url) = ($env->{REQUEST_URI} =~ m!^/(.*)!); my @html; push(@html, qq|<img src="$_">|) for get($url) =~ m!<img[^>]*src="(https?://[^"]+)"[^>]*>!g; return [200, ["Content-Type" => "text/html"], [join("", @html) || "OK"]] }'

http://127.0.0.1:5000/http://matome.naver.jp/odai/2135350364969742801

@bayashi
bayashi / found_3idols.pl
Created August 10, 2012 17:15
found 3 idols
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Encode qw/encode_utf8/;
my @list = split //, '岩多大片倉小篠高高仲中仲前前松秋板内梅大菊田中仁野藤松松峯宮横石河柏北小小佐佐佐鈴鈴近増宮渡渡阿市入岩大加川島島高竹田仲中永山伊小小名藤森伊小小名藤森大サ佐平武江相岩梅大岡北篠高光村茂内岡小西橋前宇上折高今星渡増井大駒戸中成野松川早大早成佐大野浦小佐小奥森平米指磯大坂藤堀飯金小吉渡出山西中片石有鈴冨畑瓜上小林西浅石石郭小坂杉冨三村伊今石絹藤高植岩佐豊岡川金牛山鈴雨北長森渡百玉佐有高';
my $words = [qw/
岩佐美咲
多田愛佳